2019-02-14 15:01:46 +00:00
|
|
|
"""Support for HomeMatic binary sensors."""
|
2016-06-24 08:06:58 +00:00
|
|
|
import logging
|
2018-08-21 19:25:16 +00:00
|
|
|
|
2019-11-01 20:25:33 +00:00
|
|
|
from homeassistant.components.binary_sensor import (
|
|
|
|
DEVICE_CLASS_BATTERY,
|
|
|
|
DEVICE_CLASS_MOTION,
|
|
|
|
DEVICE_CLASS_OPENING,
|
|
|
|
DEVICE_CLASS_PRESENCE,
|
|
|
|
DEVICE_CLASS_SMOKE,
|
|
|
|
BinarySensorDevice,
|
|
|
|
)
|
2016-06-24 08:06:58 +00:00
|
|
|
|
2020-01-14 10:26:59 +00:00
|
|
|
from .const import ATTR_DISCOVER_DEVICES, ATTR_DISCOVERY_TYPE, DISCOVER_BATTERY
|
|
|
|
from .entity import HMDevice
|
2019-03-21 05:56:46 +00:00
|
|
|
|
2016-06-24 08:06:58 +00:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
SENSOR_TYPES_CLASS = {
|
2019-11-01 20:25:33 +00:00
|
|
|
"IPShutterContact": DEVICE_CLASS_OPENING,
|
|
|
|
"IPShutterContactSabotage": DEVICE_CLASS_OPENING,
|
|
|
|
"MaxShutterContact": DEVICE_CLASS_OPENING,
|
|
|
|
"Motion": DEVICE_CLASS_MOTION,
|
|
|
|
"MotionV2": DEVICE_CLASS_MOTION,
|
|
|
|
"PresenceIP": DEVICE_CLASS_PRESENCE,
|
2019-07-31 19:25:30 +00:00
|
|
|
"Remote": None,
|
|
|
|
"RemoteMotion": None,
|
2019-11-01 20:25:33 +00:00
|
|
|
"ShutterContact": DEVICE_CLASS_OPENING,
|
|
|
|
"Smoke": DEVICE_CLASS_SMOKE,
|
|
|
|
"SmokeV2": DEVICE_CLASS_SMOKE,
|
2019-07-31 19:25:30 +00:00
|
|
|
"TiltSensor": None,
|
|
|
|
"WeatherSensor": None,
|
2020-01-08 23:32:57 +00:00
|
|
|
"IPContact": DEVICE_CLASS_OPENING,
|
2016-06-24 08:06:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-24 14:37:30 +00:00
|
|
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
2017-06-10 08:08:36 +00:00
|
|
|
"""Set up the HomeMatic binary sensor platform."""
|
2016-06-28 20:53:53 +00:00
|
|
|
if discovery_info is None:
|
|
|
|
return
|
|
|
|
|
2017-02-20 16:07:33 +00:00
|
|
|
devices = []
|
2017-07-06 06:30:01 +00:00
|
|
|
for conf in discovery_info[ATTR_DISCOVER_DEVICES]:
|
2019-05-13 18:52:55 +00:00
|
|
|
if discovery_info[ATTR_DISCOVERY_TYPE] == DISCOVER_BATTERY:
|
|
|
|
devices.append(HMBatterySensor(conf))
|
2019-05-09 17:38:51 +00:00
|
|
|
else:
|
2019-05-13 18:52:55 +00:00
|
|
|
devices.append(HMBinarySensor(conf))
|
2017-02-20 16:07:33 +00:00
|
|
|
|
2020-01-14 10:26:59 +00:00
|
|
|
add_entities(devices, True)
|
2016-06-24 08:06:58 +00:00
|
|
|
|
|
|
|
|
2016-11-29 19:53:02 +00:00
|
|
|
class HMBinarySensor(HMDevice, BinarySensorDevice):
|
2017-06-10 08:08:36 +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
|
2017-02-11 04:46:15 +00:00
|
|
|
def device_class(self):
|
2017-06-10 08:08:36 +00:00
|
|
|
"""Return the class of this sensor from DEVICE_CLASSES."""
|
|
|
|
# If state is MOTION (Only RemoteMotion working)
|
2019-07-31 19:25:30 +00:00
|
|
|
if self._state == "MOTION":
|
2019-11-01 20:25:33 +00:00
|
|
|
return DEVICE_CLASS_MOTION
|
|
|
|
return SENSOR_TYPES_CLASS.get(self._hmdevice.__class__.__name__)
|
2016-06-24 08:06:58 +00:00
|
|
|
|
|
|
|
def _init_data_struct(self):
|
2017-06-10 08:08:36 +00:00
|
|
|
"""Generate the data dictionary (self._data) from metadata."""
|
|
|
|
# Add state to data struct
|
2016-06-24 08:06:58 +00:00
|
|
|
if self._state:
|
2019-05-13 18:52:55 +00:00
|
|
|
self._data.update({self._state: None})
|
2019-05-09 17:38:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
class HMBatterySensor(HMDevice, BinarySensorDevice):
|
|
|
|
"""Representation of an HomeMatic low battery sensor."""
|
|
|
|
|
|
|
|
@property
|
|
|
|
def device_class(self):
|
|
|
|
"""Return battery as a device class."""
|
|
|
|
return DEVICE_CLASS_BATTERY
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self):
|
|
|
|
"""Return True if battery is low."""
|
2019-05-13 18:52:55 +00:00
|
|
|
return bool(self._hm_get_state())
|
2019-05-09 17:38:51 +00:00
|
|
|
|
|
|
|
def _init_data_struct(self):
|
|
|
|
"""Generate the data dictionary (self._data) from metadata."""
|
|
|
|
# Add state to data struct
|
|
|
|
if self._state:
|
2019-05-13 18:52:55 +00:00
|
|
|
self._data.update({self._state: None})
|