Propagate service call `Context` from ZHA group entities to member entities
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 45/100
Direzione di ricerca
Start in homeassistant/components/zha/ and trace how group entity service calls reach the Zigbee multicast command, then find how the gateway proxy maps group members to registered Home Assistant entities. Check the base Entity.async_set_context behavior and the existing ZHA entity tests; done means member state updates after a group command retain its context while later physical updates remain independently attributed.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Context & Problem Description
When calling a service (such as light.turn_on, light.turn_off, switch.turn_on, etc.) on a native ZHA Group entity, the service call's Context (user_id, parent_id, id) is properly recorded on the ZHA Group entity itself. However, the resulting state changes on the individual member entities of that Zigbee group are recorded in the Home Assistant state machine and Activity logbook with a brand-new, empty Context().
Because native Zigbee groups operate via multicast RF frames to a 16-bit group address rather than calling Home Assistant services on individual member entities, the physical member devices update their state in Home Assistant asynchronously when their Report_Attributes frames arrive back at the coordinator (~50–500ms later). When the zha library processes those incoming attribute reports and fires the state update callback to the Home Assistant entity wrapper, Entity.async_write_ha_state() sees no active context on the member entity and generates an unattributed context.
This breaks:
- Activity / Logbook Attribution: Member lights/switches appear to have turned on or off by themselves (no user icon or automation link), even when toggled via a ZHA group in the UI or an automation.
- Manual/Physical Override Detection: Automations that inspect
trigger.to_state.context.user_idortrigger.to_state.context.parent_idon individual lights to distinguish between HA-initiated changes and physical wall-switch presses falsely classify ZHA group commands as physical/external hardware changes.
Proposed Solution: Optimistic Context Seeding
Home Assistant's base Entity class already includes a built-in rolling TTL mechanism for pre-seeding context via Entity.async_set_context(context) (which remains valid for CONTEXT_RECENT_TIME_SECONDS = 5 seconds).
When a service call is executed on a ZHA group entity wrapper in homeassistant/components/zha/ (e.g., Light, Switch, Fan, Cover), the group entity wrapper can propagate its active self._context to the Home Assistant entities of its group members before (or immediately after) issuing the Zigbee multicast command:
- In the ZHA group entity service handler (or a helper method on the ZHA base entity / gateway proxy), identify the member entities belonging to the group (available via the underlying
zhalibrary group entity'sgroup.membersormember_entity_unique_ids). - Look up the corresponding registered Home Assistant
ZHAEntityinstances viazha_gateway_proxy. - Call
member_ha_entity.async_set_context(self._context)on each member entity. - When the physical devices respond with
Report_Attributeswithin the 5-second window (or when thezhalibrary performs its optimistic/post-command group member state sync),async_write_ha_state()on each member entity will automatically attach the pre-seededContext.
Edge Cases & Considerations
- Layer Boundaries (
homeassistant/components/zhavszigpy/zha): Becausecore.Contextis a Home Assistant construct and does not exist inside the standalonezhalibrary, this propagation can stay entirely withinhomeassistant/components/zhaby resolving member entities in the HA component layer. - Already-Matching States: If a member bulb is already
offwhenlight.turn_offis called on the group, pre-seedingasync_set_contextis harmless—either no state write occurs, orcontext_recent_timenaturally expires after 5 seconds. - Sub-second Race Conditions: Since almost all mains-powered Zigbee routers (bulbs, plugs, relays) report attribute changes well within the 5-second
CONTEXT_RECENT_TIME_SECONDSwindow, standardasync_set_contextshould cover both immediatezhagroup state updates and incomingReport_Attributesframes without needing custom timers.
Alternatives Considered
- Using Home Assistant Light Groups (
groupintegration) instead of ZHA Groups: PreservesContextbecause it issues sequential service calls over the HA event bus, but sacrifices Zigbee multicast, flooding the Zigbee mesh with unicast packets and causing the "popcorn effect". - **Tracking `Co
- Lingua principale
- Python
- Stelle
- 96
- Fork
- 84
- Merge medio
- 3g 1h
- PR unite (30g)
- 13
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
-
Analog output numbers and analog input sensors show eleven BACnet engineering units as a different unitForse già presa @zigpy-review-bot l’ha presa 3 giorni fa. Apertabot: code audit
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/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
-
quirks
Difficoltà 3/5 Mezza giornata Idoneità per principianti 58/100
I maintainer di solito rispondono entro 1 giorno
Issue simili
-
separate_packages splits imports from the same explicitly configured packageForse già presa @rahul05ranjan l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
TigreGotico/text2spoken#626 ·
I maintainer di solito rispondono entro 1 giorno
-
oncoref MappingProxyType in proteome.layers breaks deepcopy in reference_coverage._inventoryForse già presa @iskandr l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
pipecat-ai/pipecat#7014 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
NL-BioImaging/biomero#136 ·
I maintainer di solito rispondono entro 1 giorno