hass-core/tests
Jack 2909e1c4fe
Fix ZHA handling of power factor ElectricalMeasurement attribute sensor (#107641)
* Correct handling of power_factor ElectricalMeasurement attribute

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

* Update ZHA Metering formatter to perform None check on _div_mul_prefix

To address feedback:
https://github.com/home-assistant/core/pull/107641#discussion_r1447547054

* _div_mul_prefix needs self reference

* Simplify None check for _div_mul_prefix

Co-authored-by: Joakim Plate <elupus@ecce.se>

* Updates to formatting and CI test typing fix

* Use ' | ' in place of Union

* Add tests for power_factor sensor

---------

Co-authored-by: Joakim Plate <elupus@ecce.se>
2024-01-30 23:11:18 +01:00
..
auth Add expiration of unused refresh tokens (#108428) 2024-01-24 13:24:22 -10:00
components Fix ZHA handling of power factor ElectricalMeasurement attribute sensor (#107641) 2024-01-30 23:11:18 +01:00
fixtures Fix feedreader date comparison to allow RSS entries with identical timestamps (#104925) 2023-12-23 16:48:36 +01:00
hassfest Add type hints to core tests (#88478) 2023-02-20 11:42:56 +01:00
helpers Add default parameter to as_datetime template function/filter (#107229) 2024-01-29 18:05:44 +01:00
pylint Add pylint plugin to check if coordinator is placed in its own module (#108174) 2024-01-29 10:30:19 +01:00
resources
scripts Use modern platform path when reporting platform config errors (#104238) 2023-12-05 15:06:13 +01:00
snapshots Add minor version to config entries (#105479) 2023-12-12 08:44:35 +01:00
test_util
testing_config Add icon translations support (#103294) 2024-01-19 16:56:56 +01:00
util Add DurationConverter (#108865) 2024-01-30 23:08:12 +01:00
__init__.py
common.py Small speed up to checking core state (#107845) 2024-01-18 08:41:32 -10:00
conftest.py Remove deprecated event_loop fixtures in tests (#109048) 2024-01-29 14:24:58 +01:00
ignore_uncaught_exceptions.py
patch_time.py
ruff.toml
syrupy.py
test_bootstrap.py Remove deprecated event_loop fixtures in tests (#109048) 2024-01-29 14:24:58 +01:00
test_config.py Deprecate legacy_templates (#105556) 2023-12-22 00:42:16 +01:00
test_config_entries.py Small speed up to listing config entries in the websocket api (#108892) 2024-01-25 20:20:19 -10:00
test_const.py Flow rate unit conversions and device class (#106077) 2024-01-30 15:01:08 +01:00
test_core.py Remove deprecated event_loop fixtures in tests (#109048) 2024-01-29 14:24:58 +01:00
test_data_entry_flow.py Fix FlowHandler show progress (#108586) 2024-01-21 22:40:48 +01:00
test_exceptions.py
test_loader.py Avoid keeping config dir in path (#107760) 2024-01-16 13:38:47 +01:00
test_main.py
test_requirements.py Switch formatting from black to ruff-format (#102893) 2023-11-27 14:38:59 +01:00
test_runner.py Trigger Home Assistant shutdown automations right before the stop event instead of during it (#91165) 2023-12-05 11:24:41 -10:00
test_setup.py Reverse component path (#104087) 2023-12-05 08:43:58 +01:00
test_test_fixtures.py Patch aiohttp server app router freeze in tests (#105555) 2023-12-12 14:40:38 +01:00
typing.py