Koenkk / zigbee2mqtt

Zigbee 🐝 to MQTT bridge 🌉, get rid of your proprietary Zigbee bridges 🔨
https://www.zigbee2mqtt.io
GNU General Public License v3.0
12.17k stars 1.68k forks source link

Forcibly deleted devices stay in coordinator #8914

Closed okastl closed 2 years ago

okastl commented 3 years ago

What happened

When a device is forcibly removed, it is deleted from database, but stays in the coordinator. Over time, coordinator_backup.json is filled with "dead" entries.

What did you expect to happen

database.db and coordinator_backup.json should stay in sync, if a device is "forcibly removed".

How to reproduce it (minimal and precise)

Add a device. Force remove it. Shut down z2m. The deleted device entry is present in coordinator_backup.json

Debug info

Zigbee2MQTT version: 1.21.1 Adapter hardware: CC26X2R1 Adapter firmware version: 20210708

MokeleM commented 3 years ago

Same issue here

github-actions[bot] commented 3 years ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days

okastl commented 3 years ago

I recently noticed, that sometimes devices, which are "normal" deleted, stay in coordinator. Zigbee 3 devices (with the "link_key") are in the backup, but the "link_key" is removed. Further, sometimes non-Zigbee 3 devices added are not added to the coordinator backup. Not tragic, as these devices don't need the additional encryption keys, but still, something is broken.

okastl commented 3 years ago

Debug info

Zigbee2MQTT version: 1.21.1

The problem is the same in 1.22.0-dev commit: a09aa42

Koenkk commented 3 years ago

This is expected, force remove just removes the device from the z2m db, not from the network.

okastl commented 3 years ago

This is expected, force remove just removes the device from the z2m db, not from the network.

Unfortunately this happens with "normal" remove, too. Just not as often and therefore not easy to reproduce.

okastl commented 3 years ago

Further, sometimes non-Zigbee 3 devices added are not added to the coordinator backup.

To demonstrate the discrepancy I have made a little quick hack in python. It alerts you about differences between coordinator_backup.json and database.db. After adding an CLA60 TW OSRAM Bulb, the device was not added to coordinator_backup.json, and my tool showed this error:

ieeKey 7cb03eaa00... (Osram) missing!

I have attached the Python program, maybe it is helpful. It expects devices in a separate file. Without such a tool missing or non deleted entries in coordinator_backup.json are not easily spotted.

z2mcheck.zip

ptath commented 2 years ago

Any ideas how to fix this?

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days