From 46433e4516b7293468034efe4b63c1ab0c1469af Mon Sep 17 00:00:00 2001 From: Kuba Sawulski Date: Tue, 13 Aug 2024 18:47:22 +0200 Subject: [PATCH] Get program name from prCode MQTT update Fix SensorDeviceClass for Current Electricity Used --- custom_components/hon/sensor.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/custom_components/hon/sensor.py b/custom_components/hon/sensor.py index b3886ca..b03b2a4 100644 --- a/custom_components/hon/sensor.py +++ b/custom_components/hon/sensor.py @@ -81,7 +81,7 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = { key="currentElectricityUsed", name="Current Electricity Used", state_class=SensorStateClass.MEASUREMENT, - device_class=SensorDeviceClass.POWER, + device_class=SensorDeviceClass.ENERGY, native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, icon="mdi:lightning-bolt", translation_key="energy_current", @@ -180,7 +180,7 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = { translation_key="temperature", ), HonSensorEntityDescription( - key="programName", + key="prCode", name="Program", icon="mdi:play", device_class=SensorDeviceClass.ENUM, @@ -834,10 +834,11 @@ class HonSensorEntity(HonEntity, SensorEntity): @callback def _handle_coordinator_update(self, update: bool = True) -> None: value = self._device.get(self.entity_description.key, "") - if self.entity_description.key == "programName": + if self.entity_description.key == "prCode": if not (options := self._device.settings.get("startProgram.program")): raise ValueError - self._attr_options = options.values + ["No Program"] + self._attr_options = [*options.values, "No Program"] + value = options.ids.get(value) elif self.entity_description.option_list is not None: self._attr_options = list(self.entity_description.option_list.values()) value = str(get_readable(self.entity_description, value)) @@ -874,3 +875,4 @@ class HonConfigSensorEntity(HonEntity, SensorEntity): self._attr_native_value = value if update: self.async_write_ha_state() +