diff --git a/homeassistant/components/homematicip_cloud/sensor.py b/homeassistant/components/homematicip_cloud/sensor.py index fdf125dbfec..b4eb89f06c8 100644 --- a/homeassistant/components/homematicip_cloud/sensor.py +++ b/homeassistant/components/homematicip_cloud/sensor.py @@ -35,13 +35,13 @@ from homeassistant.components.sensor import ( ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( - ENERGY_KILO_WATT_HOUR, - LENGTH_MILLIMETERS, LIGHT_LUX, PERCENTAGE, - POWER_WATT, - SPEED_KILOMETERS_PER_HOUR, - TEMP_CELSIUS, + UnitOfEnergy, + UnitOfPower, + UnitOfPrecipitationDepth, + UnitOfSpeed, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -144,31 +144,25 @@ async def async_setup_entry( class HomematicipAccesspointDutyCycle(HomematicipGenericEntity, SensorEntity): """Representation of then HomeMaticIP access point.""" + _attr_icon = "mdi:access-point-network" + _attr_native_unit_of_measurement = PERCENTAGE _attr_state_class = SensorStateClass.MEASUREMENT def __init__(self, hap: HomematicipHAP, device) -> None: """Initialize access point status entity.""" super().__init__(hap, device, post="Duty Cycle") - @property - def icon(self) -> str: - """Return the icon of the access point entity.""" - return "mdi:access-point-network" - @property def native_value(self) -> float: """Return the state of the access point.""" return self._device.dutyCycleLevel - @property - def native_unit_of_measurement(self) -> str: - """Return the unit this state is expressed in.""" - return PERCENTAGE - class HomematicipHeatingThermostat(HomematicipGenericEntity, SensorEntity): """Representation of the HomematicIP heating thermostat.""" + _attr_native_unit_of_measurement = PERCENTAGE + def __init__(self, hap: HomematicipHAP, device) -> None: """Initialize heating thermostat device.""" super().__init__(hap, device, post="Heating") @@ -189,51 +183,35 @@ class HomematicipHeatingThermostat(HomematicipGenericEntity, SensorEntity): return self._device.valveState return round(self._device.valvePosition * 100) - @property - def native_unit_of_measurement(self) -> str: - """Return the unit this state is expressed in.""" - return PERCENTAGE - class HomematicipHumiditySensor(HomematicipGenericEntity, SensorEntity): """Representation of the HomematicIP humidity sensor.""" + _attr_device_class = SensorDeviceClass.HUMIDITY + _attr_native_unit_of_measurement = PERCENTAGE _attr_state_class = SensorStateClass.MEASUREMENT def __init__(self, hap: HomematicipHAP, device) -> None: """Initialize the thermometer device.""" super().__init__(hap, device, post="Humidity") - @property - def device_class(self) -> SensorDeviceClass: - """Return the device class of the sensor.""" - return SensorDeviceClass.HUMIDITY - @property def native_value(self) -> int: """Return the state.""" return self._device.humidity - @property - def native_unit_of_measurement(self) -> str: - """Return the unit this state is expressed in.""" - return PERCENTAGE - class HomematicipTemperatureSensor(HomematicipGenericEntity, SensorEntity): """Representation of the HomematicIP thermometer.""" + _attr_device_class = SensorDeviceClass.TEMPERATURE + _attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS _attr_state_class = SensorStateClass.MEASUREMENT def __init__(self, hap: HomematicipHAP, device) -> None: """Initialize the thermometer device.""" super().__init__(hap, device, post="Temperature") - @property - def device_class(self) -> SensorDeviceClass: - """Return the device class of the sensor.""" - return SensorDeviceClass.TEMPERATURE - @property def native_value(self) -> float: """Return the state.""" @@ -242,11 +220,6 @@ class HomematicipTemperatureSensor(HomematicipGenericEntity, SensorEntity): return self._device.actualTemperature - @property - def native_unit_of_measurement(self) -> str: - """Return the unit this state is expressed in.""" - return TEMP_CELSIUS - @property def extra_state_attributes(self) -> dict[str, Any]: """Return the state attributes of the windspeed sensor.""" @@ -262,17 +235,14 @@ class HomematicipTemperatureSensor(HomematicipGenericEntity, SensorEntity): class HomematicipIlluminanceSensor(HomematicipGenericEntity, SensorEntity): """Representation of the HomematicIP Illuminance sensor.""" + _attr_device_class = SensorDeviceClass.ILLUMINANCE + _attr_native_unit_of_measurement = LIGHT_LUX _attr_state_class = SensorStateClass.MEASUREMENT def __init__(self, hap: HomematicipHAP, device) -> None: """Initialize the device.""" super().__init__(hap, device, post="Illuminance") - @property - def device_class(self) -> SensorDeviceClass: - """Return the device class of the sensor.""" - return SensorDeviceClass.ILLUMINANCE - @property def native_value(self) -> float: """Return the state.""" @@ -281,11 +251,6 @@ class HomematicipIlluminanceSensor(HomematicipGenericEntity, SensorEntity): return self._device.illumination - @property - def native_unit_of_measurement(self) -> str: - """Return the unit this state is expressed in.""" - return LIGHT_LUX - @property def extra_state_attributes(self) -> dict[str, Any]: """Return the state attributes of the wind speed sensor.""" @@ -301,57 +266,42 @@ class HomematicipIlluminanceSensor(HomematicipGenericEntity, SensorEntity): class HomematicipPowerSensor(HomematicipGenericEntity, SensorEntity): """Representation of the HomematicIP power measuring sensor.""" + _attr_device_class = SensorDeviceClass.POWER + _attr_native_unit_of_measurement = UnitOfPower.WATT _attr_state_class = SensorStateClass.MEASUREMENT def __init__(self, hap: HomematicipHAP, device) -> None: """Initialize the device.""" super().__init__(hap, device, post="Power") - @property - def device_class(self) -> SensorDeviceClass: - """Return the device class of the sensor.""" - return SensorDeviceClass.POWER - @property def native_value(self) -> float: """Return the power consumption value.""" return self._device.currentPowerConsumption - @property - def native_unit_of_measurement(self) -> str: - """Return the unit this state is expressed in.""" - return POWER_WATT - class HomematicipEnergySensor(HomematicipGenericEntity, SensorEntity): """Representation of the HomematicIP energy measuring sensor.""" + _attr_device_class = SensorDeviceClass.ENERGY + _attr_native_unit_of_measurement = UnitOfEnergy.KILO_WATT_HOUR _attr_state_class = SensorStateClass.TOTAL_INCREASING def __init__(self, hap: HomematicipHAP, device) -> None: """Initialize the device.""" super().__init__(hap, device, post="Energy") - @property - def device_class(self) -> SensorDeviceClass: - """Return the device class of the sensor.""" - return SensorDeviceClass.ENERGY - @property def native_value(self) -> float: """Return the energy counter value.""" return self._device.energyCounter - @property - def native_unit_of_measurement(self) -> str: - """Return the unit this state is expressed in.""" - return ENERGY_KILO_WATT_HOUR - class HomematicipWindspeedSensor(HomematicipGenericEntity, SensorEntity): """Representation of the HomematicIP wind speed sensor.""" - _attr_device_class = SensorDeviceClass.SPEED + _attr_device_class = SensorDeviceClass.WIND_SPEED + _attr_native_unit_of_measurement = UnitOfSpeed.KILOMETERS_PER_HOUR def __init__(self, hap: HomematicipHAP, device) -> None: """Initialize the windspeed sensor.""" @@ -362,11 +312,6 @@ class HomematicipWindspeedSensor(HomematicipGenericEntity, SensorEntity): """Return the wind speed value.""" return self._device.windSpeed - @property - def native_unit_of_measurement(self) -> str: - """Return the unit this state is expressed in.""" - return SPEED_KILOMETERS_PER_HOUR - @property def extra_state_attributes(self) -> dict[str, Any]: """Return the state attributes of the wind speed sensor.""" @@ -386,6 +331,9 @@ class HomematicipWindspeedSensor(HomematicipGenericEntity, SensorEntity): class HomematicipTodayRainSensor(HomematicipGenericEntity, SensorEntity): """Representation of the HomematicIP rain counter of a day sensor.""" + _attr_device_class = SensorDeviceClass.PRECIPITATION + _attr_native_unit_of_measurement = UnitOfPrecipitationDepth.MILLIMETERS + def __init__(self, hap: HomematicipHAP, device) -> None: """Initialize the device.""" super().__init__(hap, device, post="Today Rain") @@ -395,86 +343,57 @@ class HomematicipTodayRainSensor(HomematicipGenericEntity, SensorEntity): """Return the today's rain value.""" return round(self._device.todayRainCounter, 2) - @property - def native_unit_of_measurement(self) -> str: - """Return the unit this state is expressed in.""" - return LENGTH_MILLIMETERS - class HomematicpTemperatureExternalSensorCh1(HomematicipGenericEntity, SensorEntity): """Representation of the HomematicIP device HmIP-STE2-PCB.""" + _attr_device_class = SensorDeviceClass.TEMPERATURE + _attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS _attr_state_class = SensorStateClass.MEASUREMENT def __init__(self, hap: HomematicipHAP, device) -> None: """Initialize the device.""" super().__init__(hap, device, post="Channel 1 Temperature") - @property - def device_class(self) -> SensorDeviceClass: - """Return the device class of the sensor.""" - return SensorDeviceClass.TEMPERATURE - @property def native_value(self) -> float: """Return the state.""" return self._device.temperatureExternalOne - @property - def native_unit_of_measurement(self) -> str: - """Return the unit this state is expressed in.""" - return TEMP_CELSIUS - class HomematicpTemperatureExternalSensorCh2(HomematicipGenericEntity, SensorEntity): """Representation of the HomematicIP device HmIP-STE2-PCB.""" + _attr_device_class = SensorDeviceClass.TEMPERATURE + _attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS _attr_state_class = SensorStateClass.MEASUREMENT def __init__(self, hap: HomematicipHAP, device) -> None: """Initialize the device.""" super().__init__(hap, device, post="Channel 2 Temperature") - @property - def device_class(self) -> SensorDeviceClass: - """Return the device class of the sensor.""" - return SensorDeviceClass.TEMPERATURE - @property def native_value(self) -> float: """Return the state.""" return self._device.temperatureExternalTwo - @property - def native_unit_of_measurement(self) -> str: - """Return the unit this state is expressed in.""" - return TEMP_CELSIUS - class HomematicpTemperatureExternalSensorDelta(HomematicipGenericEntity, SensorEntity): """Representation of the HomematicIP device HmIP-STE2-PCB.""" + _attr_device_class = SensorDeviceClass.TEMPERATURE + _attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS _attr_state_class = SensorStateClass.MEASUREMENT def __init__(self, hap: HomematicipHAP, device) -> None: """Initialize the device.""" super().__init__(hap, device, post="Delta Temperature") - @property - def device_class(self) -> SensorDeviceClass: - """Return the device class of the sensor.""" - return SensorDeviceClass.TEMPERATURE - @property def native_value(self) -> float: """Return the state.""" return self._device.temperatureExternalDelta - @property - def native_unit_of_measurement(self) -> str: - """Return the unit this state is expressed in.""" - return TEMP_CELSIUS - class HomematicipPassageDetectorDeltaCounter(HomematicipGenericEntity, SensorEntity): """Representation of the HomematicIP passage detector delta counter."""