mirror of
https://github.com/Laxilef/OTGateway.git
synced 2025-12-10 18:24:27 +05:00
refactor: dynamic sensors
This commit is contained in:
@@ -10,7 +10,7 @@ public:
|
||||
free(this->buffer);
|
||||
}
|
||||
|
||||
void send(int code, const char* contentType, JsonDocument& content, bool pretty = false) {
|
||||
void send(int code, const char* contentType, const JsonVariantConst content, bool pretty = false) {
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
if (!this->webServer->chunkedResponseModeStart(code, contentType)) {
|
||||
this->webServer->send(505, F("text/html"), F("HTTP1.1 required"));
|
||||
|
||||
@@ -98,66 +98,6 @@ public:
|
||||
));
|
||||
}
|
||||
|
||||
bool setHeatingCh1Temp(float temperature) {
|
||||
unsigned long response = this->sendRequest(buildRequest(
|
||||
OpenThermMessageType::WRITE_DATA,
|
||||
OpenThermMessageID::TSet,
|
||||
temperatureToData(temperature)
|
||||
));
|
||||
|
||||
return isValidResponse(response) && isValidResponseId(response, OpenThermMessageID::TSet);
|
||||
}
|
||||
|
||||
bool setHeatingCh2Temp(float temperature) {
|
||||
unsigned long response = this->sendRequest(buildRequest(
|
||||
OpenThermMessageType::WRITE_DATA,
|
||||
OpenThermMessageID::TsetCH2,
|
||||
temperatureToData(temperature)
|
||||
));
|
||||
|
||||
return isValidResponse(response) && isValidResponseId(response, OpenThermMessageID::TsetCH2);
|
||||
}
|
||||
|
||||
bool setDhwTemp(float temperature) {
|
||||
unsigned long response = this->sendRequest(buildRequest(
|
||||
OpenThermMessageType::WRITE_DATA,
|
||||
OpenThermMessageID::TdhwSet,
|
||||
temperatureToData(temperature)
|
||||
));
|
||||
|
||||
return isValidResponse(response) && isValidResponseId(response, OpenThermMessageID::TdhwSet);
|
||||
}
|
||||
|
||||
bool setRoomSetpoint(float temperature) {
|
||||
unsigned long response = this->sendRequest(buildRequest(
|
||||
OpenThermMessageType::WRITE_DATA,
|
||||
OpenThermMessageID::TrSet,
|
||||
temperatureToData(temperature)
|
||||
));
|
||||
|
||||
return isValidResponse(response) && isValidResponseId(response, OpenThermMessageID::TrSet);
|
||||
}
|
||||
|
||||
bool setRoomSetpointCh2(float temperature) {
|
||||
unsigned long response = this->sendRequest(buildRequest(
|
||||
OpenThermMessageType::WRITE_DATA,
|
||||
OpenThermMessageID::TrSetCH2,
|
||||
temperatureToData(temperature)
|
||||
));
|
||||
|
||||
return isValidResponse(response) && isValidResponseId(response, OpenThermMessageID::TrSetCH2);
|
||||
}
|
||||
|
||||
bool setRoomTemp(float temperature) {
|
||||
unsigned long response = this->sendRequest(buildRequest(
|
||||
OpenThermMessageType::WRITE_DATA,
|
||||
OpenThermMessageID::Tr,
|
||||
temperatureToData(temperature)
|
||||
));
|
||||
|
||||
return isValidResponse(response) && isValidResponseId(response, OpenThermMessageID::Tr);
|
||||
}
|
||||
|
||||
bool sendBoilerReset() {
|
||||
unsigned int data = 1;
|
||||
data <<= 8;
|
||||
|
||||
@@ -100,8 +100,8 @@ public:
|
||||
return result;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
String getTopic(T category, T name, char nameSeparator = '/') {
|
||||
template <class CT, class NT>
|
||||
String makeConfigTopic(CT category, NT name, char nameSeparator = '/') {
|
||||
String topic = "";
|
||||
topic.concat(this->prefix);
|
||||
topic.concat('/');
|
||||
@@ -115,16 +115,40 @@ public:
|
||||
}
|
||||
|
||||
template <class T>
|
||||
String getDeviceTopic(T value, char separator = '/') {
|
||||
String getDeviceTopic(T value, char dpvSeparator = '/') {
|
||||
String topic = "";
|
||||
topic.concat(this->devicePrefix);
|
||||
topic.concat(separator);
|
||||
topic.concat(dpvSeparator);
|
||||
topic.concat(value);
|
||||
return topic;
|
||||
}
|
||||
|
||||
template <class CT, class NT>
|
||||
String getDeviceTopic(CT category, NT name, char dpcSeparator = '/', char cnSeparator = '/') {
|
||||
String topic = "";
|
||||
topic.concat(this->devicePrefix);
|
||||
topic.concat(dpcSeparator);
|
||||
topic.concat(category);
|
||||
topic.concat(cnSeparator);
|
||||
topic.concat(name);
|
||||
return topic;
|
||||
}
|
||||
|
||||
template <class CT, class NT, class ST>
|
||||
String getDeviceTopic(CT category, NT name, ST suffix, char dpcSeparator = '/', char cnSeparator = '/', char nsSeparator = '/') {
|
||||
String topic = "";
|
||||
topic.concat(this->devicePrefix);
|
||||
topic.concat(dpcSeparator);
|
||||
topic.concat(category);
|
||||
topic.concat(cnSeparator);
|
||||
topic.concat(name);
|
||||
topic.concat(nsSeparator);
|
||||
topic.concat(suffix);
|
||||
return topic;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
String getObjectId(T value, char separator = '_') {
|
||||
String getObjectIdWithPrefix(T value, char separator = '_') {
|
||||
String topic = "";
|
||||
topic.concat(this->devicePrefix);
|
||||
topic.concat(separator);
|
||||
|
||||
@@ -25,6 +25,8 @@ const char HA_ENABLED_BY_DEFAULT[] PROGMEM = "enabled_by_default";
|
||||
const char HA_UNIQUE_ID[] PROGMEM = "unique_id";
|
||||
const char HA_OBJECT_ID[] PROGMEM = "object_id";
|
||||
const char HA_ENTITY_CATEGORY[] PROGMEM = "entity_category";
|
||||
const char HA_ENTITY_CATEGORY_DIAGNOSTIC[] PROGMEM = "diagnostic";
|
||||
const char HA_ENTITY_CATEGORY_CONFIG[] PROGMEM = "config";
|
||||
const char HA_STATE_TOPIC[] PROGMEM = "state_topic";
|
||||
const char HA_VALUE_TEMPLATE[] PROGMEM = "value_template";
|
||||
const char HA_OPTIONS[] PROGMEM = "options";
|
||||
@@ -45,6 +47,7 @@ const char HA_STATE_OFF[] PROGMEM = "state_off";
|
||||
const char HA_PAYLOAD_ON[] PROGMEM = "payload_on";
|
||||
const char HA_PAYLOAD_OFF[] PROGMEM = "payload_off";
|
||||
const char HA_STATE_CLASS[] PROGMEM = "state_class";
|
||||
const char HA_STATE_CLASS_MEASUREMENT[] PROGMEM = "measurement";
|
||||
const char HA_EXPIRE_AFTER[] PROGMEM = "expire_after";
|
||||
const char HA_CURRENT_TEMPERATURE_TOPIC[] PROGMEM = "current_temperature_topic";
|
||||
const char HA_CURRENT_TEMPERATURE_TEMPLATE[] PROGMEM = "current_temperature_template";
|
||||
|
||||
@@ -77,7 +77,7 @@ public:
|
||||
#endif
|
||||
}
|
||||
|
||||
bool publish(const char* topic, JsonDocument& doc, bool retained = false) {
|
||||
bool publish(const char* topic, const JsonVariantConst doc, bool retained = false) {
|
||||
if (!this->client->connected()) {
|
||||
this->bufferPos = 0;
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user