1
0
Fork 0
mirror of https://github.com/Andre0512/hon.git synced 2025-04-01 15:47:04 +00:00

Get program name from prCode MQTT update

Fix SensorDeviceClass for Current Electricity Used
This commit is contained in:
Kuba Sawulski 2024-08-13 18:47:22 +02:00
parent d76f3bddc7
commit 46433e4516

View file

@ -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()