2019-02-14 04:35:12 +00:00
|
|
|
"""Support for MAX! binary sensors via MAX! Cube."""
|
2020-09-12 02:24:23 +00:00
|
|
|
from homeassistant.components.binary_sensor import (
|
|
|
|
DEVICE_CLASS_WINDOW,
|
|
|
|
BinarySensorEntity,
|
|
|
|
)
|
2019-03-21 05:56:46 +00:00
|
|
|
|
|
|
|
from . import DATA_KEY
|
2017-02-27 05:35:33 +00:00
|
|
|
|
|
|
|
|
2018-08-24 14:37:30 +00:00
|
|
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
2017-04-22 19:13:04 +00:00
|
|
|
"""Iterate through all MAX! Devices and add window shutters."""
|
2017-02-27 05:35:33 +00:00
|
|
|
devices = []
|
2018-04-19 07:11:38 +00:00
|
|
|
for handler in hass.data[DATA_KEY].values():
|
|
|
|
cube = handler.cube
|
|
|
|
for device in cube.devices:
|
2020-03-10 22:34:54 +00:00
|
|
|
name = f"{cube.room_by_id(device.room_id).name} {device.name}"
|
2017-02-27 05:35:33 +00:00
|
|
|
|
2018-04-19 07:11:38 +00:00
|
|
|
# Only add Window Shutters
|
2020-11-05 08:45:29 +00:00
|
|
|
if cube.is_windowshutter(device):
|
2019-07-31 19:25:30 +00:00
|
|
|
devices.append(MaxCubeShutter(handler, name, device.rf_address))
|
2017-02-27 05:35:33 +00:00
|
|
|
|
2017-04-24 03:41:09 +00:00
|
|
|
if devices:
|
2018-08-24 14:37:30 +00:00
|
|
|
add_entities(devices)
|
2017-02-27 05:35:33 +00:00
|
|
|
|
|
|
|
|
2020-04-23 19:57:07 +00:00
|
|
|
class MaxCubeShutter(BinarySensorEntity):
|
2017-04-22 19:13:04 +00:00
|
|
|
"""Representation of a MAX! Cube Binary Sensor device."""
|
2017-02-27 05:35:33 +00:00
|
|
|
|
2018-04-19 07:11:38 +00:00
|
|
|
def __init__(self, handler, name, rf_address):
|
2020-04-23 19:57:07 +00:00
|
|
|
"""Initialize MAX! Cube BinarySensorEntity."""
|
2017-02-27 05:35:33 +00:00
|
|
|
self._name = name
|
2020-09-12 02:24:23 +00:00
|
|
|
self._sensor_type = DEVICE_CLASS_WINDOW
|
2017-02-27 05:35:33 +00:00
|
|
|
self._rf_address = rf_address
|
2018-04-19 07:11:38 +00:00
|
|
|
self._cubehandle = handler
|
2019-01-24 07:20:20 +00:00
|
|
|
self._state = None
|
2017-02-27 05:35:33 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
2020-04-23 19:57:07 +00:00
|
|
|
"""Return the name of the BinarySensorEntity."""
|
2017-02-27 05:35:33 +00:00
|
|
|
return self._name
|
|
|
|
|
|
|
|
@property
|
|
|
|
def device_class(self):
|
|
|
|
"""Return the class of this sensor."""
|
|
|
|
return self._sensor_type
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self):
|
|
|
|
"""Return true if the binary sensor is on/open."""
|
|
|
|
return self._state
|
|
|
|
|
|
|
|
def update(self):
|
|
|
|
"""Get latest data from MAX! Cube."""
|
|
|
|
self._cubehandle.update()
|
|
|
|
device = self._cubehandle.cube.device_by_rf(self._rf_address)
|
|
|
|
self._state = device.is_open
|