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>
pull/74955/head
Glenn Waters 2022-07-11 03:11:37 -04:00 committed by GitHub
parent f4e61eff18
commit a3d0719c49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 65 additions and 6 deletions

View File

@ -266,6 +266,7 @@ omit =
homeassistant/components/eliqonline/sensor.py
homeassistant/components/elkm1/__init__.py
homeassistant/components/elkm1/alarm_control_panel.py
homeassistant/components/elkm1/binary_sensor.py
homeassistant/components/elkm1/climate.py
homeassistant/components/elkm1/discovery.py
homeassistant/components/elkm1/light.py

View File

@ -74,6 +74,7 @@ _LOGGER = logging.getLogger(__name__)
PLATFORMS = [
Platform.ALARM_CONTROL_PANEL,
Platform.BINARY_SENSOR,
Platform.CLIMATE,
Platform.LIGHT,
Platform.SCENE,

View File

@ -69,7 +69,7 @@ async def async_setup_entry(
elk = elk_data["elk"]
entities: list[ElkEntity] = []
create_elk_entities(elk_data, elk.areas, "area", ElkArea, entities)
async_add_entities(entities, True)
async_add_entities(entities)
platform = entity_platform.async_get_current_platform()

View 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
)

View File

@ -68,7 +68,7 @@ async def async_setup_entry(
create_elk_entities(
elk_data, elk.thermostats, "thermostat", ElkThermostat, entities
)
async_add_entities(entities, True)
async_add_entities(entities)
class ElkThermostat(ElkEntity, ClimateEntity):

View File

@ -26,7 +26,7 @@ async def async_setup_entry(
entities: list[ElkEntity] = []
elk = elk_data["elk"]
create_elk_entities(elk_data, elk.lights, "plc", ElkLight, entities)
async_add_entities(entities, True)
async_add_entities(entities)
class ElkLight(ElkEntity, LightEntity):

View File

@ -24,7 +24,7 @@ async def async_setup_entry(
entities: list[ElkEntity] = []
elk = elk_data["elk"]
create_elk_entities(elk_data, elk.tasks, "task", ElkTask, entities)
async_add_entities(entities, True)
async_add_entities(entities)
class ElkTask(ElkAttachedEntity, Scene):

View File

@ -51,7 +51,7 @@ async def async_setup_entry(
create_elk_entities(elk_data, [elk.panel], "panel", ElkPanel, entities)
create_elk_entities(elk_data, elk.settings, "setting", ElkSetting, entities)
create_elk_entities(elk_data, elk.zones, "zone", ElkZone, entities)
async_add_entities(entities, True)
async_add_entities(entities)
platform = entity_platform.async_get_current_platform()

View File

@ -24,7 +24,7 @@ async def async_setup_entry(
entities: list[ElkEntity] = []
elk = elk_data["elk"]
create_elk_entities(elk_data, elk.outputs, "output", ElkOutput, entities)
async_add_entities(entities, True)
async_add_entities(entities)
class ElkOutput(ElkAttachedEntity, SwitchEntity):