mirror of
https://github.com/home-assistant/core.git
synced 2025-08-03 04:35:11 +02:00
Introduce UnitConverter protocol (#78888)
* Introduce ConversionUtility * Use ConversionUtility in number * Use ConversionUtility in sensor * Use ConversionUtility in sensor recorder * Add normalise to ConversionUtility * Revert changes to recorder.py * Reduce size of PR * Adjust recorder statistics * Rename variable * Rename * Apply suggestion Co-authored-by: Erik Montnemery <erik@montnemery.com> * Apply suggestion Co-authored-by: Erik Montnemery <erik@montnemery.com> * Apply suggestion Co-authored-by: Erik Montnemery <erik@montnemery.com> Co-authored-by: Erik Montnemery <erik@montnemery.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
"""Typing Helpers for Home Assistant."""
|
||||
from collections.abc import Mapping
|
||||
from enum import Enum
|
||||
from typing import Any, Optional, Union
|
||||
from typing import Any, Optional, Protocol, Union
|
||||
|
||||
import homeassistant.core
|
||||
|
||||
@@ -26,6 +26,16 @@ class UndefinedType(Enum):
|
||||
|
||||
UNDEFINED = UndefinedType._singleton # pylint: disable=protected-access
|
||||
|
||||
|
||||
class UnitConverter(Protocol):
|
||||
"""Define the format of a conversion utility."""
|
||||
|
||||
VALID_UNITS: tuple[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
|
||||
|
Reference in New Issue
Block a user