Skip to content

Conversation

@abmantis
Copy link
Contributor

@abmantis abmantis commented Nov 2, 2025

Proposed change

SSIA.

Additional information

Device diagnostics

Checklist

  • The changes are tested and work correctly
  • pre-commit checks pass / the code has been formatted using Black
  • Tests have been added to verify that the new code works
  • Device diagnostics data has been attached

@codecov
Copy link

codecov bot commented Nov 2, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.24%. Comparing base (aa7b32d) to head (e7661d2).

Additional details and impacted files
@@           Coverage Diff           @@
##              dev    #4458   +/-   ##
=======================================
  Coverage   92.24%   92.24%           
=======================================
  Files         369      369           
  Lines       12088    12090    +2     
=======================================
+ Hits        11150    11152    +2     
  Misses        938      938           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.


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.

@abmantis abmantis requested a review from puddly November 2, 2025 01:39
@TheJulianJES TheJulianJES added bugfix This PR fixes a bug Xiaomi Request/PR regarding a Xiaomi or Aqara device labels Nov 2, 2025
@abmantis abmantis requested a review from TheJulianJES November 2, 2025 02:13
Copy link
Collaborator

@TheJulianJES TheJulianJES left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

@TheJulianJES
Copy link
Collaborator

Energy and voltage just didn't display for this device before at all, right?

@TheJulianJES TheJulianJES added the smash This PR is close to be merged soon label Nov 2, 2025
@abmantis
Copy link
Contributor Author

abmantis commented Nov 2, 2025

Energy and voltage just didn't display for this device before at all, right?

Power was already displayed and updated more frequently than the custom xiaomi attribute updates.
IIRC energy and voltage where shown as 0. If you think it is relevant, I can unpair a device and pair it to my dev env to check it out with a clean database.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix This PR fixes a bug smash This PR is close to be merged soon Xiaomi Request/PR regarding a Xiaomi or Aqara device

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants