From b645560633f49eea5fa0574ca4e7f18d7c80bf24 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Tue, 6 Jul 2021 13:29:39 +0200 Subject: [PATCH] Minor improvements of util.percentage typing (#52581) --- homeassistant/util/percentage.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/homeassistant/util/percentage.py b/homeassistant/util/percentage.py index 42beeeb5523..260c4f374fe 100644 --- a/homeassistant/util/percentage.py +++ b/homeassistant/util/percentage.py @@ -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"