2019-02-13 20:21:14 +00:00
|
|
|
"""Support for Tahoma sensors."""
|
2017-11-19 20:35:13 +00:00
|
|
|
from datetime import timedelta
|
2019-03-21 05:56:46 +00:00
|
|
|
import logging
|
2017-11-19 20:35:13 +00:00
|
|
|
|
2018-08-26 19:20:34 +00:00
|
|
|
from homeassistant.const import ATTR_BATTERY_LEVEL
|
2019-03-21 05:56:46 +00:00
|
|
|
from homeassistant.helpers.entity import Entity
|
|
|
|
|
|
|
|
from . import DOMAIN as TAHOMA_DOMAIN, TahomaDevice
|
2017-11-19 20:35:13 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2018-08-26 19:20:34 +00:00
|
|
|
SCAN_INTERVAL = timedelta(seconds=60)
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
ATTR_RSSI_LEVEL = "rssi_level"
|
2017-11-19 20:35:13 +00:00
|
|
|
|
|
|
|
|
2018-08-24 14:37:30 +00:00
|
|
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
2017-11-19 20:35:13 +00:00
|
|
|
"""Set up Tahoma controller devices."""
|
2019-07-31 19:25:30 +00:00
|
|
|
controller = hass.data[TAHOMA_DOMAIN]["controller"]
|
2017-11-19 20:35:13 +00:00
|
|
|
devices = []
|
2019-07-31 19:25:30 +00:00
|
|
|
for device in hass.data[TAHOMA_DOMAIN]["devices"]["sensor"]:
|
2017-11-19 20:35:13 +00:00
|
|
|
devices.append(TahomaSensor(device, controller))
|
2018-08-24 14:37:30 +00:00
|
|
|
add_entities(devices, True)
|
2017-11-19 20:35:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TahomaSensor(TahomaDevice, Entity):
|
|
|
|
"""Representation of a Tahoma Sensor."""
|
|
|
|
|
|
|
|
def __init__(self, tahoma_device, controller):
|
|
|
|
"""Initialize the sensor."""
|
|
|
|
self.current_value = None
|
2018-08-26 19:20:34 +00:00
|
|
|
self._available = False
|
2017-11-19 20:35:13 +00:00
|
|
|
super().__init__(tahoma_device, controller)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def state(self):
|
|
|
|
"""Return the name of the sensor."""
|
|
|
|
return self.current_value
|
|
|
|
|
|
|
|
@property
|
|
|
|
def unit_of_measurement(self):
|
|
|
|
"""Return the unit of measurement of this entity, if any."""
|
2019-07-31 19:25:30 +00:00
|
|
|
if self.tahoma_device.type == "Temperature Sensor":
|
2017-11-19 20:35:13 +00:00
|
|
|
return None
|
2019-07-31 19:25:30 +00:00
|
|
|
if self.tahoma_device.type == "io:SomfyContactIOSystemSensor":
|
2018-04-25 05:09:45 +00:00
|
|
|
return None
|
2019-10-05 23:12:50 +00:00
|
|
|
if self.tahoma_device.type == "io:SomfyBasicContactIOSystemSensor":
|
|
|
|
return None
|
2019-07-31 19:25:30 +00:00
|
|
|
if self.tahoma_device.type == "io:LightIOSystemSensor":
|
|
|
|
return "lx"
|
|
|
|
if self.tahoma_device.type == "Humidity Sensor":
|
|
|
|
return "%"
|
|
|
|
if self.tahoma_device.type == "rtds:RTDSContactSensor":
|
2018-09-14 19:31:08 +00:00
|
|
|
return None
|
2019-07-31 19:25:30 +00:00
|
|
|
if self.tahoma_device.type == "rtds:RTDSMotionSensor":
|
2018-09-14 19:31:08 +00:00
|
|
|
return None
|
2017-11-19 20:35:13 +00:00
|
|
|
|
|
|
|
def update(self):
|
|
|
|
"""Update the state."""
|
|
|
|
self.controller.get_states([self.tahoma_device])
|
2019-07-31 19:25:30 +00:00
|
|
|
if self.tahoma_device.type == "io:LightIOSystemSensor":
|
|
|
|
self.current_value = self.tahoma_device.active_states["core:LuminanceState"]
|
|
|
|
self._available = bool(
|
|
|
|
self.tahoma_device.active_states.get("core:StatusState") == "available"
|
|
|
|
)
|
|
|
|
if self.tahoma_device.type == "io:SomfyContactIOSystemSensor":
|
|
|
|
self.current_value = self.tahoma_device.active_states["core:ContactState"]
|
|
|
|
self._available = bool(
|
|
|
|
self.tahoma_device.active_states.get("core:StatusState") == "available"
|
|
|
|
)
|
2019-10-05 23:12:50 +00:00
|
|
|
if self.tahoma_device.type == "io:SomfyBasicContactIOSystemSensor":
|
|
|
|
self.current_value = self.tahoma_device.active_states["core:ContactState"]
|
|
|
|
self._available = bool(
|
|
|
|
self.tahoma_device.active_states.get("core:StatusState") == "available"
|
|
|
|
)
|
2019-07-31 19:25:30 +00:00
|
|
|
if self.tahoma_device.type == "rtds:RTDSContactSensor":
|
|
|
|
self.current_value = self.tahoma_device.active_states["core:ContactState"]
|
2018-09-14 19:31:08 +00:00
|
|
|
self._available = True
|
2019-07-31 19:25:30 +00:00
|
|
|
if self.tahoma_device.type == "rtds:RTDSMotionSensor":
|
|
|
|
self.current_value = self.tahoma_device.active_states["core:OccupancyState"]
|
2018-09-14 19:31:08 +00:00
|
|
|
self._available = True
|
2018-08-26 19:20:34 +00:00
|
|
|
|
|
|
|
_LOGGER.debug("Update %s, value: %d", self._name, self.current_value)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def device_state_attributes(self):
|
|
|
|
"""Return the device state attributes."""
|
|
|
|
attr = {}
|
|
|
|
super_attr = super().device_state_attributes
|
|
|
|
if super_attr is not None:
|
|
|
|
attr.update(super_attr)
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
if "core:RSSILevelState" in self.tahoma_device.active_states:
|
|
|
|
attr[ATTR_RSSI_LEVEL] = self.tahoma_device.active_states[
|
|
|
|
"core:RSSILevelState"
|
|
|
|
]
|
|
|
|
if "core:SensorDefectState" in self.tahoma_device.active_states:
|
|
|
|
attr[ATTR_BATTERY_LEVEL] = self.tahoma_device.active_states[
|
|
|
|
"core:SensorDefectState"
|
|
|
|
]
|
2018-08-26 19:20:34 +00:00
|
|
|
return attr
|
|
|
|
|
|
|
|
@property
|
|
|
|
def available(self):
|
|
|
|
"""Return True if entity is available."""
|
|
|
|
return self._available
|