Use new enums in nest (#61942)

This commit is contained in:
epenet 2021-12-15 22:00:10 +01:00 committed by GitHub
parent 1e9e056671
commit 25d33a2126
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 24 deletions

View file

@ -3,10 +3,7 @@ from itertools import chain
import logging import logging
from homeassistant.components.binary_sensor import ( from homeassistant.components.binary_sensor import (
DEVICE_CLASS_CONNECTIVITY, BinarySensorDeviceClass,
DEVICE_CLASS_MOTION,
DEVICE_CLASS_OCCUPANCY,
DEVICE_CLASS_SOUND,
BinarySensorEntity, BinarySensorEntity,
) )
from homeassistant.const import CONF_BINARY_SENSORS, CONF_MONITORED_CONDITIONS from homeassistant.const import CONF_BINARY_SENSORS, CONF_MONITORED_CONDITIONS
@ -16,7 +13,7 @@ from .const import DATA_NEST, DATA_NEST_CONFIG
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
BINARY_TYPES = {"online": DEVICE_CLASS_CONNECTIVITY} BINARY_TYPES = {"online": BinarySensorDeviceClass.CONNECTIVITY}
CLIMATE_BINARY_TYPES = { CLIMATE_BINARY_TYPES = {
"fan": None, "fan": None,
@ -26,9 +23,9 @@ CLIMATE_BINARY_TYPES = {
} }
CAMERA_BINARY_TYPES = { CAMERA_BINARY_TYPES = {
"motion_detected": DEVICE_CLASS_MOTION, "motion_detected": BinarySensorDeviceClass.MOTION,
"sound_detected": DEVICE_CLASS_SOUND, "sound_detected": BinarySensorDeviceClass.SOUND,
"person_detected": DEVICE_CLASS_OCCUPANCY, "person_detected": BinarySensorDeviceClass.OCCUPANCY,
} }
STRUCTURE_BINARY_TYPES = {"away": None} STRUCTURE_BINARY_TYPES = {"away": None}
@ -160,7 +157,7 @@ class NestActivityZoneSensor(NestBinarySensor):
@property @property
def device_class(self): def device_class(self):
"""Return the device class of the binary sensor.""" """Return the device class of the binary sensor."""
return DEVICE_CLASS_MOTION return BinarySensorDeviceClass.MOTION
def update(self): def update(self):
"""Retrieve latest state.""" """Retrieve latest state."""

View file

@ -1,12 +1,10 @@
"""Support for Nest Thermostat sensors for the legacy API.""" """Support for Nest Thermostat sensors for the legacy API."""
import logging import logging
from homeassistant.components.sensor import SensorEntity from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
from homeassistant.const import ( from homeassistant.const import (
CONF_MONITORED_CONDITIONS, CONF_MONITORED_CONDITIONS,
CONF_SENSORS, CONF_SENSORS,
DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_TEMPERATURE,
PERCENTAGE, PERCENTAGE,
STATE_OFF, STATE_OFF,
TEMP_CELSIUS, TEMP_CELSIUS,
@ -47,7 +45,7 @@ _VALID_SENSOR_TYPES = (
SENSOR_UNITS = {"humidity": PERCENTAGE} SENSOR_UNITS = {"humidity": PERCENTAGE}
SENSOR_DEVICE_CLASSES = {"humidity": DEVICE_CLASS_HUMIDITY} SENSOR_DEVICE_CLASSES = {"humidity": SensorDeviceClass.HUMIDITY}
VARIABLE_NAME_MAPPING = {"eta": "eta_begin", "operation_mode": "mode"} VARIABLE_NAME_MAPPING = {"eta": "eta_begin", "operation_mode": "mode"}
@ -201,7 +199,7 @@ class NestTempSensor(NestSensorDevice, SensorEntity):
@property @property
def device_class(self): def device_class(self):
"""Return the device class of the sensor.""" """Return the device class of the sensor."""
return DEVICE_CLASS_TEMPERATURE return SensorDeviceClass.TEMPERATURE
def update(self): def update(self):
"""Retrieve latest state.""" """Retrieve latest state."""

View file

@ -7,14 +7,13 @@ from google_nest_sdm.device import Device
from google_nest_sdm.device_traits import HumidityTrait, TemperatureTrait from google_nest_sdm.device_traits import HumidityTrait, TemperatureTrait
from google_nest_sdm.exceptions import GoogleNestException from google_nest_sdm.exceptions import GoogleNestException
from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT, SensorEntity from homeassistant.components.sensor import (
from homeassistant.config_entries import ConfigEntry SensorDeviceClass,
from homeassistant.const import ( SensorEntity,
DEVICE_CLASS_HUMIDITY, SensorStateClass,
DEVICE_CLASS_TEMPERATURE,
PERCENTAGE,
TEMP_CELSIUS,
) )
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import PERCENTAGE, TEMP_CELSIUS
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.exceptions import PlatformNotReady from homeassistant.exceptions import PlatformNotReady
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -58,7 +57,7 @@ class SensorBase(SensorEntity):
"""Representation of a dynamically updated Sensor.""" """Representation of a dynamically updated Sensor."""
_attr_shoud_poll = False _attr_shoud_poll = False
_attr_state_class = STATE_CLASS_MEASUREMENT _attr_state_class = SensorStateClass.MEASUREMENT
def __init__(self, device: Device) -> None: def __init__(self, device: Device) -> None:
"""Initialize the sensor.""" """Initialize the sensor."""
@ -77,7 +76,7 @@ class SensorBase(SensorEntity):
class TemperatureSensor(SensorBase): class TemperatureSensor(SensorBase):
"""Representation of a Temperature Sensor.""" """Representation of a Temperature Sensor."""
_attr_device_class = DEVICE_CLASS_TEMPERATURE _attr_device_class = SensorDeviceClass.TEMPERATURE
_attr_native_unit_of_measurement = TEMP_CELSIUS _attr_native_unit_of_measurement = TEMP_CELSIUS
@property @property
@ -98,7 +97,7 @@ class TemperatureSensor(SensorBase):
class HumiditySensor(SensorBase): class HumiditySensor(SensorBase):
"""Representation of a Humidity Sensor.""" """Representation of a Humidity Sensor."""
_attr_device_class = DEVICE_CLASS_HUMIDITY _attr_device_class = SensorDeviceClass.HUMIDITY
_attr_native_unit_of_measurement = PERCENTAGE _attr_native_unit_of_measurement = PERCENTAGE
@property @property