diff --git a/homeassistant/components/melcloud/sensor.py b/homeassistant/components/melcloud/sensor.py index 19be1ea172d..ab4cded5fa7 100644 --- a/homeassistant/components/melcloud/sensor.py +++ b/homeassistant/components/melcloud/sensor.py @@ -9,12 +9,10 @@ from pymelcloud import DEVICE_TYPE_ATA, DEVICE_TYPE_ATW from pymelcloud.atw_device import Zone from homeassistant.components.sensor import ( - DEVICE_CLASS_ENERGY, - DEVICE_CLASS_TEMPERATURE, - STATE_CLASS_MEASUREMENT, - STATE_CLASS_TOTAL_INCREASING, + SensorDeviceClass, SensorEntity, SensorEntityDescription, + SensorStateClass, ) from homeassistant.const import ENERGY_KILO_WATT_HOUR, TEMP_CELSIUS @@ -43,7 +41,7 @@ ATA_SENSORS: tuple[MelcloudSensorEntityDescription, ...] = ( name="Room Temperature", icon="mdi:thermometer", native_unit_of_measurement=TEMP_CELSIUS, - device_class=DEVICE_CLASS_TEMPERATURE, + device_class=SensorDeviceClass.TEMPERATURE, value_fn=lambda x: x.device.room_temperature, enabled=lambda x: True, ), @@ -52,7 +50,7 @@ ATA_SENSORS: tuple[MelcloudSensorEntityDescription, ...] = ( name="Energy", icon="mdi:factory", native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, - device_class=DEVICE_CLASS_ENERGY, + device_class=SensorDeviceClass.ENERGY, value_fn=lambda x: x.device.total_energy_consumed, enabled=lambda x: x.device.has_energy_consumed_meter, ), @@ -63,7 +61,7 @@ ATW_SENSORS: tuple[MelcloudSensorEntityDescription, ...] = ( name="Outside Temperature", icon="mdi:thermometer", native_unit_of_measurement=TEMP_CELSIUS, - device_class=DEVICE_CLASS_TEMPERATURE, + device_class=SensorDeviceClass.TEMPERATURE, value_fn=lambda x: x.device.outside_temperature, enabled=lambda x: True, ), @@ -72,7 +70,7 @@ ATW_SENSORS: tuple[MelcloudSensorEntityDescription, ...] = ( name="Tank Temperature", icon="mdi:thermometer", native_unit_of_measurement=TEMP_CELSIUS, - device_class=DEVICE_CLASS_TEMPERATURE, + device_class=SensorDeviceClass.TEMPERATURE, value_fn=lambda x: x.device.tank_temperature, enabled=lambda x: True, ), @@ -83,7 +81,7 @@ ATW_ZONE_SENSORS: tuple[MelcloudSensorEntityDescription, ...] = ( name="Room Temperature", icon="mdi:thermometer", native_unit_of_measurement=TEMP_CELSIUS, - device_class=DEVICE_CLASS_TEMPERATURE, + device_class=SensorDeviceClass.TEMPERATURE, value_fn=lambda zone: zone.room_temperature, enabled=lambda x: True, ), @@ -92,7 +90,7 @@ ATW_ZONE_SENSORS: tuple[MelcloudSensorEntityDescription, ...] = ( name="Flow Temperature", icon="mdi:thermometer", native_unit_of_measurement=TEMP_CELSIUS, - device_class=DEVICE_CLASS_TEMPERATURE, + device_class=SensorDeviceClass.TEMPERATURE, value_fn=lambda zone: zone.flow_temperature, enabled=lambda x: True, ), @@ -101,7 +99,7 @@ ATW_ZONE_SENSORS: tuple[MelcloudSensorEntityDescription, ...] = ( name="Flow Return Temperature", icon="mdi:thermometer", native_unit_of_measurement=TEMP_CELSIUS, - device_class=DEVICE_CLASS_TEMPERATURE, + device_class=SensorDeviceClass.TEMPERATURE, value_fn=lambda zone: zone.return_temperature, enabled=lambda x: True, ), @@ -152,10 +150,10 @@ class MelDeviceSensor(SensorEntity): self._attr_name = f"{api.name} {description.name}" self._attr_unique_id = f"{api.device.serial}-{api.device.mac}-{description.key}" - if description.device_class == DEVICE_CLASS_ENERGY: - self._attr_state_class = STATE_CLASS_TOTAL_INCREASING + if description.device_class == SensorDeviceClass.ENERGY: + self._attr_state_class = SensorStateClass.TOTAL_INCREASING else: - self._attr_state_class = STATE_CLASS_MEASUREMENT + self._attr_state_class = SensorStateClass.MEASUREMENT @property def native_value(self):