Update typing 03 (#48015)
This commit is contained in:
parent
6fb2e63e49
commit
fabd73f08b
37 changed files with 417 additions and 379 deletions
|
@ -1,6 +1,7 @@
|
|||
"""Unit system helper class and methods."""
|
||||
from __future__ import annotations
|
||||
|
||||
from numbers import Number
|
||||
from typing import Dict, Optional
|
||||
|
||||
from homeassistant.const import (
|
||||
CONF_UNIT_SYSTEM_IMPERIAL,
|
||||
|
@ -109,7 +110,7 @@ class UnitSystem:
|
|||
|
||||
return temperature_util.convert(temperature, from_unit, self.temperature_unit)
|
||||
|
||||
def length(self, length: Optional[float], from_unit: str) -> float:
|
||||
def length(self, length: float | None, from_unit: str) -> float:
|
||||
"""Convert the given length to this unit system."""
|
||||
if not isinstance(length, Number):
|
||||
raise TypeError(f"{length!s} is not a numeric value.")
|
||||
|
@ -119,7 +120,7 @@ class UnitSystem:
|
|||
length, from_unit, self.length_unit
|
||||
)
|
||||
|
||||
def pressure(self, pressure: Optional[float], from_unit: str) -> float:
|
||||
def pressure(self, pressure: float | None, from_unit: str) -> float:
|
||||
"""Convert the given pressure to this unit system."""
|
||||
if not isinstance(pressure, Number):
|
||||
raise TypeError(f"{pressure!s} is not a numeric value.")
|
||||
|
@ -129,7 +130,7 @@ class UnitSystem:
|
|||
pressure, from_unit, self.pressure_unit
|
||||
)
|
||||
|
||||
def volume(self, volume: Optional[float], from_unit: str) -> float:
|
||||
def volume(self, volume: float | None, from_unit: str) -> float:
|
||||
"""Convert the given volume to this unit system."""
|
||||
if not isinstance(volume, Number):
|
||||
raise TypeError(f"{volume!s} is not a numeric value.")
|
||||
|
@ -137,7 +138,7 @@ class UnitSystem:
|
|||
# type ignore: https://github.com/python/mypy/issues/7207
|
||||
return volume_util.convert(volume, from_unit, self.volume_unit) # type: ignore
|
||||
|
||||
def as_dict(self) -> Dict[str, str]:
|
||||
def as_dict(self) -> dict[str, str]:
|
||||
"""Convert the unit system to a dictionary."""
|
||||
return {
|
||||
LENGTH: self.length_unit,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue