Skip to content

Robust entity discovery via registry and visible demo-mode notice - #5

Open
Optic00 wants to merge 1 commit into
TimWeyand:mainfrom
Optic00:fix/entity-discovery
Open

Robust entity discovery via registry and visible demo-mode notice#5
Optic00 wants to merge 1 commit into
TimWeyand:mainfrom
Optic00:fix/entity-discovery

Conversation

@Optic00

@Optic00 Optic00 commented Jul 17, 2026

Copy link
Copy Markdown

Summary

The card discovers its data by guessing exact entity IDs (sensor.bms_1_cells_average_voltage, sensor.bmu_power, ...) and silently renders demo data when nothing matches. This PR makes discovery robust and the demo fallback visible:

  • Discovery now goes through the entity registry (which the card already fetches in _ensureRegistries() for product names): entries are filtered by platform === 'byd_battery_box', then matched with relaxed patterns that tolerate any entity_id prefix and the numeric duplicate suffix HA appends (..._2). Without registry access (e.g. card preview), it falls back to the previous state-key scan, with the same relaxed patterns.
  • Sibling sensors (min/max history, balancing, temperature, SoC, SoH, charge/discharge energy, efficiency) are resolved with the same matcher instead of literal template strings, and the matcher prefers entities with a usable state so an orphaned unavailable duplicate never shadows the live entity.
  • The render change-detector accepts prefixed entity IDs too and now also fires when previously present sensors disappear, so the demo notice can appear without a reload.
  • When discovery still finds nothing, the demo render is kept (useful for the card picker preview), but the card now shows a visible notice: "No byd_battery_box entities found – showing demo data".

Fixes #4.

Why exact-ID matching breaks

Testing

  • Static verification: node --check on source and rebuilt bundle; npm run build regenerated the committed bundle (CI's up-to-date check passes).
  • Not yet run against a live HA instance. The manual matrix to verify is: default IDs -> real data exactly as before (exact matches still win); IDs with _2 suffix -> real data (previously demo); prefixed IDs -> real data (previously demo); integration absent or not running -> demo data plus visible notice.

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.

Card silently falls back to demo data when entity discovery fails (brittle entity_id matching)

1 participant