2019-02-13 20:21:14 +00:00
|
|
|
"""Support for Velbus Binary Sensors."""
|
2017-07-26 12:03:29 +00:00
|
|
|
import logging
|
|
|
|
|
2020-04-23 19:57:07 +00:00
|
|
|
from homeassistant.components.binary_sensor import BinarySensorEntity
|
2019-03-21 05:56:46 +00:00
|
|
|
|
2019-07-29 07:21:26 +00:00
|
|
|
from . import VelbusEntity
|
2019-12-09 08:36:42 +00:00
|
|
|
from .const import DOMAIN
|
2017-07-26 12:03:29 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2019-07-29 07:21:26 +00:00
|
|
|
async def async_setup_entry(hass, entry, async_add_entities):
|
|
|
|
"""Set up Velbus binary sensor based on config_entry."""
|
2019-07-31 19:25:30 +00:00
|
|
|
cntrl = hass.data[DOMAIN][entry.entry_id]["cntrl"]
|
|
|
|
modules_data = hass.data[DOMAIN][entry.entry_id]["binary_sensor"]
|
2019-07-29 07:21:26 +00:00
|
|
|
entities = []
|
|
|
|
for address, channel in modules_data:
|
|
|
|
module = cntrl.get_module(address)
|
2019-07-31 19:25:30 +00:00
|
|
|
entities.append(VelbusBinarySensor(module, channel))
|
2019-07-29 07:21:26 +00:00
|
|
|
async_add_entities(entities)
|
2017-07-26 12:03:29 +00:00
|
|
|
|
|
|
|
|
2020-04-23 19:57:07 +00:00
|
|
|
class VelbusBinarySensor(VelbusEntity, BinarySensorEntity):
|
2017-07-26 12:03:29 +00:00
|
|
|
"""Representation of a Velbus Binary Sensor."""
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self):
|
|
|
|
"""Return true if the sensor is on."""
|
2018-08-05 08:47:17 +00:00
|
|
|
return self._module.is_closed(self._channel)
|