mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 22:57:17 +00:00
Use attr** in tellstick sensor (#62422)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
4176cb15f6
commit
bd63b707fc
@ -6,13 +6,15 @@ from tellcore import telldus
|
|||||||
import tellcore.constants as tellcore_constants
|
import tellcore.constants as tellcore_constants
|
||||||
import voluptuous as vol
|
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 (
|
from homeassistant.const import (
|
||||||
CONF_ID,
|
CONF_ID,
|
||||||
CONF_NAME,
|
CONF_NAME,
|
||||||
CONF_PROTOCOL,
|
CONF_PROTOCOL,
|
||||||
DEVICE_CLASS_HUMIDITY,
|
|
||||||
DEVICE_CLASS_TEMPERATURE,
|
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
TEMP_CELSIUS,
|
TEMP_CELSIUS,
|
||||||
)
|
)
|
||||||
@ -62,12 +64,14 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
|
|
||||||
sensor_value_descriptions = {
|
sensor_value_descriptions = {
|
||||||
tellcore_constants.TELLSTICK_TEMPERATURE: DatatypeDescription(
|
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(
|
tellcore_constants.TELLSTICK_HUMIDITY: DatatypeDescription(
|
||||||
"humidity",
|
"humidity",
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
DEVICE_CLASS_HUMIDITY,
|
SensorDeviceClass.HUMIDITY,
|
||||||
),
|
),
|
||||||
tellcore_constants.TELLSTICK_RAINRATE: DatatypeDescription(
|
tellcore_constants.TELLSTICK_RAINRATE: DatatypeDescription(
|
||||||
"rain rate", "", None
|
"rain rate", "", None
|
||||||
@ -143,26 +147,9 @@ class TellstickSensor(SensorEntity):
|
|||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
self._datatype = datatype
|
self._datatype = datatype
|
||||||
self._tellcore_sensor = tellcore_sensor
|
self._tellcore_sensor = tellcore_sensor
|
||||||
self._unit_of_measurement = sensor_info.unit or None
|
self._attr_native_unit_of_measurement = sensor_info.unit or None
|
||||||
self._value = None
|
self._attr_name = f"{name} {sensor_info.name}"
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update tellstick sensor."""
|
"""Update tellstick sensor."""
|
||||||
self._value = self._tellcore_sensor.value(self._datatype).value
|
self._attr_native_value = self._tellcore_sensor.value(self._datatype).value
|
||||||
|
Loading…
x
Reference in New Issue
Block a user