Skip to content

Commit 4362273

Browse files
authored
Ignore metering cluster handlers for invalid metering clusters (#432)
* Ignore metering cluster handlers for invalid metering clusters * Use the correct attribute definition * Regenerate device tests
1 parent 0ff6e10 commit 4362273

File tree

2 files changed

+15
-187
lines changed

2 files changed

+15
-187
lines changed

tests/data/devices/frient-a-s-emizb-151.json

Lines changed: 0 additions & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -9346,180 +9346,6 @@
93469346
"status": "NO_ALARMS",
93479347
"zcl_unit_of_measurement": 1
93489348
}
9349-
},
9350-
{
9351-
"info_object": {
9352-
"fallback_name": null,
9353-
"unique_id": "ab:cd:ef:12:74:0f:89:c3-65-1794-summation_delivered",
9354-
"migrate_unique_ids": [],
9355-
"platform": "sensor",
9356-
"class_name": "SmartEnergySummation",
9357-
"translation_key": "summation_delivered",
9358-
"device_class": null,
9359-
"state_class": null,
9360-
"entity_category": null,
9361-
"entity_registry_enabled_default": true,
9362-
"enabled": true,
9363-
"primary": false,
9364-
"cluster_handlers": [
9365-
{
9366-
"class_name": "MeteringClusterHandler",
9367-
"generic_id": "cluster_handler_0x0702",
9368-
"endpoint_id": 65,
9369-
"cluster": {
9370-
"id": 1794,
9371-
"name": "Metering",
9372-
"type": "server"
9373-
},
9374-
"id": "65:0x0702",
9375-
"unique_id": "ab:cd:ef:12:74:0f:89:c3:65:0x0702",
9376-
"status": "INITIALIZED",
9377-
"value_attribute": "instantaneous_demand"
9378-
}
9379-
],
9380-
"device_ieee": [
9381-
195,
9382-
137,
9383-
15,
9384-
116,
9385-
18,
9386-
239,
9387-
205,
9388-
171
9389-
],
9390-
"endpoint_id": 65,
9391-
"available": true,
9392-
"group_id": null,
9393-
"attribute": "current_summ_delivered",
9394-
"suggested_display_precision": 3,
9395-
"divisor": 1,
9396-
"multiplier": 1,
9397-
"unit": null
9398-
},
9399-
"state": {
9400-
"class_name": "SmartEnergySummation",
9401-
"available": true,
9402-
"state": 281474976710655.0,
9403-
"device_type": 255,
9404-
"status": "NO_ALARMS",
9405-
"zcl_unit_of_measurement": 255
9406-
}
9407-
},
9408-
{
9409-
"info_object": {
9410-
"fallback_name": null,
9411-
"unique_id": "ab:cd:ef:12:74:0f:89:c3-66-1794-summation_delivered",
9412-
"migrate_unique_ids": [],
9413-
"platform": "sensor",
9414-
"class_name": "SmartEnergySummation",
9415-
"translation_key": "summation_delivered",
9416-
"device_class": null,
9417-
"state_class": null,
9418-
"entity_category": null,
9419-
"entity_registry_enabled_default": true,
9420-
"enabled": true,
9421-
"primary": false,
9422-
"cluster_handlers": [
9423-
{
9424-
"class_name": "MeteringClusterHandler",
9425-
"generic_id": "cluster_handler_0x0702",
9426-
"endpoint_id": 66,
9427-
"cluster": {
9428-
"id": 1794,
9429-
"name": "Metering",
9430-
"type": "server"
9431-
},
9432-
"id": "66:0x0702",
9433-
"unique_id": "ab:cd:ef:12:74:0f:89:c3:66:0x0702",
9434-
"status": "INITIALIZED",
9435-
"value_attribute": "instantaneous_demand"
9436-
}
9437-
],
9438-
"device_ieee": [
9439-
195,
9440-
137,
9441-
15,
9442-
116,
9443-
18,
9444-
239,
9445-
205,
9446-
171
9447-
],
9448-
"endpoint_id": 66,
9449-
"available": true,
9450-
"group_id": null,
9451-
"attribute": "current_summ_delivered",
9452-
"suggested_display_precision": 3,
9453-
"divisor": 1,
9454-
"multiplier": 1,
9455-
"unit": null
9456-
},
9457-
"state": {
9458-
"class_name": "SmartEnergySummation",
9459-
"available": true,
9460-
"state": 281474976710655.0,
9461-
"device_type": 255,
9462-
"status": "NO_ALARMS",
9463-
"zcl_unit_of_measurement": 255
9464-
}
9465-
},
9466-
{
9467-
"info_object": {
9468-
"fallback_name": null,
9469-
"unique_id": "ab:cd:ef:12:74:0f:89:c3-67-1794-summation_delivered",
9470-
"migrate_unique_ids": [],
9471-
"platform": "sensor",
9472-
"class_name": "SmartEnergySummation",
9473-
"translation_key": "summation_delivered",
9474-
"device_class": null,
9475-
"state_class": null,
9476-
"entity_category": null,
9477-
"entity_registry_enabled_default": true,
9478-
"enabled": true,
9479-
"primary": false,
9480-
"cluster_handlers": [
9481-
{
9482-
"class_name": "MeteringClusterHandler",
9483-
"generic_id": "cluster_handler_0x0702",
9484-
"endpoint_id": 67,
9485-
"cluster": {
9486-
"id": 1794,
9487-
"name": "Metering",
9488-
"type": "server"
9489-
},
9490-
"id": "67:0x0702",
9491-
"unique_id": "ab:cd:ef:12:74:0f:89:c3:67:0x0702",
9492-
"status": "INITIALIZED",
9493-
"value_attribute": "instantaneous_demand"
9494-
}
9495-
],
9496-
"device_ieee": [
9497-
195,
9498-
137,
9499-
15,
9500-
116,
9501-
18,
9502-
239,
9503-
205,
9504-
171
9505-
],
9506-
"endpoint_id": 67,
9507-
"available": true,
9508-
"group_id": null,
9509-
"attribute": "current_summ_delivered",
9510-
"suggested_display_precision": 3,
9511-
"divisor": 1,
9512-
"multiplier": 1,
9513-
"unit": null
9514-
},
9515-
"state": {
9516-
"class_name": "SmartEnergySummation",
9517-
"available": true,
9518-
"state": 281474976710655.0,
9519-
"device_type": 255,
9520-
"status": "NO_ALARMS",
9521-
"zcl_unit_of_measurement": 255
9522-
}
95239349
}
95249350
],
95259351
"update": [

zha/application/platforms/sensor/__init__.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from zigpy.zcl import foundation
2222
from zigpy.zcl.clusters.closures import WindowCovering
2323
from zigpy.zcl.clusters.general import Basic
24+
from zigpy.zcl.clusters.smartenergy import Metering
2425

2526
from zha.application import Platform
2627
from zha.application.platforms import (
@@ -309,12 +310,17 @@ def handle_cluster_handler_attribute_updated(
309310
):
310311
self.maybe_emit_state_changed_event()
311312

312-
def _is_non_value(self, value: int | float) -> bool:
313+
def _is_non_value(
314+
self, value: int | float, *, attr_def: foundation.ZCLAttributeDef | None = None
315+
) -> bool:
313316
"""Ignore non-value numerical values."""
314-
if self._attr_def is None:
317+
if attr_def is None:
318+
attr_def = self._attr_def
319+
320+
if attr_def is None:
315321
return False
316322

317-
data_type = foundation.DataType.from_type_id(self._attr_def.zcl_type)
323+
data_type = foundation.DataType.from_type_id(attr_def.zcl_type)
318324
return value == data_type.non_value
319325

320326
def formatter(
@@ -999,16 +1005,12 @@ class SmartEnergyMetering(PollableSensor):
9991005
),
10001006
}
10011007

1002-
def __init__(
1003-
self,
1004-
cluster_handlers: list[ClusterHandler],
1005-
endpoint: Endpoint,
1006-
device: Device,
1007-
**kwargs: Any,
1008-
) -> None:
1009-
"""Init."""
1010-
super().__init__(cluster_handlers, endpoint, device, **kwargs)
1011-
self.recompute_capabilities()
1008+
def _is_supported(self) -> bool:
1009+
unit = self._cluster_handler.unit_of_measurement
1010+
if self._is_non_value(unit, attr_def=Metering.AttributeDefs.unit_of_measure):
1011+
return False
1012+
1013+
return super()._is_supported()
10121014

10131015
def recompute_capabilities(self) -> None:
10141016
"""Recompute capabilities and feature flags."""

0 commit comments

Comments
 (0)