Add config entities for the Aqara P1 motion sensor to ZHA (#72466)

* initial work for configurable detection interval

* update opple cluster channel

* detection interval

* motion sensitivity

* only set the init attributes for the right device

* add trigger indicator configuration entity
pull/72474/head
David F. Mulcahey 2022-05-25 02:57:26 -04:00 committed by GitHub
parent a98af2ad58
commit 9591d5366e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 64 additions and 3 deletions

View File

@ -1,7 +1,9 @@
"""Manufacturer specific channels module for Zigbee Home Automation."""
import logging
from homeassistant.core import callback
from .. import registries
from .. import registries, typing as zha_typing
from ..const import (
ATTR_ATTRIBUTE_ID,
ATTR_ATTRIBUTE_NAME,
@ -14,6 +16,8 @@ from ..const import (
)
from .base import ClientChannel, ZigbeeChannel
_LOGGER = logging.getLogger(__name__)
@registries.ZIGBEE_CHANNEL_REGISTRY.register(registries.SMARTTHINGS_HUMIDITY_CLUSTER)
class SmartThingsHumidity(ZigbeeChannel):
@ -50,6 +54,26 @@ class OppleRemote(ZigbeeChannel):
REPORT_CONFIG = []
def __init__(
self, cluster: zha_typing.ZigpyClusterType, ch_pool: zha_typing.ChannelPoolType
) -> None:
"""Initialize Opple channel."""
super().__init__(cluster, ch_pool)
if self.cluster.endpoint.model == "lumi.motion.ac02":
self.ZCL_INIT_ATTRS = { # pylint: disable=C0103
"detection_interval": True,
"motion_sensitivity": True,
"trigger_indicator": True,
}
async def async_initialize_channel_specific(self, from_cache: bool) -> None:
"""Initialize channel specific."""
if self.cluster.endpoint.model == "lumi.motion.ac02":
interval = self.cluster.get("detection_interval", self.cluster.get(0x0102))
if interval is not None:
self.debug("Loaded detection interval at startup: %s", interval)
self.cluster.endpoint.ias_zone.reset_s = int(interval)
@registries.ZIGBEE_CHANNEL_REGISTRY.register(
registries.SMARTTHINGS_ACCELERATION_CLUSTER

View File

@ -433,6 +433,17 @@ class ZHANumberConfigurationEntity(ZhaEntity, NumberEntity):
_LOGGER.debug("read value=%s", value)
@CONFIG_DIAGNOSTIC_MATCH(channel_names="opple_cluster", models={"lumi.motion.ac02"})
class AqaraMotionDetectionInterval(
ZHANumberConfigurationEntity, id_suffix="detection_interval"
):
"""Representation of a ZHA on off transition time configuration entity."""
_attr_min_value: float = 2
_attr_max_value: float = 65535
_zcl_attribute: str = "detection_interval"
@CONFIG_DIAGNOSTIC_MATCH(channel_names=CHANNEL_LEVEL)
class OnOffTransitionTimeConfigurationEntity(
ZHANumberConfigurationEntity, id_suffix="on_off_transition_time"

View File

@ -5,6 +5,7 @@ from enum import Enum
import functools
import logging
from zigpy import types
from zigpy.zcl.clusters.general import OnOff
from zigpy.zcl.clusters.security import IasWd
@ -208,3 +209,19 @@ class ZHAStartupOnOffSelectEntity(
_select_attr = "start_up_on_off"
_enum: Enum = OnOff.StartUpOnOff
class AqaraMotionSensitivities(types.enum8):
"""Aqara motion sensitivities."""
Low = 0x01
Medium = 0x02
High = 0x03
@CONFIG_DIAGNOSTIC_MATCH(channel_names="opple_cluster", models={"lumi.motion.ac02"})
class AqaraMotionSensitivity(ZCLEnumSelectEntity, id_suffix="motion_sensitivity"):
"""Representation of a ZHA on off transition time configuration entity."""
_select_attr = "motion_sensitivity"
_enum: Enum = AqaraMotionSensitivities

View File

@ -155,6 +155,7 @@ class SwitchGroup(ZhaGroupEntity, SwitchEntity):
class ZHASwitchConfigurationEntity(ZhaEntity, SwitchEntity):
"""Representation of a ZHA switch configuration entity."""
_attr_entity_category = EntityCategory.CONFIG
_zcl_attribute: str
_zcl_inverter_attribute: str = ""
@ -260,8 +261,16 @@ class ZHASwitchConfigurationEntity(ZhaEntity, SwitchEntity):
class OnOffWindowDetectionFunctionConfigurationEntity(
ZHASwitchConfigurationEntity, id_suffix="on_off_window_opened_detection"
):
"""Representation of a ZHA on off transition time configuration entity."""
"""Representation of a ZHA window detection configuration entity."""
_attr_entity_category = EntityCategory.CONFIG
_zcl_attribute = "window_detection_function"
_zcl_inverter_attribute = "window_detection_function_inverter"
@CONFIG_DIAGNOSTIC_MATCH(channel_names="opple_cluster", models={"lumi.motion.ac02"})
class P1MotionTriggerIndicatorSwitch(
ZHASwitchConfigurationEntity, id_suffix="trigger_indicator"
):
"""Representation of a ZHA motion triggering configuration entity."""
_zcl_attribute = "trigger_indicator"