2020-05-12 16:10:03 +02:00
|
|
|
"""BleBox sensor entities."""
|
|
|
|
|
2021-03-22 12:37:16 +01:00
|
|
|
from homeassistant.components.sensor import SensorEntity
|
2020-05-12 16:10:03 +02:00
|
|
|
|
|
|
|
from . import BleBoxEntity, create_blebox_entities
|
2020-05-16 17:51:37 +02:00
|
|
|
from .const import BLEBOX_TO_HASS_DEVICE_CLASSES, BLEBOX_TO_UNIT_MAP
|
2020-05-12 16:10:03 +02:00
|
|
|
|
|
|
|
|
2020-05-18 22:30:15 +02:00
|
|
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
2020-05-12 16:10:03 +02:00
|
|
|
"""Set up a BleBox entry."""
|
|
|
|
|
2020-05-18 22:30:15 +02:00
|
|
|
create_blebox_entities(
|
|
|
|
hass, config_entry, async_add_entities, BleBoxSensorEntity, "sensors"
|
|
|
|
)
|
2020-05-12 16:10:03 +02:00
|
|
|
|
|
|
|
|
2021-03-22 20:05:13 +01:00
|
|
|
class BleBoxSensorEntity(BleBoxEntity, SensorEntity):
|
2020-05-12 16:10:03 +02:00
|
|
|
"""Representation of a BleBox sensor feature."""
|
|
|
|
|
|
|
|
@property
|
|
|
|
def state(self):
|
|
|
|
"""Return the state."""
|
|
|
|
return self._feature.current
|
|
|
|
|
|
|
|
@property
|
|
|
|
def unit_of_measurement(self):
|
|
|
|
"""Return the unit."""
|
|
|
|
return BLEBOX_TO_UNIT_MAP[self._feature.unit]
|
|
|
|
|
|
|
|
@property
|
|
|
|
def device_class(self):
|
|
|
|
"""Return the device class."""
|
2020-05-15 23:48:17 +02:00
|
|
|
return BLEBOX_TO_HASS_DEVICE_CLASSES[self._feature.device_class]
|