From 048bdd321e3ff9e5fa2e0fe99117738da3524c8b Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Wed, 8 Dec 2021 21:17:41 +0100 Subject: [PATCH] Use new DeviceClass and StateClass enums in airly (#61258) Co-authored-by: epenet --- homeassistant/components/airly/sensor.py | 36 ++++++++++-------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/homeassistant/components/airly/sensor.py b/homeassistant/components/airly/sensor.py index 8da42b86a7c..3dab90f5620 100644 --- a/homeassistant/components/airly/sensor.py +++ b/homeassistant/components/airly/sensor.py @@ -6,22 +6,16 @@ from dataclasses import dataclass from typing import Any, cast from homeassistant.components.sensor import ( - STATE_CLASS_MEASUREMENT, + SensorDeviceClass, SensorEntity, SensorEntityDescription, + SensorStateClass, ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( ATTR_ATTRIBUTION, CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, CONF_NAME, - DEVICE_CLASS_AQI, - DEVICE_CLASS_HUMIDITY, - DEVICE_CLASS_PM1, - DEVICE_CLASS_PM10, - DEVICE_CLASS_PM25, - DEVICE_CLASS_PRESSURE, - DEVICE_CLASS_TEMPERATURE, PERCENTAGE, PRESSURE_HPA, TEMP_CELSIUS, @@ -72,52 +66,52 @@ class AirlySensorEntityDescription(SensorEntityDescription): SENSOR_TYPES: tuple[AirlySensorEntityDescription, ...] = ( AirlySensorEntityDescription( key=ATTR_API_CAQI, - device_class=DEVICE_CLASS_AQI, + device_class=SensorDeviceClass.AQI, name=ATTR_API_CAQI, native_unit_of_measurement="CAQI", ), AirlySensorEntityDescription( key=ATTR_API_PM1, - device_class=DEVICE_CLASS_PM1, + device_class=SensorDeviceClass.PM1, name=ATTR_API_PM1, native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, - state_class=STATE_CLASS_MEASUREMENT, + state_class=SensorStateClass.MEASUREMENT, ), AirlySensorEntityDescription( key=ATTR_API_PM25, - device_class=DEVICE_CLASS_PM25, + device_class=SensorDeviceClass.PM25, name="PM2.5", native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, - state_class=STATE_CLASS_MEASUREMENT, + state_class=SensorStateClass.MEASUREMENT, ), AirlySensorEntityDescription( key=ATTR_API_PM10, - device_class=DEVICE_CLASS_PM10, + device_class=SensorDeviceClass.PM10, name=ATTR_API_PM10, native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, - state_class=STATE_CLASS_MEASUREMENT, + state_class=SensorStateClass.MEASUREMENT, ), AirlySensorEntityDescription( key=ATTR_API_HUMIDITY, - device_class=DEVICE_CLASS_HUMIDITY, + device_class=SensorDeviceClass.HUMIDITY, name=ATTR_API_HUMIDITY.capitalize(), native_unit_of_measurement=PERCENTAGE, - state_class=STATE_CLASS_MEASUREMENT, + state_class=SensorStateClass.MEASUREMENT, value=lambda value: round(value, 1), ), AirlySensorEntityDescription( key=ATTR_API_PRESSURE, - device_class=DEVICE_CLASS_PRESSURE, + device_class=SensorDeviceClass.PRESSURE, name=ATTR_API_PRESSURE.capitalize(), native_unit_of_measurement=PRESSURE_HPA, - state_class=STATE_CLASS_MEASUREMENT, + state_class=SensorStateClass.MEASUREMENT, ), AirlySensorEntityDescription( key=ATTR_API_TEMPERATURE, - device_class=DEVICE_CLASS_TEMPERATURE, + device_class=SensorDeviceClass.TEMPERATURE, name=ATTR_API_TEMPERATURE.capitalize(), native_unit_of_measurement=TEMP_CELSIUS, - state_class=STATE_CLASS_MEASUREMENT, + state_class=SensorStateClass.MEASUREMENT, value=lambda value: round(value, 1), ), )