def preset_mode(self): """Get the active preset mode.""" if self._state: preset_mode = AirpurifierOperationMode( self._state_attrs[ATTR_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 = AirpurifierOperationMode(self._state_attrs[ATTR_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
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: await self._try_command( "Setting operation mode of the miio device failed.", self._device.set_mode, AirpurifierOperationMode(self.SPEED_MODE_MAPPING[speed_mode]), )
def speed(self): """Return the current speed.""" if self._state: return AirpurifierOperationMode(self._state_attrs[ATTR_MODE]).name return None