async def async_set_percentage(self, percentage: int) -> None: """Set the percentage of the fan. This method is a coroutine. """ speed_mode = math.ceil( percentage_to_ranged_value((1, self._speed_count), percentage)) if speed_mode: if await self._try_command( "Setting operation mode of the miio device failed.", self._device.set_mode, AirfreshOperationMode(self.SPEED_MODE_MAPPING[speed_mode]), ): self._mode = AirfreshOperationMode( self.SPEED_MODE_MAPPING[speed_mode]).value self.async_write_ha_state()
def preset_mode(self): """Get the active preset mode.""" if self._state: preset_mode = AirfreshOperationMode(self._mode).name return preset_mode if preset_mode in self._preset_modes else None return None
def percentage(self): """Return the current percentage based speed.""" if self._state: mode = AirfreshOperationMode(self._mode) if mode in self.REVERSE_SPEED_MODE_MAPPING: return ranged_value_to_percentage( (1, self._speed_count), self.REVERSE_SPEED_MODE_MAPPING[mode] ) return None
def speed(self): """Return the current speed.""" if self._state: return AirfreshOperationMode(self._state_attrs[ATTR_MODE]).name return None
def speed(self): """Return the current speed.""" if self._state: return AirfreshOperationMode(self._mode).name return None