Invalidate resolved entities when the configured device changes
setConfig cached entity IDs for the first device it saw and never cleared them, so picking a different device in the editor left the card reading the previous device's sensors. Pre-existing, but _resolveEntities now stops scanning once the full set is found, which made it easier to hit. Surfaced by review of the auto-detect-gap-closure changes. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -81,3 +81,9 @@ The card SHALL continue attempting entity resolution until the expected sensors
|
||||
#### Scenario: Resolution stops once complete
|
||||
- **WHEN** all expected sensor entities for the device have been resolved
|
||||
- **THEN** the card SHALL NOT repeat the registry scan on subsequent `hass` updates
|
||||
|
||||
#### Scenario: Configured device changes
|
||||
- **WHEN** the card's configured `device_id` changes, for example because the user picked a different device in the editor
|
||||
- **THEN** the card SHALL discard the previously resolved entity IDs and the previously detected beer
|
||||
- **THEN** the card SHALL resolve entities afresh for the newly configured device
|
||||
- **THEN** the card SHALL NOT display values read from the previous device
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
|
||||
- [x] 6.1 Replace the `if (this._entityIds.temperature) return;` latch in `_resolveEntities` with a condition that only stops once the expected sensor set is resolved
|
||||
- [x] 6.2 Verify that keg sensors added after first render are picked up on a later `hass` update without a browser reload, and that the scan stops once complete
|
||||
- [x] 6.3 Invalidate the resolved entity IDs and detected beer in `setConfig` when `device_id` changes, so switching devices in the editor does not keep reading the previous device's sensors (pre-existing bug, surfaced by review)
|
||||
|
||||
## 7. Documentation and release
|
||||
|
||||
|
||||
@@ -81,6 +81,16 @@ export class PerfectDraftCard extends LitElement {
|
||||
"PerfectDraft Card: No device configured. Please use the visual editor to select a PerfectDraft device.",
|
||||
);
|
||||
}
|
||||
|
||||
// Entity IDs and the detected beer belong to a specific device, so switching
|
||||
// devices in the editor has to invalidate them. Without this the card keeps
|
||||
// reading the previous device's sensors.
|
||||
if (this._config?.device_id !== config.device_id) {
|
||||
this._entityIds = {};
|
||||
this._entitiesResolved = false;
|
||||
this._beer = undefined;
|
||||
}
|
||||
|
||||
this._config = { ...config };
|
||||
|
||||
this._layout = resolveLayout(config.layout) as CardLayout;
|
||||
|
||||
Reference in New Issue
Block a user