Add Siemes and Millisiemens as additional units of conductivity and enable conversion between conductivity units (#118728)

This commit is contained in:
dontinelli 2024-06-21 11:10:15 +02:00 committed by GitHub
parent 818750dfd1
commit 0dd5391cd7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 112 additions and 16 deletions

View file

@ -28,6 +28,7 @@ from homeassistant.helpers.typing import UNDEFINED, UndefinedType
from homeassistant.util import dt as dt_util
from homeassistant.util.unit_conversion import (
BaseUnitConverter,
ConductivityConverter,
DataRateConverter,
DistanceConverter,
DurationConverter,
@ -126,6 +127,7 @@ QUERY_STATISTICS_SUMMARY_SUM = (
STATISTIC_UNIT_TO_UNIT_CONVERTER: dict[str | None, type[BaseUnitConverter]] = {
**{unit: ConductivityConverter for unit in ConductivityConverter.VALID_UNITS},
**{unit: DataRateConverter for unit in DataRateConverter.VALID_UNITS},
**{unit: DistanceConverter for unit in DistanceConverter.VALID_UNITS},
**{unit: DurationConverter for unit in DurationConverter.VALID_UNITS},
@ -154,7 +156,7 @@ def mean(values: list[float]) -> float | None:
This is a very simple version that only works
with a non-empty list of floats. The built-in
statistics.mean is more robust but is is almost
statistics.mean is more robust but is almost
an order of magnitude slower.
"""
return sum(values) / len(values)