From 65b391e6515d341e5468b30590ef231671b1b5c8 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 6 Dec 2022 20:05:27 +0100 Subject: [PATCH] Use new device class in arwn (#83406) --- homeassistant/components/arwn/sensor.py | 45 +++++++++++++++++-------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/homeassistant/components/arwn/sensor.py b/homeassistant/components/arwn/sensor.py index 45db805d1de..420ffb2d8a8 100644 --- a/homeassistant/components/arwn/sensor.py +++ b/homeassistant/components/arwn/sensor.py @@ -6,12 +6,7 @@ import logging from homeassistant.components import mqtt from homeassistant.components.sensor import SensorDeviceClass, SensorEntity -from homeassistant.const import ( - DEGREE, - PRECIPITATION_INCHES, - TEMP_CELSIUS, - TEMP_FAHRENHEIT, -) +from homeassistant.const import DEGREE, UnitOfPrecipitationDepth, UnitOfTemperature from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType @@ -36,9 +31,9 @@ def discover_sensors(topic, payload): if domain == "temperature": name = parts[2] if unit == "F": - unit = TEMP_FAHRENHEIT + unit = UnitOfTemperature.FAHRENHEIT else: - unit = TEMP_CELSIUS + unit = UnitOfTemperature.CELSIUS return ArwnSensor( topic, name, "temp", unit, device_class=SensorDeviceClass.TEMPERATURE ) @@ -51,21 +46,43 @@ def discover_sensors(topic, payload): topic, "Rain Since Midnight", "since_midnight", - PRECIPITATION_INCHES, - "mdi:water", + UnitOfPrecipitationDepth.INCHES, + device_class=SensorDeviceClass.PRECIPITATION, ) return ( - ArwnSensor(topic + "/total", "Total Rainfall", "total", unit, "mdi:water"), - ArwnSensor(topic + "/rate", "Rainfall Rate", "rate", unit, "mdi:water"), + ArwnSensor( + topic + "/total", + "Total Rainfall", + "total", + unit, + device_class=SensorDeviceClass.PRECIPITATION, + ), + ArwnSensor( + topic + "/rate", + "Rainfall Rate", + "rate", + unit, + device_class=SensorDeviceClass.PRECIPITATION, + ), ) if domain == "barometer": return ArwnSensor(topic, "Barometer", "pressure", unit, "mdi:thermometer-lines") if domain == "wind": return ( ArwnSensor( - topic + "/speed", "Wind Speed", "speed", unit, "mdi:speedometer" + topic + "/speed", + "Wind Speed", + "speed", + unit, + device_class=SensorDeviceClass.WIND_SPEED, + ), + ArwnSensor( + topic + "/gust", + "Wind Gust", + "gust", + unit, + device_class=SensorDeviceClass.WIND_SPEED, ), - ArwnSensor(topic + "/gust", "Wind Gust", "gust", unit, "mdi:speedometer"), ArwnSensor( topic + "/dir", "Wind Direction", "direction", DEGREE, "mdi:compass" ),