From 7a7a9c610af4021574e5203ffbdf4edb2c5d8553 Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Wed, 5 Jun 2024 11:40:37 +0200 Subject: [PATCH] Detach name from unique id in incomfort (#118862) * Detach name from unique id in incomfort * Add entity descriptions to incomfort * Revert "Add entity descriptions to incomfort" This reverts commit 2b6ccd4c3bb921a1b607239a33ef15834dd23e8c. --- homeassistant/components/incomfort/sensor.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/incomfort/sensor.py b/homeassistant/components/incomfort/sensor.py index 044443c8ac0..3ee42dbd78f 100644 --- a/homeassistant/components/incomfort/sensor.py +++ b/homeassistant/components/incomfort/sensor.py @@ -16,7 +16,7 @@ from homeassistant.const import UnitOfPressure, UnitOfTemperature from homeassistant.core import HomeAssistant from homeassistant.helpers.device_registry import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.util import slugify +from homeassistant.helpers.typing import StateType from . import InComfortConfigEntry from .const import DOMAIN @@ -28,10 +28,11 @@ INCOMFORT_PRESSURE = "CV Pressure" INCOMFORT_TAP_TEMP = "Tap Temp" -@dataclass(frozen=True) +@dataclass(frozen=True, kw_only=True) class IncomfortSensorEntityDescription(SensorEntityDescription): """Describes Incomfort sensor entity.""" + value_key: str extra_key: str | None = None # IncomfortSensor does not support UNDEFINED or None, # restrict the type to str @@ -40,17 +41,19 @@ class IncomfortSensorEntityDescription(SensorEntityDescription): SENSOR_TYPES: tuple[IncomfortSensorEntityDescription, ...] = ( IncomfortSensorEntityDescription( - key="pressure", + key="cv_pressure", name=INCOMFORT_PRESSURE, device_class=SensorDeviceClass.PRESSURE, native_unit_of_measurement=UnitOfPressure.BAR, + value_key="pressure", ), IncomfortSensorEntityDescription( - key="heater_temp", + key="cv_temp", name=INCOMFORT_HEATER_TEMP, device_class=SensorDeviceClass.TEMPERATURE, native_unit_of_measurement=UnitOfTemperature.CELSIUS, extra_key="is_pumping", + value_key="heater_temp", ), IncomfortSensorEntityDescription( key="tap_temp", @@ -58,6 +61,7 @@ SENSOR_TYPES: tuple[IncomfortSensorEntityDescription, ...] = ( device_class=SensorDeviceClass.TEMPERATURE, native_unit_of_measurement=UnitOfTemperature.CELSIUS, extra_key="is_tapping", + value_key="tap_temp", ), ) @@ -94,7 +98,7 @@ class IncomfortSensor(IncomfortEntity, SensorEntity): self._heater = heater - self._attr_unique_id = f"{heater.serial_no}_{slugify(description.name)}" + self._attr_unique_id = f"{heater.serial_no}_{description.key}" self._attr_device_info = DeviceInfo( identifiers={(DOMAIN, heater.serial_no)}, manufacturer="Intergas", @@ -102,9 +106,9 @@ class IncomfortSensor(IncomfortEntity, SensorEntity): ) @property - def native_value(self) -> str | None: + def native_value(self) -> StateType: """Return the state of the sensor.""" - return self._heater.status[self.entity_description.key] + return self._heater.status[self.entity_description.value_key] @property def extra_state_attributes(self) -> dict[str, Any] | None: