Brewhouse/lib/Device/Device.h
2023-01-25 21:00:25 -05:00

82 lines
1.8 KiB
C

#ifndef DEVICE_H
#define DEVICE_H
#include <ArduinoJson.h>
#include <PubSubClient.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <ESP8266WiFi.h>
#include <Tools.h>
#include <secrets.h>
const char version[] = "0.0.1";
#define ACTION_TPC "action/state"
#define MODE_SET "mode/set"
#define MODE_STATE "mode/state"
#define TEMP_SET "temp/set"
#define TEMP_STATE "temp/state"
#define TEMP_CURRENT "temp/current"
#define TEMP_HI_SET "temp_hi/set"
#define TEMP_HI_STATE "temp_hi/state"
#define TEMP_LO_SET "temp_lo/set"
#define TEMP_LO_STATE "temp_lo/state"
#define ACTION_OFF "off"
#define ACTION_HEATING "heating"
#define ACTION_COOLING "cooling"
#define ACTION_IDLE "idle"
#ifndef DEVICE_NAME
#define DEVICE_NAME "MQTT Thermostat"
#endif
#ifndef DEVICE_MDL
#define DEVICE_MDL "Thermostat"
#endif
#ifndef DEVICE_MF
#define DEVICE_MF ""
#endif
#ifndef ROOT
#define ROOT "thermostat/"
#endif
#ifndef CONFIG_ROOT
#define CONFIG_ROOT "homeassistant/climate/"
#endif
#ifndef MSG_RETAIN
#define MSG_RETAIN true
#endif
#define TOPIC_LIMIT 4
//COMMAND_SIGNATURE void (*commandFunction)(uint8_t*) // https://forum.arduino.cc/t/assignment-of-function/528949/3
//CALLBACK_SIGNATURE void (*callback)(char*, uint8_t*, unsigned int)
const size_t DOC_SIZE = JSON_OBJECT_SIZE(29) + JSON_ARRAY_SIZE(4);
struct CommandTopic {
void (*cmd)(byte*);
String CmdTopic;
};
struct ControlDevice {
String name; // "Glycol Chiller"
String topic_root; // "brewhouse/"
CommandTopic command_topics[TOPIC_LIMIT];
};
void (*cmd)(byte*) CmdLookup(String command_topic, ControlDevice devices[], int device_count) {
for (int i=0;i<device_count;i++) {
ControlDevice this_device = devices[i];
for (int j=0;j<TOPIC_LIMIT;j++) {
if (this_device.command_topics[j]->CmdTopic == command_topic) return this_device.command_topics[j]->cmd;
}
}
}
#endif