mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 17:27:52 +00:00
Minor improvements of util.percentage typing (#52581)
This commit is contained in:
parent
94aa292c9b
commit
b645560633
@ -1,8 +1,12 @@
|
||||
"""Percentage util functions."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TypeVar
|
||||
|
||||
def ordered_list_item_to_percentage(ordered_list: list[str], item: str) -> int:
|
||||
T = TypeVar("T")
|
||||
|
||||
|
||||
def ordered_list_item_to_percentage(ordered_list: list[T], item: T) -> int:
|
||||
"""Determine the percentage of an item in an ordered list.
|
||||
|
||||
When using this utility for fan speeds, do not include "off"
|
||||
@ -25,7 +29,7 @@ def ordered_list_item_to_percentage(ordered_list: list[str], item: str) -> int:
|
||||
return (list_position * 100) // list_len
|
||||
|
||||
|
||||
def percentage_to_ordered_list_item(ordered_list: list[str], percentage: int) -> str:
|
||||
def percentage_to_ordered_list_item(ordered_list: list[T], percentage: int) -> T:
|
||||
"""Find the item that most closely matches the percentage in an ordered list.
|
||||
|
||||
When using this utility for fan speeds, do not include "off"
|
||||
|
Loading…
x
Reference in New Issue
Block a user