2019-02-13 20:21:14 +00:00
|
|
|
"""Support for Tahoma sensors."""
|
2017-11-19 20:35:13 +00:00
|
|
|
import logging
|
|
|
|
from datetime import timedelta
|
|
|
|
|
|
|
|
from homeassistant.helpers.entity import Entity
|
|
|
|
from homeassistant.components.tahoma import (
|
|
|
|
DOMAIN as TAHOMA_DOMAIN, TahomaDevice)
|
2018-08-26 19:20:34 +00:00
|
|
|
from homeassistant.const import ATTR_BATTERY_LEVEL
|
2017-11-19 20:35:13 +00:00
|
|
|
|
|
|
|
DEPENDENCIES = ['tahoma']
|
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2018-08-26 19:20:34 +00:00
|
|
|
SCAN_INTERVAL = timedelta(seconds=60)
|
|
|
|
|
|
|
|
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."""
|
|
|
|
controller = hass.data[TAHOMA_DOMAIN]['controller']
|
|
|
|
devices = []
|
|
|
|
for device in hass.data[TAHOMA_DOMAIN]['devices']['sensor']:
|
|
|
|
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."""
|
|
|
|
if self.tahoma_device.type == 'Temperature Sensor':
|
|
|
|
return None
|
2018-07-23 08:16:05 +00:00
|
|
|
if self.tahoma_device.type == 'io:SomfyContactIOSystemSensor':
|
2018-04-25 05:09:45 +00:00
|
|
|
return None
|
2018-07-23 08:16:05 +00:00
|
|
|
if self.tahoma_device.type == 'io:LightIOSystemSensor':
|
2018-05-05 13:37:40 +00:00
|
|
|
return 'lx'
|
2018-07-23 08:16:05 +00:00
|
|
|
if self.tahoma_device.type == 'Humidity Sensor':
|
2017-11-19 20:35:13 +00:00
|
|
|
return '%'
|
2018-09-14 19:31:08 +00:00
|
|
|
if self.tahoma_device.type == 'rtds:RTDSContactSensor':
|
|
|
|
return None
|
|
|
|
if self.tahoma_device.type == 'rtds:RTDSMotionSensor':
|
|
|
|
return None
|
2017-11-19 20:35:13 +00:00
|
|
|
|
|
|
|
def update(self):
|
|
|
|
"""Update the state."""
|
|
|
|
self.controller.get_states([self.tahoma_device])
|
|
|
|
if self.tahoma_device.type == 'io:LightIOSystemSensor':
|
|
|
|
self.current_value = self.tahoma_device.active_states[
|
|
|
|
'core:LuminanceState']
|
2018-09-14 19:31:08 +00:00
|
|
|
self._available = bool(self.tahoma_device.active_states.get(
|
|
|
|
'core:StatusState') == 'available')
|
2018-04-25 05:09:45 +00:00
|
|
|
if self.tahoma_device.type == 'io:SomfyContactIOSystemSensor':
|
|
|
|
self.current_value = self.tahoma_device.active_states[
|
|
|
|
'core:ContactState']
|
2018-09-14 19:31:08 +00:00
|
|
|
self._available = bool(self.tahoma_device.active_states.get(
|
|
|
|
'core:StatusState') == 'available')
|
|
|
|
if self.tahoma_device.type == 'rtds:RTDSContactSensor':
|
|
|
|
self.current_value = self.tahoma_device.active_states[
|
|
|
|
'core:ContactState']
|
|
|
|
self._available = True
|
|
|
|
if self.tahoma_device.type == 'rtds:RTDSMotionSensor':
|
|
|
|
self.current_value = self.tahoma_device.active_states[
|
|
|
|
'core:OccupancyState']
|
|
|
|
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)
|
|
|
|
|
|
|
|
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']
|
|
|
|
return attr
|
|
|
|
|
|
|
|
@property
|
|
|
|
def available(self):
|
|
|
|
"""Return True if entity is available."""
|
|
|
|
return self._available
|