Skip to content

Commit d73b703

Browse files
committed
Fix resending configs upon MQTT reconnects
All objects suppressed resending their configuration, having sent it successfully via an earlier connection.
1 parent b3d5d8b commit d73b703

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

include/mgos_homeassistant_api.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ struct mgos_homeassistant_handler {
125125
extern "C" {
126126
#endif
127127

128-
bool mgos_homeassistant_send_config(struct mgos_homeassistant *ha);
128+
bool mgos_homeassistant_send_config(struct mgos_homeassistant *ha, bool force);
129129
bool mgos_homeassistant_send_status(struct mgos_homeassistant *ha);
130130
bool mgos_homeassistant_add_handler(struct mgos_homeassistant *ha, ha_ev_handler ev_handler, void *user_data);
131131
bool mgos_homeassistant_call_handlers(struct mgos_homeassistant *ha, int ev, void *ev_data);

src/mgos_homeassistant.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static void mgos_homeassistant_mqtt_ev(struct mg_connection *nc, int ev, void *e
3939
case MG_EV_MQTT_CONNACK: {
4040
mgos_mqtt_pub(mgos_sys_config_get_device_id(), "online", 6, 0, true);
4141
if (user_data) {
42-
mgos_homeassistant_send_config((struct mgos_homeassistant *) user_data);
42+
mgos_homeassistant_send_config((struct mgos_homeassistant *) user_data, true);
4343
mgos_homeassistant_send_status((struct mgos_homeassistant *) user_data);
4444
}
4545
break;
@@ -150,7 +150,7 @@ bool mgos_homeassistant_fromjson(struct mgos_homeassistant *ha, const char *json
150150
SLIST_INSERT_HEAD(&ha->automations, a, entry);
151151
}
152152

153-
mgos_homeassistant_send_config(ha);
153+
mgos_homeassistant_send_config(ha, false);
154154
if (name) free(name);
155155
return true;
156156
}

src/mgos_homeassistant_api.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ static void mgos_homeassistant_mqtt_cb(struct mg_connection *nc, const char *top
285285
(void) nc;
286286
}
287287

288-
bool mgos_homeassistant_send_config(struct mgos_homeassistant *ha) {
288+
bool mgos_homeassistant_send_config(struct mgos_homeassistant *ha, bool force) {
289289
struct mgos_homeassistant_object *o;
290290
if (!ha) return false;
291291
int done = 0, success = 0;
@@ -294,6 +294,7 @@ bool mgos_homeassistant_send_config(struct mgos_homeassistant *ha) {
294294

295295
SLIST_FOREACH(o, &ha->objects, entry) {
296296
done++;
297+
if (force) o->config_sent = false;
297298
if (mgos_homeassistant_object_send_config(o)) success++;
298299
}
299300
LOG((done == success) ? LL_DEBUG : LL_WARN, ("Sent %u configs (%u successfully) for node '%s'", done, success, ha->node_name));

0 commit comments

Comments
 (0)