Use a TypedDict for REPORT_CONFIG in zha (#73629)

* Introduce ReportConfig TypedDict in zha

* Fix hint

* Always use Tuple

* Replace empty list with empty tuple

* Allow float for third config tuple value

* ReportConfig -> AttrReportConfig

* dict -> AttrReportConfig

* Allow int attributes

* Add coments
This commit is contained in:
epenet 2022-06-20 17:29:45 +02:00 committed by GitHub
parent be2aa44559
commit 9a95649a22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 173 additions and 121 deletions

View File

@ -5,7 +5,7 @@ import asyncio
from enum import Enum from enum import Enum
from functools import partialmethod, wraps from functools import partialmethod, wraps
import logging import logging
from typing import TYPE_CHECKING, Any from typing import TYPE_CHECKING, Any, TypedDict
import zigpy.exceptions import zigpy.exceptions
import zigpy.zcl import zigpy.zcl
@ -46,6 +46,16 @@ if TYPE_CHECKING:
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
class AttrReportConfig(TypedDict, total=True):
"""Configuration to report for the attributes."""
# Could be either an attribute name or attribute id
attr: str | int
# The config for the attribute reporting configuration consists of a tuple for
# (minimum_reported_time_interval_s, maximum_reported_time_interval_s, value_delta)
config: tuple[int, int, int | float]
def parse_and_log_command(channel, tsn, command_id, args): def parse_and_log_command(channel, tsn, command_id, args):
"""Parse and log a zigbee cluster command.""" """Parse and log a zigbee cluster command."""
cmd = channel.cluster.server_commands.get(command_id, [command_id])[0] cmd = channel.cluster.server_commands.get(command_id, [command_id])[0]
@ -99,7 +109,7 @@ class ChannelStatus(Enum):
class ZigbeeChannel(LogMixin): class ZigbeeChannel(LogMixin):
"""Base channel for a Zigbee cluster.""" """Base channel for a Zigbee cluster."""
REPORT_CONFIG: tuple[dict[int | str, tuple[int, int, int | float]]] = () REPORT_CONFIG: tuple[AttrReportConfig] = ()
BIND: bool = True BIND: bool = True
# Dict of attributes to read on channel initialization. # Dict of attributes to read on channel initialization.

View File

@ -5,7 +5,7 @@ from homeassistant.core import callback
from .. import registries from .. import registries
from ..const import REPORT_CONFIG_IMMEDIATE, SIGNAL_ATTR_UPDATED from ..const import REPORT_CONFIG_IMMEDIATE, SIGNAL_ATTR_UPDATED
from .base import ClientChannel, ZigbeeChannel from .base import AttrReportConfig, ClientChannel, ZigbeeChannel
@registries.ZIGBEE_CHANNEL_REGISTRY.register(closures.DoorLock.cluster_id) @registries.ZIGBEE_CHANNEL_REGISTRY.register(closures.DoorLock.cluster_id)
@ -13,7 +13,9 @@ class DoorLockChannel(ZigbeeChannel):
"""Door lock channel.""" """Door lock channel."""
_value_attribute = 0 _value_attribute = 0
REPORT_CONFIG = ({"attr": "lock_state", "config": REPORT_CONFIG_IMMEDIATE},) REPORT_CONFIG = (
AttrReportConfig(attr="lock_state", config=REPORT_CONFIG_IMMEDIATE),
)
async def async_update(self): async def async_update(self):
"""Retrieve latest state.""" """Retrieve latest state."""
@ -121,7 +123,9 @@ class WindowCovering(ZigbeeChannel):
_value_attribute = 8 _value_attribute = 8
REPORT_CONFIG = ( REPORT_CONFIG = (
{"attr": "current_position_lift_percentage", "config": REPORT_CONFIG_IMMEDIATE}, AttrReportConfig(
attr="current_position_lift_percentage", config=REPORT_CONFIG_IMMEDIATE
),
) )
async def async_update(self): async def async_update(self):

View File

@ -27,7 +27,7 @@ from ..const import (
SIGNAL_SET_LEVEL, SIGNAL_SET_LEVEL,
SIGNAL_UPDATE_DEVICE, SIGNAL_UPDATE_DEVICE,
) )
from .base import ClientChannel, ZigbeeChannel, parse_and_log_command from .base import AttrReportConfig, ClientChannel, ZigbeeChannel, parse_and_log_command
if TYPE_CHECKING: if TYPE_CHECKING:
from . import ChannelPool from . import ChannelPool
@ -42,7 +42,9 @@ class Alarms(ZigbeeChannel):
class AnalogInput(ZigbeeChannel): class AnalogInput(ZigbeeChannel):
"""Analog Input channel.""" """Analog Input channel."""
REPORT_CONFIG = [{"attr": "present_value", "config": REPORT_CONFIG_DEFAULT}] REPORT_CONFIG = (
AttrReportConfig(attr="present_value", config=REPORT_CONFIG_DEFAULT),
)
@registries.BINDABLE_CLUSTERS.register(general.AnalogOutput.cluster_id) @registries.BINDABLE_CLUSTERS.register(general.AnalogOutput.cluster_id)
@ -50,7 +52,9 @@ class AnalogInput(ZigbeeChannel):
class AnalogOutput(ZigbeeChannel): class AnalogOutput(ZigbeeChannel):
"""Analog Output channel.""" """Analog Output channel."""
REPORT_CONFIG = ({"attr": "present_value", "config": REPORT_CONFIG_DEFAULT},) REPORT_CONFIG = (
AttrReportConfig(attr="present_value", config=REPORT_CONFIG_DEFAULT),
)
ZCL_INIT_ATTRS = { ZCL_INIT_ATTRS = {
"min_present_value": True, "min_present_value": True,
"max_present_value": True, "max_present_value": True,
@ -119,7 +123,9 @@ class AnalogOutput(ZigbeeChannel):
class AnalogValue(ZigbeeChannel): class AnalogValue(ZigbeeChannel):
"""Analog Value channel.""" """Analog Value channel."""
REPORT_CONFIG = [{"attr": "present_value", "config": REPORT_CONFIG_DEFAULT}] REPORT_CONFIG = (
AttrReportConfig(attr="present_value", config=REPORT_CONFIG_DEFAULT),
)
@registries.ZIGBEE_CHANNEL_REGISTRY.register(general.ApplianceControl.cluster_id) @registries.ZIGBEE_CHANNEL_REGISTRY.register(general.ApplianceControl.cluster_id)
@ -151,21 +157,27 @@ class BasicChannel(ZigbeeChannel):
class BinaryInput(ZigbeeChannel): class BinaryInput(ZigbeeChannel):
"""Binary Input channel.""" """Binary Input channel."""
REPORT_CONFIG = [{"attr": "present_value", "config": REPORT_CONFIG_DEFAULT}] REPORT_CONFIG = (
AttrReportConfig(attr="present_value", config=REPORT_CONFIG_DEFAULT),
)
@registries.ZIGBEE_CHANNEL_REGISTRY.register(general.BinaryOutput.cluster_id) @registries.ZIGBEE_CHANNEL_REGISTRY.register(general.BinaryOutput.cluster_id)
class BinaryOutput(ZigbeeChannel): class BinaryOutput(ZigbeeChannel):
"""Binary Output channel.""" """Binary Output channel."""
REPORT_CONFIG = [{"attr": "present_value", "config": REPORT_CONFIG_DEFAULT}] REPORT_CONFIG = (
AttrReportConfig(attr="present_value", config=REPORT_CONFIG_DEFAULT),
)
@registries.ZIGBEE_CHANNEL_REGISTRY.register(general.BinaryValue.cluster_id) @registries.ZIGBEE_CHANNEL_REGISTRY.register(general.BinaryValue.cluster_id)
class BinaryValue(ZigbeeChannel): class BinaryValue(ZigbeeChannel):
"""Binary Value channel.""" """Binary Value channel."""
REPORT_CONFIG = [{"attr": "present_value", "config": REPORT_CONFIG_DEFAULT}] REPORT_CONFIG = (
AttrReportConfig(attr="present_value", config=REPORT_CONFIG_DEFAULT),
)
@registries.ZIGBEE_CHANNEL_REGISTRY.register(general.Commissioning.cluster_id) @registries.ZIGBEE_CHANNEL_REGISTRY.register(general.Commissioning.cluster_id)
@ -177,12 +189,12 @@ class Commissioning(ZigbeeChannel):
class DeviceTemperature(ZigbeeChannel): class DeviceTemperature(ZigbeeChannel):
"""Device Temperature channel.""" """Device Temperature channel."""
REPORT_CONFIG = [ REPORT_CONFIG = (
{ {
"attr": "current_temperature", "attr": "current_temperature",
"config": (REPORT_CONFIG_MIN_INT, REPORT_CONFIG_MAX_INT, 50), "config": (REPORT_CONFIG_MIN_INT, REPORT_CONFIG_MAX_INT, 50),
} },
] )
@registries.ZIGBEE_CHANNEL_REGISTRY.register(general.GreenPowerProxy.cluster_id) @registries.ZIGBEE_CHANNEL_REGISTRY.register(general.GreenPowerProxy.cluster_id)
@ -225,7 +237,7 @@ class LevelControlChannel(ZigbeeChannel):
"""Channel for the LevelControl Zigbee cluster.""" """Channel for the LevelControl Zigbee cluster."""
CURRENT_LEVEL = 0 CURRENT_LEVEL = 0
REPORT_CONFIG = ({"attr": "current_level", "config": REPORT_CONFIG_ASAP},) REPORT_CONFIG = (AttrReportConfig(attr="current_level", config=REPORT_CONFIG_ASAP),)
ZCL_INIT_ATTRS = { ZCL_INIT_ATTRS = {
"on_off_transition_time": True, "on_off_transition_time": True,
"on_level": True, "on_level": True,
@ -275,21 +287,27 @@ class LevelControlChannel(ZigbeeChannel):
class MultistateInput(ZigbeeChannel): class MultistateInput(ZigbeeChannel):
"""Multistate Input channel.""" """Multistate Input channel."""
REPORT_CONFIG = [{"attr": "present_value", "config": REPORT_CONFIG_DEFAULT}] REPORT_CONFIG = (
AttrReportConfig(attr="present_value", config=REPORT_CONFIG_DEFAULT),
)
@registries.ZIGBEE_CHANNEL_REGISTRY.register(general.MultistateOutput.cluster_id) @registries.ZIGBEE_CHANNEL_REGISTRY.register(general.MultistateOutput.cluster_id)
class MultistateOutput(ZigbeeChannel): class MultistateOutput(ZigbeeChannel):
"""Multistate Output channel.""" """Multistate Output channel."""
REPORT_CONFIG = [{"attr": "present_value", "config": REPORT_CONFIG_DEFAULT}] REPORT_CONFIG = (
AttrReportConfig(attr="present_value", config=REPORT_CONFIG_DEFAULT),
)
@registries.ZIGBEE_CHANNEL_REGISTRY.register(general.MultistateValue.cluster_id) @registries.ZIGBEE_CHANNEL_REGISTRY.register(general.MultistateValue.cluster_id)
class MultistateValue(ZigbeeChannel): class MultistateValue(ZigbeeChannel):
"""Multistate Value channel.""" """Multistate Value channel."""
REPORT_CONFIG = [{"attr": "present_value", "config": REPORT_CONFIG_DEFAULT}] REPORT_CONFIG = (
AttrReportConfig(attr="present_value", config=REPORT_CONFIG_DEFAULT),
)
@registries.CLIENT_CHANNELS_REGISTRY.register(general.OnOff.cluster_id) @registries.CLIENT_CHANNELS_REGISTRY.register(general.OnOff.cluster_id)
@ -303,7 +321,7 @@ class OnOffChannel(ZigbeeChannel):
"""Channel for the OnOff Zigbee cluster.""" """Channel for the OnOff Zigbee cluster."""
ON_OFF = 0 ON_OFF = 0
REPORT_CONFIG = ({"attr": "on_off", "config": REPORT_CONFIG_IMMEDIATE},) REPORT_CONFIG = (AttrReportConfig(attr="on_off", config=REPORT_CONFIG_IMMEDIATE),)
ZCL_INIT_ATTRS = { ZCL_INIT_ATTRS = {
"start_up_on_off": True, "start_up_on_off": True,
} }
@ -472,8 +490,10 @@ class PowerConfigurationChannel(ZigbeeChannel):
"""Channel for the zigbee power configuration cluster.""" """Channel for the zigbee power configuration cluster."""
REPORT_CONFIG = ( REPORT_CONFIG = (
{"attr": "battery_voltage", "config": REPORT_CONFIG_BATTERY_SAVE}, AttrReportConfig(attr="battery_voltage", config=REPORT_CONFIG_BATTERY_SAVE),
{"attr": "battery_percentage_remaining", "config": REPORT_CONFIG_BATTERY_SAVE}, AttrReportConfig(
attr="battery_percentage_remaining", config=REPORT_CONFIG_BATTERY_SAVE
),
) )
def async_initialize_channel_specific(self, from_cache: bool) -> Coroutine: def async_initialize_channel_specific(self, from_cache: bool) -> Coroutine:

View File

@ -12,7 +12,7 @@ from ..const import (
REPORT_CONFIG_OP, REPORT_CONFIG_OP,
SIGNAL_ATTR_UPDATED, SIGNAL_ATTR_UPDATED,
) )
from .base import ZigbeeChannel from .base import AttrReportConfig, ZigbeeChannel
@registries.ZIGBEE_CHANNEL_REGISTRY.register( @registries.ZIGBEE_CHANNEL_REGISTRY.register(
@ -63,15 +63,15 @@ class ElectricalMeasurementChannel(ZigbeeChannel):
POWER_QUALITY_MEASUREMENT = 256 POWER_QUALITY_MEASUREMENT = 256
REPORT_CONFIG = ( REPORT_CONFIG = (
{"attr": "active_power", "config": REPORT_CONFIG_OP}, AttrReportConfig(attr="active_power", config=REPORT_CONFIG_OP),
{"attr": "active_power_max", "config": REPORT_CONFIG_DEFAULT}, AttrReportConfig(attr="active_power_max", config=REPORT_CONFIG_DEFAULT),
{"attr": "apparent_power", "config": REPORT_CONFIG_OP}, AttrReportConfig(attr="apparent_power", config=REPORT_CONFIG_OP),
{"attr": "rms_current", "config": REPORT_CONFIG_OP}, AttrReportConfig(attr="rms_current", config=REPORT_CONFIG_OP),
{"attr": "rms_current_max", "config": REPORT_CONFIG_DEFAULT}, AttrReportConfig(attr="rms_current_max", config=REPORT_CONFIG_DEFAULT),
{"attr": "rms_voltage", "config": REPORT_CONFIG_OP}, AttrReportConfig(attr="rms_voltage", config=REPORT_CONFIG_OP),
{"attr": "rms_voltage_max", "config": REPORT_CONFIG_DEFAULT}, AttrReportConfig(attr="rms_voltage_max", config=REPORT_CONFIG_DEFAULT),
{"attr": "ac_frequency", "config": REPORT_CONFIG_OP}, AttrReportConfig(attr="ac_frequency", config=REPORT_CONFIG_OP),
{"attr": "ac_frequency_max", "config": REPORT_CONFIG_DEFAULT}, AttrReportConfig(attr="ac_frequency_max", config=REPORT_CONFIG_DEFAULT),
) )
ZCL_INIT_ATTRS = { ZCL_INIT_ATTRS = {
"ac_current_divisor": True, "ac_current_divisor": True,

View File

@ -22,7 +22,7 @@ from ..const import (
REPORT_CONFIG_OP, REPORT_CONFIG_OP,
SIGNAL_ATTR_UPDATED, SIGNAL_ATTR_UPDATED,
) )
from .base import ZigbeeChannel from .base import AttrReportConfig, ZigbeeChannel
AttributeUpdateRecord = namedtuple("AttributeUpdateRecord", "attr_id, attr_name, value") AttributeUpdateRecord = namedtuple("AttributeUpdateRecord", "attr_id, attr_name, value")
REPORT_CONFIG_CLIMATE = (REPORT_CONFIG_MIN_INT, REPORT_CONFIG_MAX_INT, 25) REPORT_CONFIG_CLIMATE = (REPORT_CONFIG_MIN_INT, REPORT_CONFIG_MAX_INT, 25)
@ -41,7 +41,7 @@ class FanChannel(ZigbeeChannel):
_value_attribute = 0 _value_attribute = 0
REPORT_CONFIG = ({"attr": "fan_mode", "config": REPORT_CONFIG_OP},) REPORT_CONFIG = (AttrReportConfig(attr="fan_mode", config=REPORT_CONFIG_OP),)
ZCL_INIT_ATTRS = {"fan_mode_sequence": True} ZCL_INIT_ATTRS = {"fan_mode_sequence": True}
@property @property
@ -90,17 +90,25 @@ class ThermostatChannel(ZigbeeChannel):
"""Thermostat channel.""" """Thermostat channel."""
REPORT_CONFIG = ( REPORT_CONFIG = (
{"attr": "local_temperature", "config": REPORT_CONFIG_CLIMATE}, AttrReportConfig(attr="local_temperature", config=REPORT_CONFIG_CLIMATE),
{"attr": "occupied_cooling_setpoint", "config": REPORT_CONFIG_CLIMATE}, AttrReportConfig(
{"attr": "occupied_heating_setpoint", "config": REPORT_CONFIG_CLIMATE}, attr="occupied_cooling_setpoint", config=REPORT_CONFIG_CLIMATE
{"attr": "unoccupied_cooling_setpoint", "config": REPORT_CONFIG_CLIMATE}, ),
{"attr": "unoccupied_heating_setpoint", "config": REPORT_CONFIG_CLIMATE}, AttrReportConfig(
{"attr": "running_mode", "config": REPORT_CONFIG_CLIMATE}, attr="occupied_heating_setpoint", config=REPORT_CONFIG_CLIMATE
{"attr": "running_state", "config": REPORT_CONFIG_CLIMATE_DEMAND}, ),
{"attr": "system_mode", "config": REPORT_CONFIG_CLIMATE}, AttrReportConfig(
{"attr": "occupancy", "config": REPORT_CONFIG_CLIMATE_DISCRETE}, attr="unoccupied_cooling_setpoint", config=REPORT_CONFIG_CLIMATE
{"attr": "pi_cooling_demand", "config": REPORT_CONFIG_CLIMATE_DEMAND}, ),
{"attr": "pi_heating_demand", "config": REPORT_CONFIG_CLIMATE_DEMAND}, AttrReportConfig(
attr="unoccupied_heating_setpoint", config=REPORT_CONFIG_CLIMATE
),
AttrReportConfig(attr="running_mode", config=REPORT_CONFIG_CLIMATE),
AttrReportConfig(attr="running_state", config=REPORT_CONFIG_CLIMATE_DEMAND),
AttrReportConfig(attr="system_mode", config=REPORT_CONFIG_CLIMATE),
AttrReportConfig(attr="occupancy", config=REPORT_CONFIG_CLIMATE_DISCRETE),
AttrReportConfig(attr="pi_cooling_demand", config=REPORT_CONFIG_CLIMATE_DEMAND),
AttrReportConfig(attr="pi_heating_demand", config=REPORT_CONFIG_CLIMATE_DEMAND),
) )
ZCL_INIT_ATTRS: dict[int | str, bool] = { ZCL_INIT_ATTRS: dict[int | str, bool] = {
"abs_min_heat_setpoint_limit": True, "abs_min_heat_setpoint_limit": True,

View File

@ -7,7 +7,7 @@ from zigpy.zcl.clusters import lighting
from .. import registries from .. import registries
from ..const import REPORT_CONFIG_DEFAULT from ..const import REPORT_CONFIG_DEFAULT
from .base import ClientChannel, ZigbeeChannel from .base import AttrReportConfig, ClientChannel, ZigbeeChannel
@registries.ZIGBEE_CHANNEL_REGISTRY.register(lighting.Ballast.cluster_id) @registries.ZIGBEE_CHANNEL_REGISTRY.register(lighting.Ballast.cluster_id)
@ -29,9 +29,9 @@ class ColorChannel(ZigbeeChannel):
CAPABILITIES_COLOR_TEMP = 0x10 CAPABILITIES_COLOR_TEMP = 0x10
UNSUPPORTED_ATTRIBUTE = 0x86 UNSUPPORTED_ATTRIBUTE = 0x86
REPORT_CONFIG = ( REPORT_CONFIG = (
{"attr": "current_x", "config": REPORT_CONFIG_DEFAULT}, AttrReportConfig(attr="current_x", config=REPORT_CONFIG_DEFAULT),
{"attr": "current_y", "config": REPORT_CONFIG_DEFAULT}, AttrReportConfig(attr="current_y", config=REPORT_CONFIG_DEFAULT),
{"attr": "color_temperature", "config": REPORT_CONFIG_DEFAULT}, AttrReportConfig(attr="color_temperature", config=REPORT_CONFIG_DEFAULT),
) )
MAX_MIREDS: int = 500 MAX_MIREDS: int = 500
MIN_MIREDS: int = 153 MIN_MIREDS: int = 153

View File

@ -19,7 +19,7 @@ from ..const import (
SIGNAL_ATTR_UPDATED, SIGNAL_ATTR_UPDATED,
UNKNOWN, UNKNOWN,
) )
from .base import ClientChannel, ZigbeeChannel from .base import AttrReportConfig, ClientChannel, ZigbeeChannel
if TYPE_CHECKING: if TYPE_CHECKING:
from . import ChannelPool from . import ChannelPool
@ -31,12 +31,12 @@ _LOGGER = logging.getLogger(__name__)
class SmartThingsHumidity(ZigbeeChannel): class SmartThingsHumidity(ZigbeeChannel):
"""Smart Things Humidity channel.""" """Smart Things Humidity channel."""
REPORT_CONFIG = [ REPORT_CONFIG = (
{ {
"attr": "measured_value", "attr": "measured_value",
"config": (REPORT_CONFIG_MIN_INT, REPORT_CONFIG_MAX_INT, 50), "config": (REPORT_CONFIG_MIN_INT, REPORT_CONFIG_MAX_INT, 50),
} },
] )
@registries.CHANNEL_ONLY_CLUSTERS.register(0xFD00) @registries.CHANNEL_ONLY_CLUSTERS.register(0xFD00)
@ -44,7 +44,7 @@ class SmartThingsHumidity(ZigbeeChannel):
class OsramButton(ZigbeeChannel): class OsramButton(ZigbeeChannel):
"""Osram button channel.""" """Osram button channel."""
REPORT_CONFIG = [] REPORT_CONFIG = ()
@registries.CHANNEL_ONLY_CLUSTERS.register(registries.PHILLIPS_REMOTE_CLUSTER) @registries.CHANNEL_ONLY_CLUSTERS.register(registries.PHILLIPS_REMOTE_CLUSTER)
@ -52,7 +52,7 @@ class OsramButton(ZigbeeChannel):
class PhillipsRemote(ZigbeeChannel): class PhillipsRemote(ZigbeeChannel):
"""Phillips remote channel.""" """Phillips remote channel."""
REPORT_CONFIG = [] REPORT_CONFIG = ()
@registries.CHANNEL_ONLY_CLUSTERS.register(0xFCC0) @registries.CHANNEL_ONLY_CLUSTERS.register(0xFCC0)
@ -60,7 +60,7 @@ class PhillipsRemote(ZigbeeChannel):
class OppleRemote(ZigbeeChannel): class OppleRemote(ZigbeeChannel):
"""Opple button channel.""" """Opple button channel."""
REPORT_CONFIG = [] REPORT_CONFIG = ()
def __init__(self, cluster: zigpy.zcl.Cluster, ch_pool: ChannelPool) -> None: def __init__(self, cluster: zigpy.zcl.Cluster, ch_pool: ChannelPool) -> None:
"""Initialize Opple channel.""" """Initialize Opple channel."""
@ -87,12 +87,12 @@ class OppleRemote(ZigbeeChannel):
class SmartThingsAcceleration(ZigbeeChannel): class SmartThingsAcceleration(ZigbeeChannel):
"""Smart Things Acceleration channel.""" """Smart Things Acceleration channel."""
REPORT_CONFIG = [ REPORT_CONFIG = (
{"attr": "acceleration", "config": REPORT_CONFIG_ASAP}, AttrReportConfig(attr="acceleration", config=REPORT_CONFIG_ASAP),
{"attr": "x_axis", "config": REPORT_CONFIG_ASAP}, AttrReportConfig(attr="x_axis", config=REPORT_CONFIG_ASAP),
{"attr": "y_axis", "config": REPORT_CONFIG_ASAP}, AttrReportConfig(attr="y_axis", config=REPORT_CONFIG_ASAP),
{"attr": "z_axis", "config": REPORT_CONFIG_ASAP}, AttrReportConfig(attr="z_axis", config=REPORT_CONFIG_ASAP),
] )
@callback @callback
def attribute_updated(self, attrid, value): def attribute_updated(self, attrid, value):
@ -121,4 +121,4 @@ class SmartThingsAcceleration(ZigbeeChannel):
class InovelliCluster(ClientChannel): class InovelliCluster(ClientChannel):
"""Inovelli Button Press Event channel.""" """Inovelli Button Press Event channel."""
REPORT_CONFIG = [] REPORT_CONFIG = ()

View File

@ -8,14 +8,16 @@ from ..const import (
REPORT_CONFIG_MAX_INT, REPORT_CONFIG_MAX_INT,
REPORT_CONFIG_MIN_INT, REPORT_CONFIG_MIN_INT,
) )
from .base import ZigbeeChannel from .base import AttrReportConfig, ZigbeeChannel
@registries.ZIGBEE_CHANNEL_REGISTRY.register(measurement.FlowMeasurement.cluster_id) @registries.ZIGBEE_CHANNEL_REGISTRY.register(measurement.FlowMeasurement.cluster_id)
class FlowMeasurement(ZigbeeChannel): class FlowMeasurement(ZigbeeChannel):
"""Flow Measurement channel.""" """Flow Measurement channel."""
REPORT_CONFIG = [{"attr": "measured_value", "config": REPORT_CONFIG_DEFAULT}] REPORT_CONFIG = (
AttrReportConfig(attr="measured_value", config=REPORT_CONFIG_DEFAULT),
)
@registries.ZIGBEE_CHANNEL_REGISTRY.register( @registries.ZIGBEE_CHANNEL_REGISTRY.register(
@ -24,7 +26,9 @@ class FlowMeasurement(ZigbeeChannel):
class IlluminanceLevelSensing(ZigbeeChannel): class IlluminanceLevelSensing(ZigbeeChannel):
"""Illuminance Level Sensing channel.""" """Illuminance Level Sensing channel."""
REPORT_CONFIG = [{"attr": "level_status", "config": REPORT_CONFIG_DEFAULT}] REPORT_CONFIG = (
AttrReportConfig(attr="level_status", config=REPORT_CONFIG_DEFAULT),
)
@registries.ZIGBEE_CHANNEL_REGISTRY.register( @registries.ZIGBEE_CHANNEL_REGISTRY.register(
@ -33,57 +37,63 @@ class IlluminanceLevelSensing(ZigbeeChannel):
class IlluminanceMeasurement(ZigbeeChannel): class IlluminanceMeasurement(ZigbeeChannel):
"""Illuminance Measurement channel.""" """Illuminance Measurement channel."""
REPORT_CONFIG = [{"attr": "measured_value", "config": REPORT_CONFIG_DEFAULT}] REPORT_CONFIG = (
AttrReportConfig(attr="measured_value", config=REPORT_CONFIG_DEFAULT),
)
@registries.ZIGBEE_CHANNEL_REGISTRY.register(measurement.OccupancySensing.cluster_id) @registries.ZIGBEE_CHANNEL_REGISTRY.register(measurement.OccupancySensing.cluster_id)
class OccupancySensing(ZigbeeChannel): class OccupancySensing(ZigbeeChannel):
"""Occupancy Sensing channel.""" """Occupancy Sensing channel."""
REPORT_CONFIG = [{"attr": "occupancy", "config": REPORT_CONFIG_IMMEDIATE}] REPORT_CONFIG = (
AttrReportConfig(attr="occupancy", config=REPORT_CONFIG_IMMEDIATE),
)
@registries.ZIGBEE_CHANNEL_REGISTRY.register(measurement.PressureMeasurement.cluster_id) @registries.ZIGBEE_CHANNEL_REGISTRY.register(measurement.PressureMeasurement.cluster_id)
class PressureMeasurement(ZigbeeChannel): class PressureMeasurement(ZigbeeChannel):
"""Pressure measurement channel.""" """Pressure measurement channel."""
REPORT_CONFIG = [{"attr": "measured_value", "config": REPORT_CONFIG_DEFAULT}] REPORT_CONFIG = (
AttrReportConfig(attr="measured_value", config=REPORT_CONFIG_DEFAULT),
)
@registries.ZIGBEE_CHANNEL_REGISTRY.register(measurement.RelativeHumidity.cluster_id) @registries.ZIGBEE_CHANNEL_REGISTRY.register(measurement.RelativeHumidity.cluster_id)
class RelativeHumidity(ZigbeeChannel): class RelativeHumidity(ZigbeeChannel):
"""Relative Humidity measurement channel.""" """Relative Humidity measurement channel."""
REPORT_CONFIG = [ REPORT_CONFIG = (
{ AttrReportConfig(
"attr": "measured_value", attr="measured_value",
"config": (REPORT_CONFIG_MIN_INT, REPORT_CONFIG_MAX_INT, 100), config=(REPORT_CONFIG_MIN_INT, REPORT_CONFIG_MAX_INT, 100),
} ),
] )
@registries.ZIGBEE_CHANNEL_REGISTRY.register(measurement.SoilMoisture.cluster_id) @registries.ZIGBEE_CHANNEL_REGISTRY.register(measurement.SoilMoisture.cluster_id)
class SoilMoisture(ZigbeeChannel): class SoilMoisture(ZigbeeChannel):
"""Soil Moisture measurement channel.""" """Soil Moisture measurement channel."""
REPORT_CONFIG = [ REPORT_CONFIG = (
{ AttrReportConfig(
"attr": "measured_value", attr="measured_value",
"config": (REPORT_CONFIG_MIN_INT, REPORT_CONFIG_MAX_INT, 100), config=(REPORT_CONFIG_MIN_INT, REPORT_CONFIG_MAX_INT, 100),
} ),
] )
@registries.ZIGBEE_CHANNEL_REGISTRY.register(measurement.LeafWetness.cluster_id) @registries.ZIGBEE_CHANNEL_REGISTRY.register(measurement.LeafWetness.cluster_id)
class LeafWetness(ZigbeeChannel): class LeafWetness(ZigbeeChannel):
"""Leaf Wetness measurement channel.""" """Leaf Wetness measurement channel."""
REPORT_CONFIG = [ REPORT_CONFIG = (
{ AttrReportConfig(
"attr": "measured_value", attr="measured_value",
"config": (REPORT_CONFIG_MIN_INT, REPORT_CONFIG_MAX_INT, 100), config=(REPORT_CONFIG_MIN_INT, REPORT_CONFIG_MAX_INT, 100),
} ),
] )
@registries.ZIGBEE_CHANNEL_REGISTRY.register( @registries.ZIGBEE_CHANNEL_REGISTRY.register(
@ -92,12 +102,12 @@ class LeafWetness(ZigbeeChannel):
class TemperatureMeasurement(ZigbeeChannel): class TemperatureMeasurement(ZigbeeChannel):
"""Temperature measurement channel.""" """Temperature measurement channel."""
REPORT_CONFIG = [ REPORT_CONFIG = (
{ AttrReportConfig(
"attr": "measured_value", attr="measured_value",
"config": (REPORT_CONFIG_MIN_INT, REPORT_CONFIG_MAX_INT, 50), config=(REPORT_CONFIG_MIN_INT, REPORT_CONFIG_MAX_INT, 50),
} ),
] )
@registries.ZIGBEE_CHANNEL_REGISTRY.register( @registries.ZIGBEE_CHANNEL_REGISTRY.register(
@ -106,12 +116,12 @@ class TemperatureMeasurement(ZigbeeChannel):
class CarbonMonoxideConcentration(ZigbeeChannel): class CarbonMonoxideConcentration(ZigbeeChannel):
"""Carbon Monoxide measurement channel.""" """Carbon Monoxide measurement channel."""
REPORT_CONFIG = [ REPORT_CONFIG = (
{ AttrReportConfig(
"attr": "measured_value", attr="measured_value",
"config": (REPORT_CONFIG_MIN_INT, REPORT_CONFIG_MAX_INT, 0.000001), config=(REPORT_CONFIG_MIN_INT, REPORT_CONFIG_MAX_INT, 0.000001),
} ),
] )
@registries.ZIGBEE_CHANNEL_REGISTRY.register( @registries.ZIGBEE_CHANNEL_REGISTRY.register(
@ -120,24 +130,24 @@ class CarbonMonoxideConcentration(ZigbeeChannel):
class CarbonDioxideConcentration(ZigbeeChannel): class CarbonDioxideConcentration(ZigbeeChannel):
"""Carbon Dioxide measurement channel.""" """Carbon Dioxide measurement channel."""
REPORT_CONFIG = [ REPORT_CONFIG = (
{ AttrReportConfig(
"attr": "measured_value", attr="measured_value",
"config": (REPORT_CONFIG_MIN_INT, REPORT_CONFIG_MAX_INT, 0.000001), config=(REPORT_CONFIG_MIN_INT, REPORT_CONFIG_MAX_INT, 0.000001),
} ),
] )
@registries.ZIGBEE_CHANNEL_REGISTRY.register(measurement.PM25.cluster_id) @registries.ZIGBEE_CHANNEL_REGISTRY.register(measurement.PM25.cluster_id)
class PM25(ZigbeeChannel): class PM25(ZigbeeChannel):
"""Particulate Matter 2.5 microns or less measurement channel.""" """Particulate Matter 2.5 microns or less measurement channel."""
REPORT_CONFIG = [ REPORT_CONFIG = (
{ AttrReportConfig(
"attr": "measured_value", attr="measured_value",
"config": (REPORT_CONFIG_MIN_INT, REPORT_CONFIG_MAX_INT, 0.1), config=(REPORT_CONFIG_MIN_INT, REPORT_CONFIG_MAX_INT, 0.1),
} ),
] )
@registries.ZIGBEE_CHANNEL_REGISTRY.register( @registries.ZIGBEE_CHANNEL_REGISTRY.register(
@ -146,9 +156,9 @@ class PM25(ZigbeeChannel):
class FormaldehydeConcentration(ZigbeeChannel): class FormaldehydeConcentration(ZigbeeChannel):
"""Formaldehyde measurement channel.""" """Formaldehyde measurement channel."""
REPORT_CONFIG = [ REPORT_CONFIG = (
{ AttrReportConfig(
"attr": "measured_value", attr="measured_value",
"config": (REPORT_CONFIG_MIN_INT, REPORT_CONFIG_MAX_INT, 0.000001), config=(REPORT_CONFIG_MIN_INT, REPORT_CONFIG_MAX_INT, 0.000001),
} ),
] )

View File

@ -15,7 +15,7 @@ from ..const import (
REPORT_CONFIG_OP, REPORT_CONFIG_OP,
SIGNAL_ATTR_UPDATED, SIGNAL_ATTR_UPDATED,
) )
from .base import ZigbeeChannel from .base import AttrReportConfig, ZigbeeChannel
if TYPE_CHECKING: if TYPE_CHECKING:
from . import ChannelPool from . import ChannelPool
@ -66,9 +66,9 @@ class Metering(ZigbeeChannel):
"""Metering channel.""" """Metering channel."""
REPORT_CONFIG = ( REPORT_CONFIG = (
{"attr": "instantaneous_demand", "config": REPORT_CONFIG_OP}, AttrReportConfig(attr="instantaneous_demand", config=REPORT_CONFIG_OP),
{"attr": "current_summ_delivered", "config": REPORT_CONFIG_DEFAULT}, AttrReportConfig(attr="current_summ_delivered", config=REPORT_CONFIG_DEFAULT),
{"attr": "status", "config": REPORT_CONFIG_ASAP}, AttrReportConfig(attr="status", config=REPORT_CONFIG_ASAP),
) )
ZCL_INIT_ATTRS = { ZCL_INIT_ATTRS = {
"demand_formatting": True, "demand_formatting": True,