From 21e46e318d57785566bce2b0177d119d1f7a7b4c Mon Sep 17 00:00:00 2001 From: Robert Hillis Date: Thu, 16 Dec 2021 11:42:24 -0500 Subject: [PATCH] Use enums in venstar (#61993) --- .../components/venstar/binary_sensor.py | 4 ++-- homeassistant/components/venstar/sensor.py | 20 +++++++++---------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/homeassistant/components/venstar/binary_sensor.py b/homeassistant/components/venstar/binary_sensor.py index 1d6c8f49bd8..4a4884cf095 100644 --- a/homeassistant/components/venstar/binary_sensor.py +++ b/homeassistant/components/venstar/binary_sensor.py @@ -1,6 +1,6 @@ """Alarm sensors for the Venstar Thermostat.""" from homeassistant.components.binary_sensor import ( - DEVICE_CLASS_PROBLEM, + BinarySensorDeviceClass, BinarySensorEntity, ) @@ -23,7 +23,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities) -> None: class VenstarBinarySensor(VenstarEntity, BinarySensorEntity): """Represent a Venstar alert.""" - _attr_device_class = DEVICE_CLASS_PROBLEM + _attr_device_class = BinarySensorDeviceClass.PROBLEM def __init__(self, coordinator, config, alert): """Initialize the alert.""" diff --git a/homeassistant/components/venstar/sensor.py b/homeassistant/components/venstar/sensor.py index d7b806927ae..eaa4eb3b927 100644 --- a/homeassistant/components/venstar/sensor.py +++ b/homeassistant/components/venstar/sensor.py @@ -6,12 +6,10 @@ from dataclasses import dataclass from typing import Any from homeassistant.components.sensor import ( - DEVICE_CLASS_BATTERY, - DEVICE_CLASS_HUMIDITY, - DEVICE_CLASS_TEMPERATURE, - STATE_CLASS_MEASUREMENT, + SensorDeviceClass, SensorEntity, SensorEntityDescription, + SensorStateClass, ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import PERCENTAGE, TEMP_CELSIUS, TEMP_FAHRENHEIT, TIME_MINUTES @@ -145,8 +143,8 @@ class VenstarSensor(VenstarEntity, SensorEntity): SENSOR_ENTITIES: tuple[VenstarSensorEntityDescription, ...] = ( VenstarSensorEntityDescription( key="hum", - device_class=DEVICE_CLASS_HUMIDITY, - state_class=STATE_CLASS_MEASUREMENT, + device_class=SensorDeviceClass.HUMIDITY, + state_class=SensorStateClass.MEASUREMENT, uom_fn=lambda coordinator: PERCENTAGE, value_fn=lambda coordinator, sensor_name: coordinator.client.get_sensor( sensor_name, "hum" @@ -155,8 +153,8 @@ SENSOR_ENTITIES: tuple[VenstarSensorEntityDescription, ...] = ( ), VenstarSensorEntityDescription( key="temp", - device_class=DEVICE_CLASS_TEMPERATURE, - state_class=STATE_CLASS_MEASUREMENT, + device_class=SensorDeviceClass.TEMPERATURE, + state_class=SensorStateClass.MEASUREMENT, uom_fn=temperature_unit, value_fn=lambda coordinator, sensor_name: round( float(coordinator.client.get_sensor(sensor_name, "temp")), 1 @@ -165,8 +163,8 @@ SENSOR_ENTITIES: tuple[VenstarSensorEntityDescription, ...] = ( ), VenstarSensorEntityDescription( key="battery", - device_class=DEVICE_CLASS_BATTERY, - state_class=STATE_CLASS_MEASUREMENT, + device_class=SensorDeviceClass.BATTERY, + state_class=SensorStateClass.MEASUREMENT, uom_fn=lambda coordinator: PERCENTAGE, value_fn=lambda coordinator, sensor_name: coordinator.client.get_sensor( sensor_name, "battery" @@ -177,7 +175,7 @@ SENSOR_ENTITIES: tuple[VenstarSensorEntityDescription, ...] = ( RUNTIME_ENTITY = VenstarSensorEntityDescription( key="runtime", - state_class=STATE_CLASS_MEASUREMENT, + state_class=SensorStateClass.MEASUREMENT, uom_fn=lambda coordinator: TIME_MINUTES, value_fn=lambda coordinator, sensor_name: coordinator.runtimes[-1][sensor_name], name_fn=lambda coordinator, sensor_name: f"{coordinator.client.name} {RUNTIME_ATTRIBUTES[sensor_name]} Runtime",