mirror of
https://github.com/lumapu/ahoy.git
synced 2025-05-10 15:36:38 +02:00
Implement state class for mqtt discovery.
This commit is contained in:
parent
6e34b4adf9
commit
3b7eb9c58b
3 changed files with 32 additions and 14 deletions
|
@ -931,6 +931,7 @@ void app::sendMqttDiscoveryConfig(void) {
|
|||
snprintf(discoveryTopic, 64, "%s/sensor/%s/ch%d_%s/config", MQTT_DISCOVERY_PREFIX, iv->name, iv->assign[i].ch, iv->getFieldName(i));
|
||||
snprintf(uniq_id, 32, "ch%d_%s", iv->assign[i].ch, iv->getFieldName(i));
|
||||
const char* devCls = getFieldDeviceClass(iv->assign[i].fieldId);
|
||||
const char* stateCls = getFieldStateClass(iv->assign[i].fieldId);
|
||||
|
||||
doc["name"] = name;
|
||||
doc["stat_t"] = stateTopic;
|
||||
|
@ -941,6 +942,9 @@ void app::sendMqttDiscoveryConfig(void) {
|
|||
if (devCls != NULL) {
|
||||
doc["dev_cla"] = devCls;
|
||||
}
|
||||
if (stateCls != NULL) {
|
||||
doc["stat_cla"] = stateCls;
|
||||
}
|
||||
|
||||
serializeJson(doc, buffer);
|
||||
mMqtt.sendMsg2(discoveryTopic, buffer);
|
||||
|
@ -963,3 +967,12 @@ const char* app::getFieldDeviceClass(uint8_t fieldId) {
|
|||
}
|
||||
return (pos >= DEVICE_CLS_ASSIGN_LIST_LEN) ? NULL : deviceClasses[deviceFieldAssignment[pos].deviceClsId];
|
||||
}
|
||||
|
||||
const char* app::getFieldStateClass(uint8_t fieldId) {
|
||||
uint8_t pos = 0;
|
||||
for(; pos < DEVICE_CLS_ASSIGN_LIST_LEN; pos++) {
|
||||
if(deviceFieldAssignment[pos].fieldId == fieldId)
|
||||
break;
|
||||
}
|
||||
return (pos >= DEVICE_CLS_ASSIGN_LIST_LEN) ? NULL : stateClasses[deviceFieldAssignment[pos].stateClsId];
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue