Add binary_sensor to ElkM1 integration (#74485)
* Add binary_sensor to ElkM1 integration * Update for review comments. * Fix black. * Fix pylint error. Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
parent
f4e61eff18
commit
a3d0719c49
9 changed files with 65 additions and 6 deletions
57
homeassistant/components/elkm1/binary_sensor.py
Normal file
57
homeassistant/components/elkm1/binary_sensor.py
Normal file
|
@ -0,0 +1,57 @@
|
|||
"""Support for control of ElkM1 binary sensors."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from elkm1_lib.const import ZoneLogicalStatus, ZoneType
|
||||
from elkm1_lib.elements import Element
|
||||
from elkm1_lib.zones import Zone
|
||||
|
||||
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 . import ElkAttachedEntity, ElkEntity
|
||||
from .const import DOMAIN
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Create the Elk-M1 sensor platform."""
|
||||
|
||||
elk_data = hass.data[DOMAIN][config_entry.entry_id]
|
||||
auto_configure = elk_data["auto_configure"]
|
||||
elk = elk_data["elk"]
|
||||
|
||||
entities: list[ElkEntity] = []
|
||||
for element in elk.zones:
|
||||
# Don't create binary sensors for zones that are analog
|
||||
if element.definition in {ZoneType.TEMPERATURE, ZoneType.ANALOG_ZONE}:
|
||||
continue
|
||||
|
||||
if auto_configure:
|
||||
if not element.configured:
|
||||
continue
|
||||
elif not elk_data["config"]["zone"]["included"][element.index]:
|
||||
continue
|
||||
|
||||
entities.append(ElkBinarySensor(element, elk, elk_data))
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
class ElkBinarySensor(ElkAttachedEntity, BinarySensorEntity):
|
||||
"""Representation of ElkM1 binary sensor."""
|
||||
|
||||
_element: Zone
|
||||
_attr_entity_registry_enabled_default = False
|
||||
|
||||
def _element_changed(self, _: Element, changeset: Any) -> None:
|
||||
# Zone in NORMAL state is OFF; any other state is ON
|
||||
self._attr_is_on = bool(
|
||||
self._element.logical_status != ZoneLogicalStatus.NORMAL
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue