Пример #1
0
 def _async_update_attrs(self) -> None:
     """Update attrs from device."""
     self._attr_is_on = self._device.fan_on
     self._attr_current_direction = SENSEME_DIRECTION_TO_HASS.get(
         self._device.fan_dir,
         DIRECTION_FORWARD  # None also means forward
     )
     if self._device.fan_speed is not None:
         self._attr_percentage = ranged_value_to_percentage(
             self._device.fan_speed_limits, self._device.fan_speed)
     else:
         self._attr_percentage = None
     whoosh = self._device.fan_whoosh_mode
     self._attr_preset_mode = PRESET_MODE_WHOOSH if whoosh else None
     super()._async_update_attrs()
Пример #2
0
 def _async_update_attrs(self) -> None:
     """Update attrs from device."""
     self._attr_is_on = self._device.fan_mode == OffOnAuto.ON
     self._attr_current_direction = DIRECTION_FORWARD
     if self._device.reverse_enable:
         self._attr_current_direction = DIRECTION_REVERSE
     if self._device.speed is not None:
         self._attr_percentage = ranged_value_to_percentage(
             SPEED_RANGE, self._device.speed
         )
     else:
         self._attr_percentage = None
     auto = self._device.fan_mode == OffOnAuto.AUTO
     self._attr_preset_mode = PRESET_MODE_AUTO if auto else None
     super()._async_update_attrs()
Пример #3
0
async def test_ranged_value_to_percentage_small():
    """Test a small range of low and high values convert a single value to a percentage."""
    range = (1, 6)

    assert ranged_value_to_percentage(range, 1) == 16
    assert ranged_value_to_percentage(range, 2) == 33
    assert ranged_value_to_percentage(range, 3) == 50
    assert ranged_value_to_percentage(range, 4) == 66
    assert ranged_value_to_percentage(range, 5) == 83
    assert ranged_value_to_percentage(range, 6) == 100
Пример #4
0
    async def _async_adjust_speed(self, modifier: int,
                                  percentage_step: int | None) -> None:
        """Increase or decrease the speed of the fan."""
        current_percentage = self.percentage or 0

        if percentage_step is not None:
            new_percentage = current_percentage + (percentage_step * modifier)
        else:
            speed_range = (1, self.speed_count)
            speed_index = math.ceil(
                percentage_to_ranged_value(speed_range, current_percentage))
            new_percentage = ranged_value_to_percentage(
                speed_range, speed_index + modifier)

        new_percentage = max(0, min(100, new_percentage))

        await self.async_set_percentage(new_percentage)
Пример #5
0
    def status_updated(self):
        """Get state of Tuya fan."""
        self._is_on = self.dps(self._dp_id)

        current_speed = self.dps_conf(CONF_FAN_SPEED_CONTROL)
        if self._use_ordered_list:
            _LOGGER.debug(
                "Fan current_speed ordered_list_item_to_percentage: %s from %s",
                current_speed,
                self._ordered_list,
            )
            if current_speed is not None:
                self._percentage = ordered_list_item_to_percentage(
                    self._ordered_list, current_speed)

        else:
            _LOGGER.debug(
                "Fan current_speed ranged_value_to_percentage: %s from %s",
                current_speed,
                self._speed_range,
            )
            if current_speed is not None:
                self._percentage = ranged_value_to_percentage(
                    self._speed_range, int(current_speed))

        _LOGGER.debug("Fan current_percentage: %s", self._percentage)

        if self.has_config(CONF_FAN_OSCILLATING_CONTROL):
            self._oscillating = self.dps_conf(CONF_FAN_OSCILLATING_CONTROL)
            _LOGGER.debug("Fan current_oscillating : %s", self._oscillating)

        if self.has_config(CONF_FAN_DIRECTION):
            value = self.dps_conf(CONF_FAN_DIRECTION)
            if value is not None:
                if value == self._config.get(CONF_FAN_DIRECTION_FWD):
                    self._direction = DIRECTION_FORWARD

                if value == self._config.get(CONF_FAN_DIRECTION_REV):
                    self._direction = DIRECTION_REVERSE
            _LOGGER.debug("Fan current_direction : %s > %s", value,
                          self._direction)
Пример #6
0
 def percentage_received(msg):
     """Handle new received MQTT message for the percentage."""
     numeric_val_str = self._value_templates[ATTR_PERCENTAGE](
         msg.payload)
     try:
         percentage = ranged_value_to_percentage(
             self._speed_range, int(numeric_val_str))
     except ValueError:
         _LOGGER.warning(
             "'%s' received on topic %s is not a valid speed within the speed range",
             msg.payload,
             msg.topic,
         )
         return
     if percentage < 0 or percentage > 100:
         _LOGGER.warning(
             "'%s' received on topic %s is not a valid speed within the speed range",
             msg.payload,
             msg.topic,
         )
         return
     self._percentage = percentage
     self.async_write_ha_state()
Пример #7
0
 def percentage(self) -> Optional[int]:
     """Return the current speed percentage."""
     return ranged_value_to_percentage(
         self._speed_range, self._client.get_pump(self._num - 1)
     )
Пример #8
0
    def percentage(self):
        """Return the current percentage based speed."""
        if self._state:
            return ranged_value_to_percentage((1, 3), self._fan_level)

        return None
 def percentage(self) -> Optional[int]:
     """Return the current speed percentage."""
     return ranged_value_to_percentage(SPEED_RANGE, self._current_speed)
Пример #10
0
 def percentage(self):
     """Return the current speed percentage."""
     if self.auto_mode:
         return None
     return ranged_value_to_percentage(SPEED_RANGE,
                                       int(self._device.state.speed))
Пример #11
0
 def percentage(self) -> Optional[int]:
     """Return the current speed percentage."""
     if self._device.speed is None:
         return None
     return ranged_value_to_percentage(SPEED_RANGE, int(self._device.speed))
Пример #12
0
 def percentage(self):
     """Return the current speed percentage"""
     return ranged_value_to_percentage(
         (self._minimum_speed, self._fan.max_speed), self._speed)
Пример #13
0
 def percentage(self) -> int:
     """Return speed percentage of the fan."""
     if self._smarty_fan_speed == 0:
         return 0
     return ranged_value_to_percentage(SPEED_RANGE, self._smarty_fan_speed)
Пример #14
0
 def percentage(self) -> int:
     """Return the current speed percentage."""
     return ranged_value_to_percentage(SPEED_RANGE, self.info.primary_value.value)
Пример #15
0
 def percentage(self):
     return ranged_value_to_percentage(BAYERNLUEFTER_SPEED_RANGE,
                                       self._current_speed())
Пример #16
0
 def percentage(self) -> str:
     """Return the current speed percentage."""
     if self._insteon_device_group.value is None:
         return None
     return ranged_value_to_percentage(SPEED_RANGE,
                                       self._insteon_device_group.value)
Пример #17
0
 def percentage(self) -> str:
     """Return the current speed percentage."""
     speed = self._ccb.data[SENSOR_FAN_SPEED_MODE]
     if speed is None:
         return None
     return ranged_value_to_percentage(SPEED_RANGE, speed)
Пример #18
0
 def percentage(self) -> int:
     """Return the current speed percentage for the fan."""
     if not self._speed or not self._power:
         return 0
     return ranged_value_to_percentage(self._speed_range, self._speed)
Пример #19
0
 def percentage(self) -> str:
     """Return the current speed percentage."""
     if self._node.status == ISY_VALUE_UNKNOWN:
         return None
     return ranged_value_to_percentage(SPEED_RANGE, self._node.status)
Пример #20
0
 def percentage(self) -> str:
     """Return the current speed."""
     return ranged_value_to_percentage(self._device.fan_speed_limits,
                                       self._device.fan_speed)
Пример #21
0
Файл: fan.py Проект: 2Fake/core
 def percentage(self) -> int:
     """Return the current speed percentage."""
     return ranged_value_to_percentage(SPEED_RANGE,
                                       self._device.status.fan_speed)
Пример #22
0
 def percentage(self) -> int | None:
     """Return the current speed percentage."""
     if self.info.primary_value.value is None:
         # guard missing value
         return None
     return ranged_value_to_percentage(SPEED_RANGE, self.info.primary_value.value)
Пример #23
0
 def percentage(self) -> int:
     """Return the current speed percentage."""
     return ranged_value_to_percentage(SPEED_RANGE, self._fan_mode)
Пример #24
0
 def percentage(self) -> int | None:
     """Return the current speed percentage."""
     if self.current_speed is None:
         return None
     return ranged_value_to_percentage(SPEED_RANGE, self.current_speed)
Пример #25
0
 def percentage(self):
     """Return the current speed percentage."""
     return ranged_value_to_percentage(SPEED_RANGE, self._state)
Пример #26
0
 def percentage(self) -> int:
     """Return percentage of the fan."""
     return ranged_value_to_percentage(SPEED_RANGE, self.device.speed)
Пример #27
0
 def percentage(self):
     """Return the current speed."""
     if (self.smartfan.mode == "manual"
             and (current_level := self.smartfan.fan_level) is not None):
         return ranged_value_to_percentage(SPEED_RANGE, current_level)
Пример #28
0
 def percentage(self) -> Optional[int]:
     """Return the current speed percentage."""
     speed = self._ccb.data.get(SENSOR_FAN_SPEED_MODE)
     if speed is None:
         return None
     return ranged_value_to_percentage(SPEED_RANGE, speed)