From 968224983018b7c94aa94e11173f457ea39a3655 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 5 Dec 2022 17:08:00 +0100 Subject: [PATCH] Use new device class in environment canada (#83297) --- .../components/environment_canada/sensor.py | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/homeassistant/components/environment_canada/sensor.py b/homeassistant/components/environment_canada/sensor.py index 88ec055ad03..d3848086bf5 100644 --- a/homeassistant/components/environment_canada/sensor.py +++ b/homeassistant/components/environment_canada/sensor.py @@ -15,13 +15,13 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( ATTR_LOCATION, DEGREE, - LENGTH_KILOMETERS, - LENGTH_MILLIMETERS, PERCENTAGE, - PRESSURE_KPA, - SPEED_KILOMETERS_PER_HOUR, - TEMP_CELSIUS, UV_INDEX, + UnitOfLength, + UnitOfPrecipitationDepth, + UnitOfPressure, + UnitOfSpeed, + UnitOfTemperature, ) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -59,7 +59,7 @@ SENSOR_TYPES: tuple[ECSensorEntityDescription, ...] = ( key="dewpoint", name="Dew point", device_class=SensorDeviceClass.TEMPERATURE, - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, state_class=SensorStateClass.MEASUREMENT, value_fn=lambda data: data.conditions.get("dewpoint", {}).get("value"), ), @@ -67,7 +67,7 @@ SENSOR_TYPES: tuple[ECSensorEntityDescription, ...] = ( key="high_temp", name="High temperature", device_class=SensorDeviceClass.TEMPERATURE, - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, state_class=SensorStateClass.MEASUREMENT, value_fn=lambda data: data.conditions.get("high_temp", {}).get("value"), ), @@ -75,7 +75,7 @@ SENSOR_TYPES: tuple[ECSensorEntityDescription, ...] = ( key="humidex", name="Humidex", device_class=SensorDeviceClass.TEMPERATURE, - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, state_class=SensorStateClass.MEASUREMENT, value_fn=lambda data: data.conditions.get("humidex", {}).get("value"), ), @@ -96,7 +96,7 @@ SENSOR_TYPES: tuple[ECSensorEntityDescription, ...] = ( key="low_temp", name="Low temperature", device_class=SensorDeviceClass.TEMPERATURE, - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, state_class=SensorStateClass.MEASUREMENT, value_fn=lambda data: data.conditions.get("low_temp", {}).get("value"), ), @@ -104,14 +104,14 @@ SENSOR_TYPES: tuple[ECSensorEntityDescription, ...] = ( key="normal_high", name="Normal high temperature", device_class=SensorDeviceClass.TEMPERATURE, - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, value_fn=lambda data: data.conditions.get("normal_high", {}).get("value"), ), ECSensorEntityDescription( key="normal_low", name="Normal low temperature", device_class=SensorDeviceClass.TEMPERATURE, - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, value_fn=lambda data: data.conditions.get("normal_low", {}).get("value"), ), ECSensorEntityDescription( @@ -123,7 +123,8 @@ SENSOR_TYPES: tuple[ECSensorEntityDescription, ...] = ( ECSensorEntityDescription( key="precip_yesterday", name="Precipitation yesterday", - native_unit_of_measurement=LENGTH_MILLIMETERS, + device_class=SensorDeviceClass.PRECIPITATION, + native_unit_of_measurement=UnitOfPrecipitationDepth.MILLIMETERS, state_class=SensorStateClass.MEASUREMENT, value_fn=lambda data: data.conditions.get("precip_yesterday", {}).get("value"), ), @@ -131,7 +132,7 @@ SENSOR_TYPES: tuple[ECSensorEntityDescription, ...] = ( key="pressure", name="Barometric pressure", device_class=SensorDeviceClass.PRESSURE, - native_unit_of_measurement=PRESSURE_KPA, + native_unit_of_measurement=UnitOfPressure.KPA, state_class=SensorStateClass.MEASUREMENT, value_fn=lambda data: data.conditions.get("pressure", {}).get("value"), ), @@ -139,7 +140,7 @@ SENSOR_TYPES: tuple[ECSensorEntityDescription, ...] = ( key="temperature", name="Temperature", device_class=SensorDeviceClass.TEMPERATURE, - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, state_class=SensorStateClass.MEASUREMENT, value_fn=lambda data: data.conditions.get("temperature", {}).get("value"), ), @@ -171,7 +172,7 @@ SENSOR_TYPES: tuple[ECSensorEntityDescription, ...] = ( ECSensorEntityDescription( key="visibility", name="Visibility", - native_unit_of_measurement=LENGTH_KILOMETERS, + native_unit_of_measurement=UnitOfLength.KILOMETERS, device_class=SensorDeviceClass.DISTANCE, state_class=SensorStateClass.MEASUREMENT, value_fn=lambda data: data.conditions.get("visibility", {}).get("value"), @@ -186,7 +187,7 @@ SENSOR_TYPES: tuple[ECSensorEntityDescription, ...] = ( key="wind_chill", name="Wind chill", device_class=SensorDeviceClass.TEMPERATURE, - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, state_class=SensorStateClass.MEASUREMENT, value_fn=lambda data: data.conditions.get("wind_chill", {}).get("value"), ), @@ -198,16 +199,16 @@ SENSOR_TYPES: tuple[ECSensorEntityDescription, ...] = ( ECSensorEntityDescription( key="wind_gust", name="Wind gust", - native_unit_of_measurement=SPEED_KILOMETERS_PER_HOUR, - device_class=SensorDeviceClass.SPEED, + native_unit_of_measurement=UnitOfSpeed.KILOMETERS_PER_HOUR, + device_class=SensorDeviceClass.WIND_SPEED, state_class=SensorStateClass.MEASUREMENT, value_fn=lambda data: data.conditions.get("wind_gust", {}).get("value"), ), ECSensorEntityDescription( key="wind_speed", name="Wind speed", - native_unit_of_measurement=SPEED_KILOMETERS_PER_HOUR, - device_class=SensorDeviceClass.SPEED, + native_unit_of_measurement=UnitOfSpeed.KILOMETERS_PER_HOUR, + device_class=SensorDeviceClass.WIND_SPEED, state_class=SensorStateClass.MEASUREMENT, value_fn=lambda data: data.conditions.get("wind_speed", {}).get("value"), ),