fix: set fan on/off state before set the percentage (#1031)
Some checks failed
Tests / check-rule-format (push) Has been cancelled
Validate / validate-hassfest (push) Has been cancelled
Validate / validate-hacs (push) Has been cancelled
Validate / validate-lint (push) Has been cancelled
Validate / validate-setup (push) Has been cancelled

This commit is contained in:
Li Shuzhen 2025-04-27 20:13:34 +08:00 committed by GitHub
parent db77af8a13
commit b4ece958ac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -236,6 +236,9 @@ class Fan(MIoTServiceEntity, FanEntity):
async def async_set_percentage(self, percentage: int) -> None: async def async_set_percentage(self, percentage: int) -> None:
"""Set the percentage of the fan speed.""" """Set the percentage of the fan speed."""
if percentage > 0: if percentage > 0:
if not self.is_on:
# If the fan is off, turn it on.
await self.set_property_async(prop=self._prop_on, value=True)
if self._speed_names: if self._speed_names:
await self.set_property_async( await self.set_property_async(
prop=self._prop_fan_level, prop=self._prop_fan_level,
@ -249,9 +252,6 @@ class Fan(MIoTServiceEntity, FanEntity):
value=int(percentage_to_ranged_value( value=int(percentage_to_ranged_value(
low_high_range=(self._speed_min, self._speed_max), low_high_range=(self._speed_min, self._speed_max),
percentage=percentage))) percentage=percentage)))
if not self.is_on:
# If the fan is off, turn it on.
await self.set_property_async(prop=self._prop_on, value=True)
else: else:
await self.set_property_async(prop=self._prop_on, value=False) await self.set_property_async(prop=self._prop_on, value=False)