Each time a device becomes available again, ZHA adds another firmware update listener that is never released
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 90/100
Direzione di ricerca
Inizia con BaseDevice.async_initialize e _async_became_available in zha/zigbee/device.py, quindi riproduci i listener duplicati utilizzando il fixture Philips SML001 in tests/data/devices/philips-sml001-0x42006bb7.json. Aggiorna l’inizializzazione in modo che la stessa entità di aggiornamento del firmware non venga sottoscritta di nuovo, mentre un’entità appena rilevata o sostituita riceva ancora un listener. Il test di conteggio dei listener dell'issue deve superarsi e mostrare un listener dopo cicli di disponibilità ripetuti.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Problem
Severity: low (the audit's estimate)
Every time a device with a firmware update entity becomes available again, ZHA subscribes the device to that entity's state changes once more, without dropping the earlier subscription. The listeners are only released when the device is removed, re-interviewed or ZHA shuts down. A device that regularly drops out and comes back, such as a battery device that reports less often than the "consider unavailable" time, a device on a weak link or one on a switched outlet, collects one more listener per cycle, for as long as Home Assistant runs, and every change of its update entity runs all of them. There's no visible symptom beyond the growing memory and work.
BaseDevice.async_initialize registers the listener on the first update entity and appends the unsubscribe callback to _on_remove_callbacks (https://github.com/zigpy/zha/blob/4d8e640c877c998e66b74ad2059c9e1ed1b07510/zha/zigbee/device.py#L1072-L1092). async_initialize runs again whenever the device becomes available (_async_became_available, https://github.com/zigpy/zha/blob/4d8e640c877c998e66b74ad2059c9e1ed1b07510/zha/zigbee/device.py#L826-L828), and that re-initialization keeps the existing update entity (rediscovered copies of existing entities are dropped), so the same entity gets one more listener each time.
Evidence
A test that makes a Philips SML001 (which has a firmware update entity) unavailable and available again three times. It fails at 4d8e640c877c998e66b74ad2059c9e1ed1b07510: the update entity has four device listeners instead of one.
Test and output
async def test_device_firmware_version_listener_not_duplicated(
zha_gateway: Gateway,
) -> None:
"""Test re-initializing a device keeps a single firmware version listener."""
zigpy_dev = await zigpy_device_from_json(
zha_gateway.application_controller,
"tests/data/devices/philips-sml001-0x42006bb7.json",
)
zha_device = await join_zigpy_device(zha_gateway, zigpy_dev)
update_entity = get_entity(zha_device, platform=Platform.UPDATE)
num_listeners = len(update_entity._listeners[STATE_CHANGED])
# The device becomes unavailable and available again a few times, and is
# re-initialized each time
for _ in range(3):
zha_device.update_available(False)
zha_device.update_available(True)
await zha_gateway.async_block_till_done()
assert len(update_entity._listeners[STATE_CHANGED]) == num_listeners
...
> assert len(update_entity._listeners[STATE_CHANGED]) == num_listeners
E assert 4 == 1
E + where 4 = len([EventListener(callback=<function BaseDevice.async_initialize.<locals>.entity_update_listener at 0x78b395bbc9e0>, with...callback=<function BaseDevice.async_initialize.<locals>.entity_update_listener at 0x78b395a6a1f0>, with_context=False)])
Proposed fix
Remember which update entity the device listens to, and skip the subscription when a re-initialization finds the same entity. A new entity (after a re-interview, or when the update entity was replaced) still gets its listener at the next initialization.
- Lingua principale
- Python
- Stelle
- 96
- Fork
- 84
- Merge medio
- 2g 4h
- PR unite (30g)
- 30
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di zigpy/zha
-
Device override creates the generic entity instead of the vendor-specific one (Light instead of HueLight, ForceOnLight, MinTransitionLight)Forse già presa @zigpy-review-bot l’ha presa oggi. Apertabot: code audit
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
Devices that left the network are re-initialized on every availability check, reading attributes from a device that is goneForse già presa @zigpy-review-bot l’ha presa 1 giorno fa. Apertabot: code audit
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
I maintainer di solito rispondono entro 1 giorno
-
device specific quirks
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
entities
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
pimutils/vdirsyncer#1242 ·
-
priority:P2
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
QuantConnect/lean-cli#792 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
open-webui/open-webui#35360 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
Suggest link: Destiny Verify (MIT zero-dependency pre-commit security, citation & link hygiene CLI)Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 68/100