Skip to content

Commit

Permalink
Update Tuya RCBO quirk power factor calculation for home-assistant/co…
Browse files Browse the repository at this point in the history
…re#107641 (#2896)

Amend power_factor calculation to respect Zigbee cluster specification - required for release of ZHA fix:
home-assistant/core#107641
  • Loading branch information
jeverley authored Jan 24, 2024
1 parent 0b19318 commit 547971c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions tests/test_tuya_rcbo.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,11 @@ async def test_power_factor(zigpy_device_from_quirk):
b"\x09\x07\x01\x02\x03g\x00\x00\x0c\x00\x09\xbf\x00\x09\xbf\x00\x00\x00\x00\x00\x00"
)
tuya_cluster.handle_message(hdr, args) # active_power
assert tuya_listener.attribute_updates == [(0x050B, 2495), (0x0510, 1000)]
assert tuya_listener.attribute_updates == [(0x050B, 2495), (0x0510, 100)]

tuya_listener.attribute_updates = []
hdr, args = tuya_cluster.deserialize(
b"\x09\x08\x01\x02\x03g\x00\x00\x0c\x00\x06\x4b\x00\x06\x4b\x00\x00\x00\x00\x00\x00"
)
tuya_cluster.handle_message(hdr, args) # active_power
assert tuya_listener.attribute_updates == [(0x050B, 1611), (0x0510, 987)]
assert tuya_listener.attribute_updates == [(0x050B, 1611), (0x0510, 99)]
8 changes: 4 additions & 4 deletions zhaquirks/tuya/ts0601_rcbo.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,10 @@ def update_attribute(self, attr_name: str, value: Any) -> None:
if attr_name == "active_power":
apparent_power = self.get("apparent_power")
if apparent_power:
power_factor = value / apparent_power * 1000
if power_factor > 1000:
power_factor = 1000
super().update_attribute("power_factor", int(power_factor))
power_factor = value / apparent_power * 100
if power_factor > 100:
power_factor = 100
super().update_attribute("power_factor", round(power_factor))


class TuyaRCBODeviceTemperature(DeviceTemperature, TuyaAttributesCluster):
Expand Down

0 comments on commit 547971c

Please sign in to comment.