fix: restore zone recovery for renamed entities and handle initialization timing - #20
fix: restore zone recovery for renamed entities and handle initialization timing#20miguelangel-nubla wants to merge 1 commit into
Conversation
fix(card): resolve zone recovery failure for renamed sensor entity IDs Fixes an issue where saved zones fail to load upon reopening the card when zone entities have friendly name suffixes or lifecycle timing delays. Key changes: - Allow optional suffix `(?:_.*)?` in zone sensor discovery regex (`sensor.zone_mapper_<location>_zone_<id>_<name>`). - Map discovered state objects directly by zone ID (`discoveredZoneStates`) instead of assuming hardcoded entity ID strings. - Ensure `updateZonesFromEntities()` runs as soon as both `hass` and `canvas` are initialized.
|
Important Review skippedReview was skipped due to path filters ⛔ Files ignored due to path filters (1)
CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
I believe this might be impacted by HA new entity ID format in latest releases, for me the change to trigger the issue was to click the reset entity id on entity This might need a bigger architectural change, relying on entity ids is very fragile. |
Description
Problem
When revisiting the
zone-mapper-card, previously created zones failed to restore and draw on the canvas under the following conditions:sensor.zone_mapper_office_zone_1_main_chair). The existing regex^sensor\.zone_mapper_([a-z0-9_]+)_zone_(\d+)$strictly anchored the end of the string, ignoring these entities.updateZonesFromEntitiesattempted to fetch attributes via hardcoded lookupsensor.zone_mapper_${location}_zone_${id}, which returnedundefinedfor renamed entities.this.canvaswas not yet available during the initialset hassinvocation, state restoration was skipped and never retried.Solution
/^sensor\.zone_mapper_([a-z0-9_]+)_zone_(\d+)(?:_.*)?$/.discoveredZoneStates) to access entity attributes directly instead of reconstructing exact entity ID strings.updateZonesFromEntities()triggers once bothhassandcanvasare ready.Type of Change
Checklist