Skip to content

Commit

Permalink
Publish channel states after discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
iprak committed Oct 20, 2022
1 parent 23b5d04 commit 1471131
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
20 changes: 14 additions & 6 deletions src/httpserver/http_fns.c
Original file line number Diff line number Diff line change
Expand Up @@ -1293,17 +1293,25 @@ int http_fn_ha_discovery(http_request_t* request) {
if (relayCount > 0) {
for (i = 0; i < CHANNEL_MAX; i++) {
if (h_isChannelRelay(i)) {
if (dev_info != NULL) {
MQTT_QueuePublish(topic, dev_info->channel, hass_build_discovery_json(dev_info), OBK_PUBLISH_FLAG_RETAIN);
hass_free_device_info(dev_info);
}
dev_info = hass_init_relay_device_info(i);
MQTT_QueuePublish(topic, dev_info->channel, hass_build_discovery_json(dev_info), OBK_PUBLISH_FLAG_RETAIN);
hass_free_device_info(dev_info);
}
}

//Invoke publishChannles after the last topic
if (dev_info != NULL) {
MQTT_QueuePublishWithCommand(topic, dev_info->channel, hass_build_discovery_json(dev_info), OBK_PUBLISH_FLAG_RETAIN, MQTT_COMMAND_PUBLISH_CHANNELS);
hass_free_device_info(dev_info);
}
}

if (pwmCount == 5 || isLedDriverChipRunning()) {
// Enable + RGB control + CW control
dev_info = hass_init_light_device_info(ENTITY_LIGHT_RGBCW);
MQTT_QueuePublish(topic, dev_info->channel, hass_build_discovery_json(dev_info), OBK_PUBLISH_FLAG_RETAIN);
MQTT_QueuePublishWithCommand(topic, dev_info->channel, hass_build_discovery_json(dev_info), OBK_PUBLISH_FLAG_RETAIN, MQTT_COMMAND_PUBLISH_CHANNELS);
hass_free_device_info(dev_info);
}
else if (pwmCount > 0) {
Expand All @@ -1323,7 +1331,7 @@ int http_fn_ha_discovery(http_request_t* request) {
}

if (dev_info != NULL) {
MQTT_QueuePublish(topic, dev_info->channel, hass_build_discovery_json(dev_info), OBK_PUBLISH_FLAG_RETAIN);
MQTT_QueuePublishWithCommand(topic, dev_info->channel, hass_build_discovery_json(dev_info), OBK_PUBLISH_FLAG_RETAIN, MQTT_COMMAND_PUBLISH_CHANNELS);
hass_free_device_info(dev_info);
}
}
Expand Down Expand Up @@ -1669,7 +1677,7 @@ int http_fn_cfg(http_request_t* request) {
http_html_end(request);
poststr(request, NULL);
return 0;
}
}

int http_fn_cfg_pins(http_request_t* request) {
int iChanged = 0;
Expand Down Expand Up @@ -1733,7 +1741,7 @@ int http_fn_cfg_pins(http_request_t* request) {
iChanged++;
}
}
}
}
if (iChangedRequested > 0) {
// Anecdotally, if pins are configured badly, the
// second-timer breaks. To reconfigure, force
Expand Down
1 change: 0 additions & 1 deletion src/mqtt/new_mqtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,6 @@ OBK_Publish_Result PublishQueuedItems() {

int count = 0;
MqttPublishItem_t* head = g_MqttPublishQueueHead;
char* command;

//The next actionable item might not be at the front. The queue size is limited to MQTT_QUEUED_ITEMS_PUBLISHED_AT_ONCE
//so this traversal is fast.
Expand Down

0 comments on commit 1471131

Please sign in to comment.