From 2cc343bb7f5c1de5594a37ff4ac41b189a0587d6 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 16 Dec 2021 15:43:15 +0100 Subject: [PATCH] Use new enums in nws (#61947) --- homeassistant/components/nws/const.py | 40 ++++++++++++-------------- homeassistant/components/nws/sensor.py | 3 +- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/homeassistant/components/nws/const.py b/homeassistant/components/nws/const.py index 1bef625eaf5..707186abebf 100644 --- a/homeassistant/components/nws/const.py +++ b/homeassistant/components/nws/const.py @@ -5,8 +5,9 @@ from dataclasses import dataclass from datetime import timedelta from homeassistant.components.sensor import ( - STATE_CLASS_MEASUREMENT, + SensorDeviceClass, SensorEntityDescription, + SensorStateClass, ) from homeassistant.components.weather import ( ATTR_CONDITION_CLOUDY, @@ -25,9 +26,6 @@ from homeassistant.components.weather import ( ) from homeassistant.const import ( DEGREE, - DEVICE_CLASS_HUMIDITY, - DEVICE_CLASS_PRESSURE, - DEVICE_CLASS_TEMPERATURE, LENGTH_METERS, LENGTH_MILES, PERCENTAGE, @@ -115,8 +113,8 @@ SENSOR_TYPES: tuple[NWSSensorEntityDescription, ...] = ( key="dewpoint", name="Dew Point", icon=None, - device_class=DEVICE_CLASS_TEMPERATURE, - state_class=STATE_CLASS_MEASUREMENT, + device_class=SensorDeviceClass.TEMPERATURE, + state_class=SensorStateClass.MEASUREMENT, native_unit_of_measurement=TEMP_CELSIUS, unit_convert=TEMP_CELSIUS, ), @@ -124,8 +122,8 @@ SENSOR_TYPES: tuple[NWSSensorEntityDescription, ...] = ( key="temperature", name="Temperature", icon=None, - device_class=DEVICE_CLASS_TEMPERATURE, - state_class=STATE_CLASS_MEASUREMENT, + device_class=SensorDeviceClass.TEMPERATURE, + state_class=SensorStateClass.MEASUREMENT, native_unit_of_measurement=TEMP_CELSIUS, unit_convert=TEMP_CELSIUS, ), @@ -133,8 +131,8 @@ SENSOR_TYPES: tuple[NWSSensorEntityDescription, ...] = ( key="windChill", name="Wind Chill", icon=None, - device_class=DEVICE_CLASS_TEMPERATURE, - state_class=STATE_CLASS_MEASUREMENT, + device_class=SensorDeviceClass.TEMPERATURE, + state_class=SensorStateClass.MEASUREMENT, native_unit_of_measurement=TEMP_CELSIUS, unit_convert=TEMP_CELSIUS, ), @@ -142,8 +140,8 @@ SENSOR_TYPES: tuple[NWSSensorEntityDescription, ...] = ( key="heatIndex", name="Heat Index", icon=None, - device_class=DEVICE_CLASS_TEMPERATURE, - state_class=STATE_CLASS_MEASUREMENT, + device_class=SensorDeviceClass.TEMPERATURE, + state_class=SensorStateClass.MEASUREMENT, native_unit_of_measurement=TEMP_CELSIUS, unit_convert=TEMP_CELSIUS, ), @@ -151,8 +149,8 @@ SENSOR_TYPES: tuple[NWSSensorEntityDescription, ...] = ( key="relativeHumidity", name="Relative Humidity", icon=None, - device_class=DEVICE_CLASS_HUMIDITY, - state_class=STATE_CLASS_MEASUREMENT, + device_class=SensorDeviceClass.HUMIDITY, + state_class=SensorStateClass.MEASUREMENT, native_unit_of_measurement=PERCENTAGE, unit_convert=PERCENTAGE, ), @@ -161,7 +159,7 @@ SENSOR_TYPES: tuple[NWSSensorEntityDescription, ...] = ( name="Wind Speed", icon="mdi:weather-windy", device_class=None, - state_class=STATE_CLASS_MEASUREMENT, + state_class=SensorStateClass.MEASUREMENT, native_unit_of_measurement=SPEED_KILOMETERS_PER_HOUR, unit_convert=SPEED_MILES_PER_HOUR, ), @@ -170,7 +168,7 @@ SENSOR_TYPES: tuple[NWSSensorEntityDescription, ...] = ( name="Wind Gust", icon="mdi:weather-windy", device_class=None, - state_class=STATE_CLASS_MEASUREMENT, + state_class=SensorStateClass.MEASUREMENT, native_unit_of_measurement=SPEED_KILOMETERS_PER_HOUR, unit_convert=SPEED_MILES_PER_HOUR, ), @@ -187,8 +185,8 @@ SENSOR_TYPES: tuple[NWSSensorEntityDescription, ...] = ( key="barometricPressure", name="Barometric Pressure", icon=None, - device_class=DEVICE_CLASS_PRESSURE, - state_class=STATE_CLASS_MEASUREMENT, + device_class=SensorDeviceClass.PRESSURE, + state_class=SensorStateClass.MEASUREMENT, native_unit_of_measurement=PRESSURE_PA, unit_convert=PRESSURE_INHG, ), @@ -196,8 +194,8 @@ SENSOR_TYPES: tuple[NWSSensorEntityDescription, ...] = ( key="seaLevelPressure", name="Sea Level Pressure", icon=None, - device_class=DEVICE_CLASS_PRESSURE, - state_class=STATE_CLASS_MEASUREMENT, + device_class=SensorDeviceClass.PRESSURE, + state_class=SensorStateClass.MEASUREMENT, native_unit_of_measurement=PRESSURE_PA, unit_convert=PRESSURE_INHG, ), @@ -206,7 +204,7 @@ SENSOR_TYPES: tuple[NWSSensorEntityDescription, ...] = ( name="Visibility", icon="mdi:eye", device_class=None, - state_class=STATE_CLASS_MEASUREMENT, + state_class=SensorStateClass.MEASUREMENT, native_unit_of_measurement=LENGTH_METERS, unit_convert=LENGTH_MILES, ), diff --git a/homeassistant/components/nws/sensor.py b/homeassistant/components/nws/sensor.py index 35bbcef838d..d3fe8833846 100644 --- a/homeassistant/components/nws/sensor.py +++ b/homeassistant/components/nws/sensor.py @@ -1,7 +1,6 @@ """Sensors for National Weather Service (NWS).""" from homeassistant.components.sensor import SensorEntity from homeassistant.const import ( - ATTR_ATTRIBUTION, CONF_LATITUDE, CONF_LONGITUDE, LENGTH_METERS, @@ -57,7 +56,7 @@ class NWSSensor(CoordinatorEntity, SensorEntity): """An NWS Sensor Entity.""" entity_description: NWSSensorEntityDescription - _attr_extra_state_attributes = {ATTR_ATTRIBUTION: ATTRIBUTION} + _attr_attribution = ATTRIBUTION def __init__( self,