Skip to content

Commit 547971c

Browse files
authored
Update Tuya RCBO quirk power factor calculation for home-assistant/core#107641 (#2896)
Amend power_factor calculation to respect Zigbee cluster specification - required for release of ZHA fix: home-assistant/core#107641
1 parent 0b19318 commit 547971c

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

tests/test_tuya_rcbo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,11 +346,11 @@ async def test_power_factor(zigpy_device_from_quirk):
346346
b"\x09\x07\x01\x02\x03g\x00\x00\x0c\x00\x09\xbf\x00\x09\xbf\x00\x00\x00\x00\x00\x00"
347347
)
348348
tuya_cluster.handle_message(hdr, args) # active_power
349-
assert tuya_listener.attribute_updates == [(0x050B, 2495), (0x0510, 1000)]
349+
assert tuya_listener.attribute_updates == [(0x050B, 2495), (0x0510, 100)]
350350

351351
tuya_listener.attribute_updates = []
352352
hdr, args = tuya_cluster.deserialize(
353353
b"\x09\x08\x01\x02\x03g\x00\x00\x0c\x00\x06\x4b\x00\x06\x4b\x00\x00\x00\x00\x00\x00"
354354
)
355355
tuya_cluster.handle_message(hdr, args) # active_power
356-
assert tuya_listener.attribute_updates == [(0x050B, 1611), (0x0510, 987)]
356+
assert tuya_listener.attribute_updates == [(0x050B, 1611), (0x0510, 99)]

zhaquirks/tuya/ts0601_rcbo.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,10 @@ def update_attribute(self, attr_name: str, value: Any) -> None:
248248
if attr_name == "active_power":
249249
apparent_power = self.get("apparent_power")
250250
if apparent_power:
251-
power_factor = value / apparent_power * 1000
252-
if power_factor > 1000:
253-
power_factor = 1000
254-
super().update_attribute("power_factor", int(power_factor))
251+
power_factor = value / apparent_power * 100
252+
if power_factor > 100:
253+
power_factor = 100
254+
super().update_attribute("power_factor", round(power_factor))
255255

256256

257257
class TuyaRCBODeviceTemperature(DeviceTemperature, TuyaAttributesCluster):

0 commit comments

Comments
 (0)