Convert UnitConverter protocol to a class (#78934)

* Convert UnitConverter protocl to a class

* Remove logic change

* Use TypeVar

* Remove NORMALIZED_UNIT from pressure

* Reduce size of PR

* Reduce some more

* Once more

* Once more

* Remove DEVICE_CLASS
This commit is contained in:
epenet
2022-09-22 14:15:22 +02:00
committed by GitHub
parent 27d1c1f471
commit 6002377d4f
6 changed files with 103 additions and 37 deletions

View File

@@ -1,7 +1,7 @@
"""Typing Helpers for Home Assistant."""
from collections.abc import Mapping
from enum import Enum
from typing import Any, Optional, Protocol, Union
from typing import Any, Optional, Union
import homeassistant.core
@@ -27,16 +27,6 @@ class UndefinedType(Enum):
UNDEFINED = UndefinedType._singleton # pylint: disable=protected-access
class UnitConverter(Protocol):
"""Define the format of a conversion utility."""
VALID_UNITS: tuple[str, ...]
NORMALIZED_UNIT: str
def convert(self, value: float, from_unit: str, to_unit: str) -> float:
"""Convert one unit of measurement to another."""
# The following types should not used and
# are not present in the core code base.
# They are kept in order not to break custom integrations