fix(v2): do not wipe a driver's groups when it announces and is in no zone
The controller sent a GROUPS packet on every driver hello. For a driver in no zone that was an empty list, which replaced the groups stored on the driver. It is now sent at announce and resync only when the list is not empty; explicit zone and device edits still send every list. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a94d6a7de5
commit
d332d447aa
1 file changed
+10
-5
+10
-5
@@ -788,8 +788,10 @@ static esp_err_t send_cmd(const uint8_t mac[6], const uint8_t *env, size_t len,
|
|||||||
return rel_send(mac, wire, len + 2, commit, 1);
|
return rel_send(mac, wire, len + 2, commit, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// GROUPS packet: the ids of every zone whose driver names include `name`
|
// GROUPS packet: the ids of every zone whose driver names include `name`. An empty list replaces
|
||||||
static void send_groups(const uint8_t mac[6], const char *name)
|
// whatever the driver stored, so it is only sent when allow_empty is set (a zone or device was edited);
|
||||||
|
// a driver that merely announced itself and is in no zone keeps the groups it already has.
|
||||||
|
static void send_groups(const uint8_t mac[6], const char *name, bool allow_empty)
|
||||||
{
|
{
|
||||||
uint8_t pkt[REL_FRAG_MAX];
|
uint8_t pkt[REL_FRAG_MAX];
|
||||||
size_t off = 3;
|
size_t off = 3;
|
||||||
@@ -807,6 +809,9 @@ static void send_groups(const uint8_t mac[6], const char *name)
|
|||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (count == 0 && !allow_empty) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
pkt[0] = 0x4C;
|
pkt[0] = 0x4C;
|
||||||
pkt[1] = 0x02; // GROUPS
|
pkt[1] = 0x02; // GROUPS
|
||||||
pkt[2] = count;
|
pkt[2] = count;
|
||||||
@@ -830,7 +835,7 @@ void engine_groups_changed(void)
|
|||||||
uint8_t mac[6];
|
uint8_t mac[6];
|
||||||
const char *hex = cJSON_IsString(addr) ? addr->valuestring : d->string;
|
const char *hex = cJSON_IsString(addr) ? addr->valuestring : d->string;
|
||||||
if (cJSON_IsString(name) && cJSON_IsString(tr) && !strcmp(tr->valuestring, "espnow") && hex_mac(hex, mac)) {
|
if (cJSON_IsString(name) && cJSON_IsString(tr) && !strcmp(tr->valuestring, "espnow") && hex_mac(hex, mac)) {
|
||||||
send_groups(mac, name->valuestring);
|
send_groups(mac, name->valuestring, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
store_unlock();
|
store_unlock();
|
||||||
@@ -872,7 +877,7 @@ static void on_announce(const uint8_t mac[6], const uint8_t *pkt, int len)
|
|||||||
cJSON_ReplaceItemInObject(rec, "name", cJSON_CreateString(name));
|
cJSON_ReplaceItemInObject(rec, "name", cJSON_CreateString(name));
|
||||||
store_save("device");
|
store_save("device");
|
||||||
}
|
}
|
||||||
send_groups(mac, name);
|
send_groups(mac, name, false);
|
||||||
store_unlock();
|
store_unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -883,7 +888,7 @@ static void resync_driver(const uint8_t mac[6])
|
|||||||
store_lock();
|
store_lock();
|
||||||
const char *name = device_name_for(mac);
|
const char *name = device_name_for(mac);
|
||||||
if (name) {
|
if (name) {
|
||||||
send_groups(mac, name); // membership first, in case the driver lost it
|
send_groups(mac, name, false); // membership first, in case the driver lost it
|
||||||
}
|
}
|
||||||
const zone_cur_t *best = NULL;
|
const zone_cur_t *best = NULL;
|
||||||
for (int i = 0; name && i < 16; i++) {
|
for (int i = 0; name && i < 16; i++) {
|
||||||
|
|||||||
Reference in new issue
Block a user