mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 09:17:10 +00:00
Use enums in venstar (#61993)
This commit is contained in:
parent
521458d981
commit
21e46e318d
@ -1,6 +1,6 @@
|
|||||||
"""Alarm sensors for the Venstar Thermostat."""
|
"""Alarm sensors for the Venstar Thermostat."""
|
||||||
from homeassistant.components.binary_sensor import (
|
from homeassistant.components.binary_sensor import (
|
||||||
DEVICE_CLASS_PROBLEM,
|
BinarySensorDeviceClass,
|
||||||
BinarySensorEntity,
|
BinarySensorEntity,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities) -> None:
|
|||||||
class VenstarBinarySensor(VenstarEntity, BinarySensorEntity):
|
class VenstarBinarySensor(VenstarEntity, BinarySensorEntity):
|
||||||
"""Represent a Venstar alert."""
|
"""Represent a Venstar alert."""
|
||||||
|
|
||||||
_attr_device_class = DEVICE_CLASS_PROBLEM
|
_attr_device_class = BinarySensorDeviceClass.PROBLEM
|
||||||
|
|
||||||
def __init__(self, coordinator, config, alert):
|
def __init__(self, coordinator, config, alert):
|
||||||
"""Initialize the alert."""
|
"""Initialize the alert."""
|
||||||
|
@ -6,12 +6,10 @@ from dataclasses import dataclass
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
DEVICE_CLASS_BATTERY,
|
SensorDeviceClass,
|
||||||
DEVICE_CLASS_HUMIDITY,
|
|
||||||
DEVICE_CLASS_TEMPERATURE,
|
|
||||||
STATE_CLASS_MEASUREMENT,
|
|
||||||
SensorEntity,
|
SensorEntity,
|
||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import PERCENTAGE, TEMP_CELSIUS, TEMP_FAHRENHEIT, TIME_MINUTES
|
from homeassistant.const import PERCENTAGE, TEMP_CELSIUS, TEMP_FAHRENHEIT, TIME_MINUTES
|
||||||
@ -145,8 +143,8 @@ class VenstarSensor(VenstarEntity, SensorEntity):
|
|||||||
SENSOR_ENTITIES: tuple[VenstarSensorEntityDescription, ...] = (
|
SENSOR_ENTITIES: tuple[VenstarSensorEntityDescription, ...] = (
|
||||||
VenstarSensorEntityDescription(
|
VenstarSensorEntityDescription(
|
||||||
key="hum",
|
key="hum",
|
||||||
device_class=DEVICE_CLASS_HUMIDITY,
|
device_class=SensorDeviceClass.HUMIDITY,
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
uom_fn=lambda coordinator: PERCENTAGE,
|
uom_fn=lambda coordinator: PERCENTAGE,
|
||||||
value_fn=lambda coordinator, sensor_name: coordinator.client.get_sensor(
|
value_fn=lambda coordinator, sensor_name: coordinator.client.get_sensor(
|
||||||
sensor_name, "hum"
|
sensor_name, "hum"
|
||||||
@ -155,8 +153,8 @@ SENSOR_ENTITIES: tuple[VenstarSensorEntityDescription, ...] = (
|
|||||||
),
|
),
|
||||||
VenstarSensorEntityDescription(
|
VenstarSensorEntityDescription(
|
||||||
key="temp",
|
key="temp",
|
||||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
uom_fn=temperature_unit,
|
uom_fn=temperature_unit,
|
||||||
value_fn=lambda coordinator, sensor_name: round(
|
value_fn=lambda coordinator, sensor_name: round(
|
||||||
float(coordinator.client.get_sensor(sensor_name, "temp")), 1
|
float(coordinator.client.get_sensor(sensor_name, "temp")), 1
|
||||||
@ -165,8 +163,8 @@ SENSOR_ENTITIES: tuple[VenstarSensorEntityDescription, ...] = (
|
|||||||
),
|
),
|
||||||
VenstarSensorEntityDescription(
|
VenstarSensorEntityDescription(
|
||||||
key="battery",
|
key="battery",
|
||||||
device_class=DEVICE_CLASS_BATTERY,
|
device_class=SensorDeviceClass.BATTERY,
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
uom_fn=lambda coordinator: PERCENTAGE,
|
uom_fn=lambda coordinator: PERCENTAGE,
|
||||||
value_fn=lambda coordinator, sensor_name: coordinator.client.get_sensor(
|
value_fn=lambda coordinator, sensor_name: coordinator.client.get_sensor(
|
||||||
sensor_name, "battery"
|
sensor_name, "battery"
|
||||||
@ -177,7 +175,7 @@ SENSOR_ENTITIES: tuple[VenstarSensorEntityDescription, ...] = (
|
|||||||
|
|
||||||
RUNTIME_ENTITY = VenstarSensorEntityDescription(
|
RUNTIME_ENTITY = VenstarSensorEntityDescription(
|
||||||
key="runtime",
|
key="runtime",
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
uom_fn=lambda coordinator: TIME_MINUTES,
|
uom_fn=lambda coordinator: TIME_MINUTES,
|
||||||
value_fn=lambda coordinator, sensor_name: coordinator.runtimes[-1][sensor_name],
|
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",
|
name_fn=lambda coordinator, sensor_name: f"{coordinator.client.name} {RUNTIME_ATTRIBUTES[sensor_name]} Runtime",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user