From d03b73eb234ab64d13c8dfd8ab15264cec0f5e3c Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Wed, 8 Dec 2021 19:57:36 +0100 Subject: [PATCH] Use new DeviceClass enums in accuweather (#61246) Co-authored-by: epenet --- homeassistant/components/accuweather/const.py | 23 +++++++++---------- .../components/accuweather/sensor.py | 8 +++---- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/homeassistant/components/accuweather/const.py b/homeassistant/components/accuweather/const.py index deab90de706..408d4700422 100644 --- a/homeassistant/components/accuweather/const.py +++ b/homeassistant/components/accuweather/const.py @@ -3,7 +3,7 @@ from __future__ import annotations from typing import Final -from homeassistant.components.sensor import SensorStateClass +from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass from homeassistant.components.weather import ( ATTR_CONDITION_CLEAR_NIGHT, ATTR_CONDITION_CLOUDY, @@ -22,7 +22,6 @@ from homeassistant.components.weather import ( ) from homeassistant.const import ( CONCENTRATION_PARTS_PER_CUBIC_METER, - DEVICE_CLASS_TEMPERATURE, LENGTH_FEET, LENGTH_INCHES, LENGTH_METERS, @@ -123,21 +122,21 @@ FORECAST_SENSOR_TYPES: Final[tuple[AccuWeatherSensorDescription, ...]] = ( ), AccuWeatherSensorDescription( key="RealFeelTemperatureMax", - device_class=DEVICE_CLASS_TEMPERATURE, + device_class=SensorDeviceClass.TEMPERATURE, name="RealFeel Temperature Max", unit_metric=TEMP_CELSIUS, unit_imperial=TEMP_FAHRENHEIT, ), AccuWeatherSensorDescription( key="RealFeelTemperatureMin", - device_class=DEVICE_CLASS_TEMPERATURE, + device_class=SensorDeviceClass.TEMPERATURE, name="RealFeel Temperature Min", unit_metric=TEMP_CELSIUS, unit_imperial=TEMP_FAHRENHEIT, ), AccuWeatherSensorDescription( key="RealFeelTemperatureShadeMax", - device_class=DEVICE_CLASS_TEMPERATURE, + device_class=SensorDeviceClass.TEMPERATURE, name="RealFeel Temperature Shade Max", unit_metric=TEMP_CELSIUS, unit_imperial=TEMP_FAHRENHEIT, @@ -145,7 +144,7 @@ FORECAST_SENSOR_TYPES: Final[tuple[AccuWeatherSensorDescription, ...]] = ( ), AccuWeatherSensorDescription( key="RealFeelTemperatureShadeMin", - device_class=DEVICE_CLASS_TEMPERATURE, + device_class=SensorDeviceClass.TEMPERATURE, name="RealFeel Temperature Shade Min", unit_metric=TEMP_CELSIUS, unit_imperial=TEMP_FAHRENHEIT, @@ -215,7 +214,7 @@ FORECAST_SENSOR_TYPES: Final[tuple[AccuWeatherSensorDescription, ...]] = ( SENSOR_TYPES: Final[tuple[AccuWeatherSensorDescription, ...]] = ( AccuWeatherSensorDescription( key="ApparentTemperature", - device_class=DEVICE_CLASS_TEMPERATURE, + device_class=SensorDeviceClass.TEMPERATURE, name="Apparent Temperature", unit_metric=TEMP_CELSIUS, unit_imperial=TEMP_FAHRENHEIT, @@ -241,7 +240,7 @@ SENSOR_TYPES: Final[tuple[AccuWeatherSensorDescription, ...]] = ( ), AccuWeatherSensorDescription( key="DewPoint", - device_class=DEVICE_CLASS_TEMPERATURE, + device_class=SensorDeviceClass.TEMPERATURE, name="Dew Point", unit_metric=TEMP_CELSIUS, unit_imperial=TEMP_FAHRENHEIT, @@ -250,7 +249,7 @@ SENSOR_TYPES: Final[tuple[AccuWeatherSensorDescription, ...]] = ( ), AccuWeatherSensorDescription( key="RealFeelTemperature", - device_class=DEVICE_CLASS_TEMPERATURE, + device_class=SensorDeviceClass.TEMPERATURE, name="RealFeel Temperature", unit_metric=TEMP_CELSIUS, unit_imperial=TEMP_FAHRENHEIT, @@ -258,7 +257,7 @@ SENSOR_TYPES: Final[tuple[AccuWeatherSensorDescription, ...]] = ( ), AccuWeatherSensorDescription( key="RealFeelTemperatureShade", - device_class=DEVICE_CLASS_TEMPERATURE, + device_class=SensorDeviceClass.TEMPERATURE, name="RealFeel Temperature Shade", unit_metric=TEMP_CELSIUS, unit_imperial=TEMP_FAHRENHEIT, @@ -291,7 +290,7 @@ SENSOR_TYPES: Final[tuple[AccuWeatherSensorDescription, ...]] = ( ), AccuWeatherSensorDescription( key="WetBulbTemperature", - device_class=DEVICE_CLASS_TEMPERATURE, + device_class=SensorDeviceClass.TEMPERATURE, name="Wet Bulb Temperature", unit_metric=TEMP_CELSIUS, unit_imperial=TEMP_FAHRENHEIT, @@ -300,7 +299,7 @@ SENSOR_TYPES: Final[tuple[AccuWeatherSensorDescription, ...]] = ( ), AccuWeatherSensorDescription( key="WindChillTemperature", - device_class=DEVICE_CLASS_TEMPERATURE, + device_class=SensorDeviceClass.TEMPERATURE, name="Wind Chill Temperature", unit_metric=TEMP_CELSIUS, unit_imperial=TEMP_FAHRENHEIT, diff --git a/homeassistant/components/accuweather/sensor.py b/homeassistant/components/accuweather/sensor.py index 62047f801fb..448c00eb53f 100644 --- a/homeassistant/components/accuweather/sensor.py +++ b/homeassistant/components/accuweather/sensor.py @@ -3,9 +3,9 @@ from __future__ import annotations from typing import Any, cast -from homeassistant.components.sensor import SensorEntity +from homeassistant.components.sensor import SensorDeviceClass, SensorEntity from homeassistant.config_entries import ConfigEntry -from homeassistant.const import CONF_NAME, DEVICE_CLASS_TEMPERATURE +from homeassistant.const import CONF_NAME from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.device_registry import DeviceEntryType from homeassistant.helpers.entity import DeviceInfo @@ -107,7 +107,7 @@ class AccuWeatherSensor(CoordinatorEntity, SensorEntity): def native_value(self) -> StateType: """Return the state.""" if self.forecast_day is not None: - if self.entity_description.device_class == DEVICE_CLASS_TEMPERATURE: + if self.entity_description.device_class == SensorDeviceClass.TEMPERATURE: return cast(float, self._sensor_data["Value"]) if self.entity_description.key == "UVIndex": return cast(int, self._sensor_data["Value"]) @@ -117,7 +117,7 @@ class AccuWeatherSensor(CoordinatorEntity, SensorEntity): return round(self._sensor_data[self._unit_system]["Value"]) if self.entity_description.key == "PressureTendency": return cast(str, self._sensor_data["LocalizedText"].lower()) - if self.entity_description.device_class == DEVICE_CLASS_TEMPERATURE: + if self.entity_description.device_class == SensorDeviceClass.TEMPERATURE: return cast(float, self._sensor_data[self._unit_system]["Value"]) if self.entity_description.key == "Precipitation": return cast(float, self._sensor_data[self._unit_system]["Value"])