Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions zhaquirks/xiaomi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ def _parse_aqara_attributes(self, value):
"lumi.relay.c2acn01",
"lumi.switch.n0agl1",
"lumi.switch.n0acn2",
"lumi.switch.acn047",
]:
attribute_names.update({149: CONSUMPTION, 150: VOLTAGE, 152: POWER})
elif self.endpoint.device.model == "lumi.switch.agl011":
Expand Down
11 changes: 10 additions & 1 deletion zhaquirks/xiaomi/aqara/switch_acn047.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ def _update_attribute(self, attrid, value):
super()._update_attribute(attrid, value)


class T2MeteringCluster(MeteringCluster):
"""T2 Metering cluster to fix divisor."""

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this work? It should avoid requiring any runtime-testable code:

    _CONSTANT_ATTRIBUTES = {
        MeteringCluster.AttributeDefs.divisor.id: 1000,
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! But its 1000000 instead since 1000 is already what we have by default for xiaomi: https://github.com/zigpy/zha-device-handlers/blob/dev/zhaquirks/xiaomi/__init__.py#L712

Copy link
Contributor

@puddly puddly Nov 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. In that case you'd need to do _CONSTANT_ATTRIBUTES = {**MeteringCluster._CONSTANT_ATTRIBUTES, MeteringCluster.AttributeDefs.divisor.id: 1000000,}.

Is the device really sending reports scaled this much? Or are we hiding a * 1000 somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. In that case you'd need to do _CONSTANT_ATTRIBUTES = {**MeteringCluster._CONSTANT_ATTRIBUTES, MeteringCluster.AttributeDefs.divisor.id: 1000000,}.

Oh, duh! This is a sign that I should probably go to sleep... 😆

Is the device really sending reports scaled this much? Or are we hiding a * 1000 somewhere?

We scale it here: https://github.com/abmantis/zha-device-handlers/blob/xiaomi_t2_fix_energy/zhaquirks/xiaomi/__init__.py#L

Copy link
Collaborator

@TheJulianJES TheJulianJES Nov 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Z2M also has a special case for this device:
https://github.com/Koenkk/zigbee-herdsman-converters/blob/ea780c92873ad254818f9bb7060f9417879893d6/src/lib/lumi.ts#L503-L507

The standard 1000 divisor is because of us needing to do the trip through zigpy cache/ZCL datatypes: https://github.com/abmantis/zha-device-handlers/blob/3916d9b9efa74e35a745c1c3d88cccb1645e86f2/zhaquirks/xiaomi/__init__.py#L329-L333
Z2M doesn't need to do this, but we'd just cut off all decimal points otherwise.

_CONSTANT_ATTRIBUTES = {
**MeteringCluster._CONSTANT_ATTRIBUTES,
MeteringCluster.AttributeDefs.divisor.id: 1000000,
}


class OppleCluster(XiaomiAqaraE1Cluster):
"""Opple cluster."""

Expand Down Expand Up @@ -197,7 +206,7 @@ class AqaraT2Relay(XiaomiCustomDevice):
OnOff.cluster_id,
MultistateInputCluster,
DeviceTemperature.cluster_id,
MeteringCluster,
T2MeteringCluster,
ElectricalMeasurementCluster,
OppleCluster,
],
Expand Down
Loading