2020-05-12 14:10:03 +00:00
|
|
|
"""BleBox sensor entities."""
|
|
|
|
|
|
|
|
from homeassistant.helpers.entity import Entity
|
|
|
|
|
|
|
|
from . import BleBoxEntity, create_blebox_entities
|
2020-05-15 21:48:17 +00:00
|
|
|
from .const import BLEBOX_TO_HASS_DEVICE_CLASSES, BLEBOX_TO_UNIT_MAP, DOMAIN, PRODUCT
|
2020-05-12 14:10:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def async_setup_entry(hass, config_entry, async_add):
|
|
|
|
"""Set up a BleBox entry."""
|
|
|
|
|
|
|
|
product = hass.data[DOMAIN][config_entry.entry_id][PRODUCT]
|
|
|
|
create_blebox_entities(product, async_add, BleBoxSensorEntity, "sensors")
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
class BleBoxSensorEntity(BleBoxEntity, Entity):
|
|
|
|
"""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 21:48:17 +00:00
|
|
|
return BLEBOX_TO_HASS_DEVICE_CLASSES[self._feature.device_class]
|