Skip to content

fix: restore zone recovery for renamed entities and handle initialization timing - #20

Open
miguelangel-nubla wants to merge 1 commit into
ApolloAutomation:mainfrom
miguelangel-nubla:main
Open

fix: restore zone recovery for renamed entities and handle initialization timing#20
miguelangel-nubla wants to merge 1 commit into
ApolloAutomation:mainfrom
miguelangel-nubla:main

Conversation

@miguelangel-nubla

Copy link
Copy Markdown

Description

Problem

When revisiting the zone-mapper-card, previously created zones failed to restore and draw on the canvas under the following conditions:

  1. Home Assistant or the integration appends zone names to sensor entity IDs (e.g. 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.
  2. updateZonesFromEntities attempted to fetch attributes via hardcoded lookup sensor.zone_mapper_${location}_zone_${id}, which returned undefined for renamed entities.
  3. If this.canvas was not yet available during the initial set hass invocation, state restoration was skipped and never retried.

Solution

  1. Updated discovery regex to allow optional trailing suffixes: /^sensor\.zone_mapper_([a-z0-9_]+)_zone_(\d+)(?:_.*)?$/.
  2. Maintained a map of discovered zone states (discoveredZoneStates) to access entity attributes directly instead of reconstructing exact entity ID strings.
  3. Ensured updateZonesFromEntities() triggers once both hass and canvas are ready.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Code quality improvements

Checklist

  • I have read the CONTRIBUTING document
  • I have updated the documentation accordingly
  • I have updated the translations if needed

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.
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (1)
  • dist/zone-mapper-card.js is excluded by !**/dist/**

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 46d0c82d-4eea-4a51-844d-5763dd041a0c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@miguelangel-nubla

miguelangel-nubla commented Aug 10, 2026

Copy link
Copy Markdown
Author

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 binary_sensor.office_zone_2_presence, that then became binary_sensor.office_zone_2_presence_office

This might need a bigger architectural change, relying on entity ids is very fragile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant