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

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

79 lines
2.4 KiB
Python
Raw Normal View History

2019-04-03 17:40:03 +02:00
"""Support for Vanderbilt (formerly Siemens) SPC alarm systems."""
from __future__ import annotations
from pyspcwebgw import SpcWebGateway
2020-04-04 15:49:29 +02:00
from pyspcwebgw.const import ZoneInput, ZoneType
from pyspcwebgw.zone import Zone
2019-12-06 15:40:04 +01:00
from homeassistant.components.binary_sensor import (
2021-12-20 14:18:48 +01:00
BinarySensorDeviceClass,
BinarySensorEntity,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from . import DATA_API, SIGNAL_UPDATE_SENSOR
def _get_device_class(zone_type: ZoneType) -> BinarySensorDeviceClass | None:
2018-09-24 10:10:10 +02:00
return {
2021-12-20 14:18:48 +01:00
ZoneType.ALARM: BinarySensorDeviceClass.MOTION,
ZoneType.ENTRY_EXIT: BinarySensorDeviceClass.OPENING,
ZoneType.FIRE: BinarySensorDeviceClass.SMOKE,
ZoneType.TECHNICAL: BinarySensorDeviceClass.POWER,
2018-09-24 10:10:10 +02:00
}.get(zone_type)
async def async_setup_platform(
hass: HomeAssistant,
config: ConfigType,
async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
2018-01-21 07:35:38 +01:00
"""Set up the SPC binary sensor."""
2018-10-08 10:20:18 +02:00
if discovery_info is None:
return
api: SpcWebGateway = hass.data[DATA_API]
async_add_entities(
2019-07-31 12:25:30 -07:00
[
SpcBinarySensor(zone)
for zone in api.zones.values()
if _get_device_class(zone.type)
2019-07-31 12:25:30 -07:00
]
)
class SpcBinarySensor(BinarySensorEntity):
2018-01-21 07:35:38 +01:00
"""Representation of a sensor based on a SPC zone."""
_attr_should_poll = False
def __init__(self, zone: Zone) -> None:
"""Initialize the sensor device."""
2018-09-24 10:10:10 +02:00
self._zone = zone
2023-09-12 18:01:05 +02:00
self._attr_name = zone.name
self._attr_device_class = _get_device_class(zone.type)
async def async_added_to_hass(self) -> None:
2018-09-24 10:10:10 +02:00
"""Call for adding new entities."""
self.async_on_remove(
async_dispatcher_connect(
self.hass,
SIGNAL_UPDATE_SENSOR.format(self._zone.id),
self._update_callback,
)
2018-09-24 10:10:10 +02:00
)
2018-09-24 10:10:10 +02:00
@callback
def _update_callback(self) -> None:
2018-09-24 10:10:10 +02:00
"""Call update method."""
self.async_schedule_update_ha_state(True)
@property
def is_on(self) -> bool:
"""Whether the device is switched on."""
2018-09-24 10:10:10 +02:00
return self._zone.input == ZoneInput.OPEN