2020-05-12 14:10:03 +00:00
|
|
|
"""BleBox sensor entities."""
|
|
|
|
|
2021-03-22 11:37:16 +00:00
|
|
|
from homeassistant.components.sensor import SensorEntity
|
2020-05-12 14:10:03 +00:00
|
|
|
|
|
|
|
from . import BleBoxEntity, create_blebox_entities
|
2020-05-16 15:51:37 +00:00
|
|
|
from .const import BLEBOX_TO_HASS_DEVICE_CLASSES, BLEBOX_TO_UNIT_MAP
|
2020-05-12 14:10:03 +00:00
|
|
|
|
|
|
|
|
2020-05-18 20:30:15 +00:00
|
|
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
2020-05-12 14:10:03 +00:00
|
|
|
"""Set up a BleBox entry."""
|
|
|
|
|
2020-05-18 20:30:15 +00:00
|
|
|
create_blebox_entities(
|
|
|
|
hass, config_entry, async_add_entities, BleBoxSensorEntity, "sensors"
|
|
|
|
)
|
2020-05-12 14:10:03 +00:00
|
|
|
|
|
|
|
|
2021-03-22 19:05:13 +00:00
|
|
|
class BleBoxSensorEntity(BleBoxEntity, SensorEntity):
|
2020-05-12 14:10:03 +00:00
|
|
|
"""Representation of a BleBox sensor feature."""
|
|
|
|
|
2021-07-12 20:52:38 +00:00
|
|
|
def __init__(self, feature):
|
|
|
|
"""Initialize a BleBox sensor feature."""
|
|
|
|
super().__init__(feature)
|
2021-08-11 08:45:05 +00:00
|
|
|
self._attr_native_unit_of_measurement = BLEBOX_TO_UNIT_MAP[feature.unit]
|
2021-07-12 20:52:38 +00:00
|
|
|
self._attr_device_class = BLEBOX_TO_HASS_DEVICE_CLASSES[feature.device_class]
|
|
|
|
|
2020-05-12 14:10:03 +00:00
|
|
|
@property
|
2021-08-11 08:45:05 +00:00
|
|
|
def native_value(self):
|
2020-05-12 14:10:03 +00:00
|
|
|
"""Return the state."""
|
|
|
|
return self._feature.current
|