Skip to content

Commit

Permalink
dynamically include alarm control panel config
Browse files Browse the repository at this point in the history
  • Loading branch information
dmulcahey committed Apr 25, 2021
1 parent e370adc commit dd414c6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions homeassistant/components/zha/api.py
Expand Up @@ -9,6 +9,7 @@
import voluptuous as vol
from zigpy.config.validators import cv_boolean
from zigpy.types.named import EUI64
from zigpy.zcl.clusters.security import IasAce
import zigpy.zdo.types as zdo_types

from homeassistant.components import websocket_api
Expand Down Expand Up @@ -54,10 +55,12 @@
WARNING_DEVICE_SQUAWK_MODE_ARMED,
WARNING_DEVICE_STROBE_HIGH,
WARNING_DEVICE_STROBE_YES,
ZHA_ALARM_OPTIONS,
ZHA_CONFIG_SCHEMAS,
)
from .core.group import GroupMember
from .core.helpers import (
async_input_cluster_exists,
async_is_bindable_target,
convert_install_code,
get_matched_clusters,
Expand Down Expand Up @@ -906,6 +909,10 @@ def custom_serializer(schema: Any) -> Any:

data = {"schemas": {}, "data": {}}
for section, schema in ZHA_CONFIG_SCHEMAS.items():
if section == ZHA_ALARM_OPTIONS and not async_input_cluster_exists(
hass, IasAce.cluster_id
):
continue
data["schemas"][section] = voluptuous_serialize.convert(
schema, custom_serializer=custom_serializer
)
Expand Down
12 changes: 12 additions & 0 deletions homeassistant/components/zha/core/helpers.py
Expand Up @@ -139,6 +139,18 @@ def async_get_zha_config_value(config_entry, section, config_key, default):
)


def async_input_cluster_exists(hass, cluster_id):
"""Determine if a device containing the specified in cluster is paired."""
zha_gateway = hass.data[DATA_ZHA][DATA_ZHA_GATEWAY]
zha_devices = zha_gateway.devices.values()
for zha_device in zha_devices:
clusters_by_endpoint = zha_device.async_get_clusters()
for clusters in clusters_by_endpoint.values():
if cluster_id in clusters[CLUSTER_TYPE_IN]:
return True
return False


async def async_get_zha_device(hass, device_id):
"""Get a ZHA device for the given device registry id."""
device_registry = await hass.helpers.device_registry.async_get_registry()
Expand Down

0 comments on commit dd414c6

Please sign in to comment.