Use attr** in tellstick sensor (#62422)
Co-authored-by: epenet <epenet@users.noreply.github.com>pull/62440/head
parent
4176cb15f6
commit
bd63b707fc
|
@ -6,13 +6,15 @@ from tellcore import telldus
|
|||
import tellcore.constants as tellcore_constants
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
||||
from homeassistant.components.sensor import (
|
||||
PLATFORM_SCHEMA,
|
||||
SensorDeviceClass,
|
||||
SensorEntity,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
CONF_ID,
|
||||
CONF_NAME,
|
||||
CONF_PROTOCOL,
|
||||
DEVICE_CLASS_HUMIDITY,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
PERCENTAGE,
|
||||
TEMP_CELSIUS,
|
||||
)
|
||||
|
@ -62,12 +64,14 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
|
||||
sensor_value_descriptions = {
|
||||
tellcore_constants.TELLSTICK_TEMPERATURE: DatatypeDescription(
|
||||
"temperature", config.get(CONF_TEMPERATURE_SCALE), DEVICE_CLASS_TEMPERATURE
|
||||
"temperature",
|
||||
config.get(CONF_TEMPERATURE_SCALE),
|
||||
SensorDeviceClass.TEMPERATURE,
|
||||
),
|
||||
tellcore_constants.TELLSTICK_HUMIDITY: DatatypeDescription(
|
||||
"humidity",
|
||||
PERCENTAGE,
|
||||
DEVICE_CLASS_HUMIDITY,
|
||||
SensorDeviceClass.HUMIDITY,
|
||||
),
|
||||
tellcore_constants.TELLSTICK_RAINRATE: DatatypeDescription(
|
||||
"rain rate", "", None
|
||||
|
@ -143,26 +147,9 @@ class TellstickSensor(SensorEntity):
|
|||
"""Initialize the sensor."""
|
||||
self._datatype = datatype
|
||||
self._tellcore_sensor = tellcore_sensor
|
||||
self._unit_of_measurement = sensor_info.unit or None
|
||||
self._value = None
|
||||
|
||||
self._name = f"{name} {sensor_info.name}"
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._value
|
||||
|
||||
@property
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit of measurement of this entity, if any."""
|
||||
return self._unit_of_measurement
|
||||
self._attr_native_unit_of_measurement = sensor_info.unit or None
|
||||
self._attr_name = f"{name} {sensor_info.name}"
|
||||
|
||||
def update(self):
|
||||
"""Update tellstick sensor."""
|
||||
self._value = self._tellcore_sensor.value(self._datatype).value
|
||||
self._attr_native_value = self._tellcore_sensor.value(self._datatype).value
|
||||
|
|
Loading…
Reference in New Issue