Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set up reporting on AC attribute divisor and multiplier #348

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from

Conversation

puddly
Copy link
Contributor

@puddly puddly commented Jan 6, 2025

Should resolve zigpy/zha-device-handlers#3374

I'll test it out with a real plug when I get one.

divisor = self._divisor

value = float(value * multiplier) / divisor
if value < 100 and divisor > 1:
return round(value, self._decimals)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we remove rounding and let HA format this?

Copy link

@folfy folfy Jan 7, 2025

Choose a reason for hiding this comment

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

Yeah, but this might be required to avoid getting some rly weird numbers like x.99999978 because of using float in the line above and dividing the number? I didn't check the definition for self._decimals, just briefly having a look at your PR here, so also just giving a random opinion on this.

AttrReportConfig(
attr=ElectricalMeasurement.AttributeDefs.ac_power_divisor.name,
config=REPORT_CONFIG_IMMEDIATE,
),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I put these at the very beginning just in case the device's attribute reports are sent in the order of the reporting config. If this is the case, you may need to re-join the device to get this to work.

@puddly puddly force-pushed the puddly/ac-divisor-properties branch from 6d53bb8 to a29cfdf Compare January 6, 2025 18:21
Copy link

codecov bot commented Jan 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.50%. Comparing base (fd6cf2f) to head (a29cfdf).

Additional details and impacted files
@@           Coverage Diff           @@
##              dev     #348   +/-   ##
=======================================
  Coverage   96.50%   96.50%           
=======================================
  Files          61       61           
  Lines        9439     9446    +7     
=======================================
+ Hits         9109     9116    +7     
  Misses        330      330           

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

Comment on lines +65 to +88
AttrReportConfig(
attr=ElectricalMeasurement.AttributeDefs.ac_voltage_multiplier.name,
config=REPORT_CONFIG_IMMEDIATE,
),
AttrReportConfig(
attr=ElectricalMeasurement.AttributeDefs.ac_voltage_divisor.name,
config=REPORT_CONFIG_IMMEDIATE,
),
AttrReportConfig(
attr=ElectricalMeasurement.AttributeDefs.ac_current_multiplier.name,
config=REPORT_CONFIG_IMMEDIATE,
),
AttrReportConfig(
attr=ElectricalMeasurement.AttributeDefs.ac_current_divisor.name,
config=REPORT_CONFIG_IMMEDIATE,
),
AttrReportConfig(
attr=ElectricalMeasurement.AttributeDefs.ac_power_multiplier.name,
config=REPORT_CONFIG_IMMEDIATE,
),
AttrReportConfig(
attr=ElectricalMeasurement.AttributeDefs.ac_power_divisor.name,
config=REPORT_CONFIG_IMMEDIATE,
),
Copy link
Contributor

@TheJulianJES TheJulianJES Jan 10, 2025

Choose a reason for hiding this comment

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

ZCL_INIT_ATTRS with True will populate cached. REPORT_CONFIG will populate uncached. So, the attributes will be read twice. They should be removed from ZCL_INIT_ATTRS at least. Relevant code:

cached = [a for a, cached in self.ZCL_INIT_ATTRS.items() if cached]
uncached = [a for a, cached in self.ZCL_INIT_ATTRS.items() if not cached]
uncached.extend([cfg["attr"] for cfg in self.REPORT_CONFIG])

Do note that, by default, we will always read six more attributes per smart plug on network startup now, as the attributes are in uncached. Is that what we want?

(Also somewhat related is a change in this PR: https://github.com/zigpy/zha/pull/254/files#diff-90a1515ba92d644591ac0c972b7ed0d9e53112a3cc9bc00d27c9804273b5d2d8R458-R461)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Device Support Request] IKEA inspelning power monitoring smart plug
4 participants