示例#1
0
    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()
示例#2
0
    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
示例#3
0
    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
示例#4
0
    def speed(self):
        """Return the current speed."""
        if self._state:
            return AirfreshOperationMode(self._state_attrs[ATTR_MODE]).name

        return None
示例#5
0
    def speed(self):
        """Return the current speed."""
        if self._state:
            return AirfreshOperationMode(self._mode).name

        return None