Use enums in venstar (#61993)

This commit is contained in:
Robert Hillis 2021-12-16 11:42:24 -05:00 committed by GitHub
parent 521458d981
commit 21e46e318d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 13 deletions

View File

@ -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."""

View File

@ -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",