hass-core/homeassistant/components/velbus/binary_sensor.py
Maikel Punie 0535578440
Velbus code cleanup (#97584)
* Some cleanup and code improvements for the velbus integration

* Comments

* More comments

* Update homeassistant/components/velbus/entity.py

Co-authored-by: G Johansson <goran.johansson@shiftit.se>

* More comments

---------

Co-authored-by: G Johansson <goran.johansson@shiftit.se>
2023-08-06 19:12:19 +02:00

34 lines
1.1 KiB
Python

"""Support for Velbus Binary Sensors."""
from velbusaio.channels import Button as VelbusButton
from homeassistant.components.binary_sensor import BinarySensorEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .const import DOMAIN
from .entity import VelbusEntity
async def async_setup_entry(
hass: HomeAssistant,
entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up Velbus switch based on config_entry."""
await hass.data[DOMAIN][entry.entry_id]["tsk"]
cntrl = hass.data[DOMAIN][entry.entry_id]["cntrl"]
async_add_entities(
VelbusBinarySensor(channel) for channel in cntrl.get_all("binary_sensor")
)
class VelbusBinarySensor(VelbusEntity, BinarySensorEntity):
"""Representation of a Velbus Binary Sensor."""
_channel: VelbusButton
@property
def is_on(self) -> bool:
"""Return true if the sensor is on."""
return self._channel.is_closed()