Add state class to nest legacy sensors (#86810)

* Add state class to nest legacy sensors

Add state class (measurement) to humidity and temperature for the nest legacy sensors.

* Update

Update
This commit is contained in:
Luca Angemi 2023-01-28 06:20:51 +01:00 committed by GitHub
parent d97a061285
commit efd2817221
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,7 +3,11 @@
import logging
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
from homeassistant.components.sensor import (
SensorDeviceClass,
SensorEntity,
SensorStateClass,
)
from homeassistant.const import (
CONF_MONITORED_CONDITIONS,
CONF_SENSORS,
@ -48,6 +52,8 @@ SENSOR_UNITS = {"humidity": PERCENTAGE}
SENSOR_DEVICE_CLASSES = {"humidity": SensorDeviceClass.HUMIDITY}
SENSOR_STATE_CLASSES = {"humidity": SensorStateClass.MEASUREMENT}
VARIABLE_NAME_MAPPING = {"eta": "eta_begin", "operation_mode": "mode"}
VALUE_MAPPING = {
@ -167,6 +173,11 @@ class NestBasicSensor(NestSensorDevice, SensorEntity):
"""Return the device class of the sensor."""
return SENSOR_DEVICE_CLASSES.get(self.variable)
@property
def state_class(self):
"""Return the state class of the sensor."""
return SENSOR_STATE_CLASSES.get(self.variable)
def update(self):
"""Retrieve latest state."""
self._unit = SENSOR_UNITS.get(self.variable)
@ -202,6 +213,11 @@ class NestTempSensor(NestSensorDevice, SensorEntity):
"""Return the device class of the sensor."""
return SensorDeviceClass.TEMPERATURE
@property
def state_class(self):
"""Return the state class of the sensor."""
return SensorStateClass.MEASUREMENT
def update(self):
"""Retrieve latest state."""
if self.device.temperature_scale == "C":