-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
Fix ZHA handling of power factor ElectricalMeasurement attribute sensor #107641
Fix ZHA handling of power factor ElectricalMeasurement attribute sensor #107641
Conversation
Hey there @dmulcahey, @Adminiuga, @puddly, @TheJulianJES, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
Amend power_factor calculation to respect Zigbee cluster specification - required for release of zha fix: home-assistant/core#107641
d357eca
to
081abba
Compare
@jeverley there are lint errors here |
Amend power_factor calculation to respect Zigbee cluster specification - required for release of zha fix: home-assistant/core#107641
71d49e0
to
b5d98f8
Compare
Resolved now 👍 |
Amend power_factor calculation to respect Zigbee cluster specification - required for release of zha fix: home-assistant/core#107641
b5d98f8
to
ded3366
Compare
The Zigbee Cluster Library defines PowerFactor as an int8 with value supported from -100 to 100. Currently the zha sensor handler attempts to apply the ac_power_divisor and ac_power_multiplier formatters against the attribute value, the spec outlines that this should not be the case. The impact of the current code is that quirks not using the default values of 1 are multiplying/dividing power and power factor values prior to updating the cluster attribute. This results in either a non-conformant power_factor e.g. the value was multiplied by 10 so that an ac_power_divider of 10 could be used, or the power readings sacrificing a point of measurement for lower readings. Two quirks currently use this workaround: * ts0601_din_power.py * ts0601_rcbo.py
Co-authored-by: Joakim Plate <elupus@ecce.se>
085828a
to
2f253d0
Compare
@jeverley you have a test conflict from your other PR I think |
@dmulcahey thanks for the heads up, I've resolved the conflict 👍 |
Currently marked as a "breaking change", but if quirks is updated, this shouldn't be breaking, right? |
Correct, it's only breaking if we don't release the quirk update in parallel (assume we'd want a note in the release notes for anyone using custom quirks). |
was automatically closed because the quirks PR included "fix #thisPr" 😅 We should probably wait with merging this one until the quirks bump has been made, otherwise the nightly builds would show the incorrect value for the Tuya RCBO devices. The PR already looks good though. |
I've removed the breaking change section and label to clarify that this PR is not a breaking change, but rather just a bug-fix, since the merged quirks bump includes your quirks PR change. So, there's no "breaking change" in that case.
Custom quirks are unsupported, but I did have a quick look in the issues section and I didn't notice any custom quirks that even update the power factor. So, there should be no issues there either. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes LGTM. Thanks!
…re#107641 (zigpy#2896) Amend power_factor calculation to respect Zigbee cluster specification - required for release of ZHA fix: home-assistant/core#107641
Proposed change
The Zigbee Cluster Library defines PowerFactor as an int8 with value supported from -100 to 100.
Currently the zha sensor handler defaults to applying the ac_power_divisor and ac_power_multiplier formatters against the power_factor attribute value as _div_mul_prefix is not set for the sensor.
The Cluster Library spec outlines that this should not be the case, the native Zigbee attribute value provides with a % value out of 100.
This change updates the formatter method for sensor class ElectricalMeasurement and ElectricalMeasurementPowerFactor sensor handler to address this.
https://zigbeealliance.org/wp-content/uploads/2021/10/07-5123-08-Zigbee-Cluster-Library.pdf
See: 4.9.2.2.6, 4.9.2.2.6.15, 4.9.2.2.7.5
The impact of the existing implementation is that quirks not using the default power divisor/multiplier values of 1 are having to multiply power factor prior to updating the cluster attribute, i.e. if the ac_power_divisor is 10, the quirk would multiply the power factor of 100 to 1000.
This results in an out of spec power_factor value.
Reviewing zha-cluster-handlers only one quirk currently use this workaround so impact of this fix should be minimal.
zha-quirks had one quirk updated, so this change is no longer breaking.
PR:
Type of change
Additional information
Checklist
ruff format homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.To help with the load of incoming pull requests: