2016-06-24 08:06:58 +00:00
|
|
|
"""
|
2016-06-30 08:33:34 +00:00
|
|
|
Support for Homematic binary sensors.
|
2016-06-24 08:06:58 +00:00
|
|
|
|
|
|
|
For more details about this platform, please refer to the documentation at
|
|
|
|
https://home-assistant.io/components/binary_sensor.homematic/
|
|
|
|
"""
|
|
|
|
import logging
|
|
|
|
from homeassistant.const import STATE_UNKNOWN
|
|
|
|
from homeassistant.components.binary_sensor import BinarySensorDevice
|
2016-11-29 19:53:02 +00:00
|
|
|
from homeassistant.components.homematic import HMDevice
|
|
|
|
from homeassistant.loader import get_component
|
2016-06-24 08:06:58 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
DEPENDENCIES = ['homematic']
|
|
|
|
|
|
|
|
SENSOR_TYPES_CLASS = {
|
|
|
|
"Remote": None,
|
|
|
|
"ShutterContact": "opening",
|
2016-10-03 21:21:53 +00:00
|
|
|
"IPShutterContact": "opening",
|
2016-06-24 08:06:58 +00:00
|
|
|
"Smoke": "smoke",
|
|
|
|
"SmokeV2": "smoke",
|
|
|
|
"Motion": "motion",
|
|
|
|
"MotionV2": "motion",
|
2016-08-25 19:55:03 +00:00
|
|
|
"RemoteMotion": None,
|
|
|
|
"WeatherSensor": None,
|
|
|
|
"TiltSensor": None,
|
2016-06-24 08:06:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def setup_platform(hass, config, add_callback_devices, discovery_info=None):
|
2016-06-30 08:33:34 +00:00
|
|
|
"""Setup the Homematic binary sensor platform."""
|
2016-06-28 20:53:53 +00:00
|
|
|
if discovery_info is None:
|
|
|
|
return
|
|
|
|
|
2016-11-29 19:53:02 +00:00
|
|
|
homematic = get_component("homematic")
|
2016-09-09 17:33:12 +00:00
|
|
|
return homematic.setup_hmdevice_discovery_helper(
|
2016-11-29 19:53:02 +00:00
|
|
|
hass,
|
2016-09-09 17:33:12 +00:00
|
|
|
HMBinarySensor,
|
|
|
|
discovery_info,
|
|
|
|
add_callback_devices
|
|
|
|
)
|
2016-06-24 08:06:58 +00:00
|
|
|
|
|
|
|
|
2016-11-29 19:53:02 +00:00
|
|
|
class HMBinarySensor(HMDevice, BinarySensorDevice):
|
2016-06-30 08:33:34 +00:00
|
|
|
"""Representation of a binary Homematic device."""
|
2016-06-24 08:06:58 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self):
|
2016-06-30 08:33:34 +00:00
|
|
|
"""Return true if switch is on."""
|
2016-06-24 08:06:58 +00:00
|
|
|
if not self.available:
|
|
|
|
return False
|
|
|
|
return bool(self._hm_get_state())
|
|
|
|
|
|
|
|
@property
|
|
|
|
def sensor_class(self):
|
|
|
|
"""Return the class of this sensor, from SENSOR_CLASSES."""
|
|
|
|
if not self.available:
|
|
|
|
return None
|
|
|
|
|
|
|
|
# If state is MOTION (RemoteMotion works only)
|
2016-06-24 17:46:42 +00:00
|
|
|
if self._state == "MOTION":
|
2016-06-24 08:06:58 +00:00
|
|
|
return "motion"
|
|
|
|
return SENSOR_TYPES_CLASS.get(self._hmdevice.__class__.__name__, None)
|
|
|
|
|
|
|
|
def _init_data_struct(self):
|
2016-06-30 08:33:34 +00:00
|
|
|
"""Generate a data struct (self._data) from the Homematic metadata."""
|
2016-06-24 08:06:58 +00:00
|
|
|
# add state to data struct
|
|
|
|
if self._state:
|
|
|
|
_LOGGER.debug("%s init datastruct with main node '%s'", self._name,
|
|
|
|
self._state)
|
|
|
|
self._data.update({self._state: STATE_UNKNOWN})
|