Files
homeassistant-core/homeassistant/components/vera/binary_sensor.py
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

49 lines
1.5 KiB
Python
Raw Normal View History

2019-02-13 21:21:14 +01:00
"""Support for Vera binary sensors."""
2021-03-18 14:43:52 +01:00
from __future__ import annotations
2020-09-16 14:23:50 -07:00
import pyvera as veraApi
2016-03-15 09:17:09 +00:00
2022-01-20 07:46:26 +01:00
from homeassistant.components.binary_sensor import ENTITY_ID_FORMAT, BinarySensorEntity
2020-04-03 00:49:50 -07:00
from homeassistant.config_entries import ConfigEntry
2022-01-20 07:46:26 +01:00
from homeassistant.const import Platform
2020-04-03 00:49:50 -07:00
from homeassistant.core import HomeAssistant
2021-05-04 22:36:48 +01:00
from homeassistant.helpers.entity_platform import AddEntitiesCallback
2020-04-03 00:49:50 -07:00
from . import VeraDevice
from .common import ControllerData, get_controller_data
2016-03-15 09:17:09 +00:00
2020-04-03 00:49:50 -07:00
async def async_setup_entry(
hass: HomeAssistant,
entry: ConfigEntry,
2021-05-04 22:36:48 +01:00
async_add_entities: AddEntitiesCallback,
2020-04-03 00:49:50 -07:00
) -> None:
"""Set up the sensor config entry."""
controller_data = get_controller_data(hass, entry)
2020-04-03 00:49:50 -07:00
async_add_entities(
[
VeraBinarySensor(device, controller_data)
2022-01-20 07:46:26 +01:00
for device in controller_data.devices[Platform.BINARY_SENSOR]
],
True,
)
2016-03-15 09:17:09 +00:00
2020-09-16 14:23:50 -07:00
class VeraBinarySensor(VeraDevice[veraApi.VeraBinarySensor], BinarySensorEntity):
2016-03-15 09:17:09 +00:00
"""Representation of a Vera Binary Sensor."""
2023-09-12 15:23:12 +02:00
_attr_is_on = False
2020-09-16 14:23:50 -07:00
def __init__(
self, vera_device: veraApi.VeraBinarySensor, controller_data: ControllerData
) -> None:
2016-03-15 09:17:09 +00:00
"""Initialize the binary_sensor."""
VeraDevice.__init__(self, vera_device, controller_data)
self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)
2016-03-15 09:17:09 +00:00
2020-09-16 14:23:50 -07:00
def update(self) -> None:
2016-03-15 09:17:09 +00:00
"""Get the latest data and update the state."""
2021-02-08 14:25:54 +00:00
super().update()
2023-09-12 15:23:12 +02:00
self._attr_is_on = self.vera_device.is_tripped