From 189793bff40a4f0b0193e36eb745f8056b131dc7 Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Thu, 8 Feb 2024 15:40:03 +0100 Subject: [PATCH] Fix demo dashboard (#19734) --- demo/src/ha-demo.ts | 2 + demo/src/stubs/sensor.ts | 58 +++++++++++++++++++ demo/src/stubs/todo.ts | 1 + .../hui-input-select-entity-row.ts | 16 +++-- 4 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 demo/src/stubs/sensor.ts diff --git a/demo/src/ha-demo.ts b/demo/src/ha-demo.ts index 17550a6af6..0a9b131556 100644 --- a/demo/src/ha-demo.ts +++ b/demo/src/ha-demo.ts @@ -23,6 +23,7 @@ import { mockMediaPlayer } from "./stubs/media_player"; import { mockPersistentNotification } from "./stubs/persistent_notification"; import { mockRecorder } from "./stubs/recorder"; import { mockTodo } from "./stubs/todo"; +import { mockSensor } from "./stubs/sensor"; import { mockSystemLog } from "./stubs/system_log"; import { mockTemplate } from "./stubs/template"; import { mockTranslations } from "./stubs/translations"; @@ -50,6 +51,7 @@ export class HaDemo extends HomeAssistantAppEl { mockHistory(hass); mockRecorder(hass); mockTodo(hass); + mockSensor(hass); mockSystemLog(hass); mockTemplate(hass); mockEvents(hass); diff --git a/demo/src/stubs/sensor.ts b/demo/src/stubs/sensor.ts new file mode 100644 index 0000000000..19c9f2e344 --- /dev/null +++ b/demo/src/stubs/sensor.ts @@ -0,0 +1,58 @@ +import { MockHomeAssistant } from "../../../src/fake_data/provide_hass"; + +export const mockSensor = (hass: MockHomeAssistant) => { + hass.mockWS("sensor/numeric_device_classes", () => [ + { + numeric_device_classes: [ + "volume_storage", + "gas", + "data_size", + "irradiance", + "wind_speed", + "volatile_organic_compounds", + "volatile_organic_compounds_parts", + "voltage", + "frequency", + "precipitation_intensity", + "volume", + "precipitation", + "battery", + "nitrogen_dioxide", + "speed", + "signal_strength", + "pm1", + "nitrous_oxide", + "atmospheric_pressure", + "data_rate", + "temperature", + "power_factor", + "aqi", + "current", + "volume_flow_rate", + "humidity", + "duration", + "ozone", + "distance", + "pressure", + "pm25", + "weight", + "energy", + "carbon_monoxide", + "apparent_power", + "illuminance", + "energy_storage", + "moisture", + "power", + "water", + "carbon_dioxide", + "ph", + "reactive_power", + "monetary", + "nitrogen_monoxide", + "pm10", + "sound_pressure", + "sulphur_dioxide", + ], + }, + ]); +}; diff --git a/demo/src/stubs/todo.ts b/demo/src/stubs/todo.ts index b0393f6c88..71d49cdede 100644 --- a/demo/src/stubs/todo.ts +++ b/demo/src/stubs/todo.ts @@ -21,4 +21,5 @@ export const mockTodo = (hass: MockHomeAssistant) => { }, ] as TodoItem[], })); + hass.mockWS("todo/item/subscribe", (_msg, _hass) => () => {}); }; diff --git a/src/panels/lovelace/entity-rows/hui-input-select-entity-row.ts b/src/panels/lovelace/entity-rows/hui-input-select-entity-row.ts index 4dbfd6f6bf..2d4f6e5bf3 100644 --- a/src/panels/lovelace/entity-rows/hui-input-select-entity-row.ts +++ b/src/panels/lovelace/entity-rows/hui-input-select-entity-row.ts @@ -40,14 +40,20 @@ class HuiInputSelectEntityRow extends LitElement implements LovelaceRow { protected updated(changedProps: PropertyValues) { super.updated(changedProps); + if (!this._config) { + return; + } if (changedProps.has("hass")) { const oldHass = changedProps.get("hass"); + const stateObj = this.hass?.states[this._config.entity] as + | InputSelectEntity + | undefined; + const oldStateObj = oldHass?.states[this._config.entity] as + | InputSelectEntity + | undefined; if ( - this.hass && - oldHass && - this._config?.entity && - this.hass.states[this._config.entity].attributes.options !== - oldHass.states[this._config.entity].attributes.options + stateObj && + stateObj.attributes.options !== oldStateObj?.attributes.options ) { this._haSelect.layoutOptions(); }