mirror of
https://github.com/home-assistant/developers.home-assistant.git
synced 2025-07-16 13:56:29 +00:00
Document percentage_step and the utility
This commit is contained in:
parent
8a4cb33493
commit
c09fd7c781
@ -17,10 +17,48 @@ 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 |
|
||||||
|
| percentage_step | float | 1 | The supported step size a speed percentage can be increased/decreased |
|
||||||
| 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. |
|
||||||
|
|
||||||
|
|
||||||
|
:::tip Converting speeds
|
||||||
|
|
||||||
|
Home Assistant includes a utility to calculate step sizes.
|
||||||
|
|
||||||
|
If the device has a list of named speeds:
|
||||||
|
|
||||||
|
```python
|
||||||
|
from homeassistant.util.percentage import ordered_list_percentage_step_size
|
||||||
|
|
||||||
|
ORDERED_NAMED_FAN_SPEEDS = ["one", "two", "three", "four", "five", "six"] # off is not included
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def percentage_step(self) -> Optional[float]:
|
||||||
|
"""Return the step size for percentage."""
|
||||||
|
return ordered_list_percentage_step_size(ORDERED_NAMED_FAN_SPEEDS)
|
||||||
|
```
|
||||||
|
|
||||||
|
If the device has a numeric range of speeds:
|
||||||
|
|
||||||
|
```python
|
||||||
|
from homeassistant.util.percentage import range_percentage_step_size
|
||||||
|
|
||||||
|
SPEED_RANGE = (1, 7) # off is not included
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def percentage_step(self) -> Optional[float]:
|
||||||
|
"""Return the step size for percentage."""
|
||||||
|
return range_percentage_step_size(SPEED_RANGE)
|
||||||
|
```
|
||||||
|
|
||||||
|
:::
|
||||||
|
|
||||||
## Deprecated Properties
|
## Deprecated Properties
|
||||||
|
|
||||||
The fan entity model has changed to use percentages in the range from 0 (off) to 100 instead
|
The fan entity model has changed to use percentages in the range from 0 (off) to 100 instead
|
||||||
|
Loading…
x
Reference in New Issue
Block a user