Fix Tuya v2 fan percentage (#56954)

* fix:Some fans do not have a fan_speed_percent key

* fix comment format issue

Co-authored-by: erchuan <jie.zheng@tuya.com>
This commit is contained in:
Oliver Ou 2021-10-03 08:41:31 +08:00 committed by GitHub
parent 06602e6cc5
commit 6c2a18c3e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -211,7 +211,7 @@ class TuyaHaFan(TuyaHaEntity, FanEntity):
return self.tuya_device.status[DPCODE_MODE]
@property
def percentage(self) -> int:
def percentage(self) -> int | None:
"""Return the current speed."""
if not self.is_on:
return 0
@ -228,7 +228,8 @@ class TuyaHaFan(TuyaHaEntity, FanEntity):
self.tuya_device.status[DPCODE_AP_FAN_SPEED_ENUM],
)
return self.tuya_device.status[DPCODE_FAN_SPEED]
# some type may not have the fan_speed_percent key
return self.tuya_device.status.get(DPCODE_FAN_SPEED)
@property
def speed_count(self) -> int: