2019-05-14 21:30:26 +00:00
|
|
|
"""Support for Genius Hub binary_sensor devices."""
|
|
|
|
from homeassistant.components.binary_sensor import BinarySensorDevice
|
2019-10-02 16:27:13 +00:00
|
|
|
from homeassistant.helpers.typing import ConfigType, HomeAssistantType
|
2019-05-14 21:30:26 +00:00
|
|
|
|
2019-10-02 16:27:13 +00:00
|
|
|
from . import DOMAIN, GeniusDevice
|
2019-05-14 21:30:26 +00:00
|
|
|
|
2019-10-02 16:27:13 +00:00
|
|
|
GH_STATE_ATTR = "outputOnOff"
|
2019-05-14 21:30:26 +00:00
|
|
|
|
|
|
|
|
2019-10-02 16:27:13 +00:00
|
|
|
async def async_setup_platform(
|
|
|
|
hass: HomeAssistantType, config: ConfigType, async_add_entities, discovery_info=None
|
|
|
|
) -> None:
|
2019-05-14 21:30:26 +00:00
|
|
|
"""Set up the Genius Hub sensor entities."""
|
2019-10-02 16:27:13 +00:00
|
|
|
if discovery_info is None:
|
|
|
|
return
|
|
|
|
|
|
|
|
broker = hass.data[DOMAIN]["broker"]
|
2019-05-14 21:30:26 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
switches = [
|
2019-10-02 16:27:13 +00:00
|
|
|
GeniusBinarySensor(broker, d, GH_STATE_ATTR)
|
|
|
|
for d in broker.client.device_objs
|
|
|
|
if GH_STATE_ATTR in d.data["state"]
|
2019-07-31 19:25:30 +00:00
|
|
|
]
|
2019-05-14 21:30:26 +00:00
|
|
|
|
2019-10-02 16:27:13 +00:00
|
|
|
async_add_entities(switches, update_before_add=True)
|
2019-05-14 21:30:26 +00:00
|
|
|
|
|
|
|
|
2019-10-02 16:27:13 +00:00
|
|
|
class GeniusBinarySensor(GeniusDevice, BinarySensorDevice):
|
2019-05-14 21:30:26 +00:00
|
|
|
"""Representation of a Genius Hub binary_sensor."""
|
|
|
|
|
2019-10-02 16:27:13 +00:00
|
|
|
def __init__(self, broker, device, state_attr) -> None:
|
2019-05-14 21:30:26 +00:00
|
|
|
"""Initialize the binary sensor."""
|
2019-10-02 16:27:13 +00:00
|
|
|
super().__init__(broker, device)
|
|
|
|
|
|
|
|
self._state_attr = state_attr
|
2019-05-14 21:30:26 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
if device.type[:21] == "Dual Channel Receiver":
|
2019-10-02 16:27:13 +00:00
|
|
|
self._name = f"{device.type[:21]} {device.id}"
|
2019-05-14 21:30:26 +00:00
|
|
|
else:
|
2019-09-03 15:10:56 +00:00
|
|
|
self._name = f"{device.type} {device.id}"
|
2019-05-14 21:30:26 +00:00
|
|
|
|
|
|
|
@property
|
2019-08-20 17:43:39 +00:00
|
|
|
def is_on(self) -> bool:
|
2019-05-14 21:30:26 +00:00
|
|
|
"""Return the status of the sensor."""
|
2019-10-02 16:27:13 +00:00
|
|
|
return self._device.data["state"][self._state_attr]
|