mirror of
https://github.com/home-assistant/developers.home-assistant.git
synced 2025-07-14 12:56:30 +00:00
Document speed_count for fans and the utility
This commit is contained in:
commit
3163f3ea26
@ -17,6 +17,7 @@ Properties should always only return information from memory and not do I/O (lik
|
|||||||
| is_on | boolean | None |Return true if the entity is on |
|
| is_on | boolean | None |Return true if the entity is on |
|
||||||
| oscillating | boolean | None | Return true if the fan is oscillating |
|
| oscillating | boolean | None | Return true if the fan is oscillating |
|
||||||
| percentage | int | None | Return the current speed percentage. Must be a value between 0 (off) and 100 |
|
| percentage | int | None | Return the current speed percentage. Must be a value between 0 (off) and 100 |
|
||||||
|
| speed_count | int | 100 | The number of speeds the fan supports |
|
||||||
| supported_features | int | 0 | Flag supported features |
|
| supported_features | int | 0 | Flag supported features |
|
||||||
| preset_mode | str | None | Return the current preset_mode. One of the values in preset_modes. |
|
| preset_mode | str | None | Return the current preset_mode. One of the values in preset_modes. |
|
||||||
| preset_modes | list | None | Get the list of available preset_modes. This is an arbitrary list of str and should not contain any speeds. |
|
| preset_modes | list | None | Get the list of available preset_modes. This is an arbitrary list of str and should not contain any speeds. |
|
||||||
@ -103,18 +104,42 @@ ORDERED_NAMED_FAN_SPEEDS = ["one", "two", "three", "four", "five", "six"] # off
|
|||||||
percentage = ordered_list_item_to_percentage(ORDERED_NAMED_FAN_SPEEDS, "three")
|
percentage = ordered_list_item_to_percentage(ORDERED_NAMED_FAN_SPEEDS, "three")
|
||||||
|
|
||||||
named_speed = percentage_to_ordered_list_item(ORDERED_NAMED_FAN_SPEEDS, 23)
|
named_speed = percentage_to_ordered_list_item(ORDERED_NAMED_FAN_SPEEDS, 23)
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def percentage(self) -> Optional[int]:
|
||||||
|
"""Return the current speed percentage."""
|
||||||
|
return ordered_list_item_to_percentage(ORDERED_NAMED_FAN_SPEEDS, current_speed)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def speed_count(self) -> Optional[int]:
|
||||||
|
"""Return the number of speeds the fan supports."""
|
||||||
|
return len(ORDERED_NAMED_FAN_SPEEDS)
|
||||||
```
|
```
|
||||||
|
|
||||||
If the device has a numeric range of speeds:
|
If the device has a numeric range of speeds:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from homeassistant.util.percentage import ranged_value_to_percentage, percentage_to_ranged_value
|
from homeassistant.util.percentage import int_states_in_range, ranged_value_to_percentage, percentage_to_ranged_value
|
||||||
|
|
||||||
SPEED_RANGE = (1, 255) # off is not included
|
SPEED_RANGE = (1, 255) # off is not included
|
||||||
|
|
||||||
percentage = ranged_value_to_percentage(SPEED_RANGE, 127)
|
percentage = ranged_value_to_percentage(SPEED_RANGE, 127)
|
||||||
|
|
||||||
value_in_range = math.ceil(percentage_to_ranged_value(SPEED_RANGE, 50))
|
value_in_range = math.ceil(percentage_to_ranged_value(SPEED_RANGE, 50))
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def percentage(self) -> Optional[int]:
|
||||||
|
"""Return the current speed percentage."""
|
||||||
|
return ranged_value_to_percentage(SPEED_RANGE, current_speed)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def speed_count(self) -> Optional[int]:
|
||||||
|
"""Return the number of speeds the fan supports."""
|
||||||
|
return int_states_in_range(SPEED_RANGE)
|
||||||
```
|
```
|
||||||
:::
|
:::
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user