Skip to content

Commit

Permalink
🌀 improve for fan entity
Browse files Browse the repository at this point in the history
  • Loading branch information
al-one committed Feb 20, 2025
1 parent 37e1b92 commit e39f75c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
1 change: 0 additions & 1 deletion custom_components/xiaomi_miot/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ def on_init(self):
hvac_modes.add(HVACMode.AUTO)
elif prop.in_list(['mode']):
self._conv_mode = conv
self._attr_hvac_modes = []
self._attr_preset_modes = prop.list_descriptions()
for mk, mv in self._hvac_modes.items():
val = prop.list_first(*(mv.get('list') or []))
Expand Down
14 changes: 7 additions & 7 deletions custom_components/xiaomi_miot/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def is_on(self):
async def async_turn_on(self, percentage=None, preset_mode=None, **kwargs):
dat = {}
if self._conv_power and not self.is_on:
dat[self._conv_power.attr] = True
dat[self._conv_power.full_name] = True
if percentage is not None:
if self._prop_percentage:
await self.device.async_set_property(self._prop_percentage, percentage)
Expand All @@ -181,19 +181,19 @@ async def async_turn_on(self, percentage=None, preset_mode=None, **kwargs):
if val is not None:
await self.device.async_set_property(self._prop_speed, val)
elif self._speed_range:
dat[self._conv_speed.attr] = percentage_to_ranged_value(self._speed_range, percentage)
dat[self._conv_speed.full_name] = percentage_to_ranged_value(self._speed_range, percentage)
elif self._speed_list:
des = percentage_to_ordered_list_item(self._speed_list, percentage)
dat[self._conv_speed.attr] = self._conv_speed.prop.list_value(des)
dat[self._conv_speed.full_name] = self._conv_speed.prop.list_value(des)
if preset_mode is not None:
dat[self._conv_mode.attr] = preset_mode
dat[self._conv_mode.full_name] = preset_mode
if dat:
await self.device.async_write(dat)

async def async_turn_off(self, **kwargs):
if not self._conv_power:
return
await self.device.async_write({self._conv_power.attr: False})
await self.device.async_write({self._conv_power.full_name: False})

async def async_set_percentage(self, percentage: int):
if percentage == 0 and self._conv_power:
Expand All @@ -204,12 +204,12 @@ async def async_set_percentage(self, percentage: int):
async def async_set_preset_mode(self, preset_mode: str):
if not self._conv_mode:
return
await self.device.async_write({self._conv_mode.attr: preset_mode})
await self.device.async_write({self._conv_mode.full_name: preset_mode})

async def async_oscillate(self, oscillating: bool):
if not self._conv_oscillate:
return
await self.device.async_write({self._conv_oscillate.attr: oscillating})
await self.device.async_write({self._conv_oscillate.full_name: oscillating})

XEntity.CLS[ENTITY_DOMAIN] = FanEntity

Expand Down

0 comments on commit e39f75c

Please sign in to comment.