mirror of
https://github.com/home-assistant/core.git
synced 2026-09-26 01:11:51 -04:00
Cleanup unit conversion (#79197)
* Move UNIT_RATIO to BaseUnitConverter * Make UNIT_CONVERSION private * Remove STATISTIC_UNIT_TO_UNIT_CLASS constant * Cleanup websocket_api * Imrpove valid_units check
This commit is contained in:
@@ -162,6 +162,30 @@ def test_convert_nonnumeric_value(
|
||||
converter.convert("a", from_unit, to_unit)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"converter,from_unit,to_unit,expected",
|
||||
[
|
||||
(DistanceConverter, LENGTH_KILOMETERS, LENGTH_METERS, 1 / 1000),
|
||||
(EnergyConverter, ENERGY_WATT_HOUR, ENERGY_KILO_WATT_HOUR, 1000),
|
||||
(PowerConverter, POWER_WATT, POWER_KILO_WATT, 1000),
|
||||
(PressureConverter, PRESSURE_HPA, PRESSURE_INHG, pytest.approx(33.86389)),
|
||||
(
|
||||
SpeedConverter,
|
||||
SPEED_KILOMETERS_PER_HOUR,
|
||||
SPEED_MILES_PER_HOUR,
|
||||
pytest.approx(1.609343),
|
||||
),
|
||||
(TemperatureConverter, TEMP_CELSIUS, TEMP_FAHRENHEIT, 1 / 1.8),
|
||||
(VolumeConverter, VOLUME_GALLONS, VOLUME_LITERS, pytest.approx(0.264172)),
|
||||
],
|
||||
)
|
||||
def test_get_unit_ratio(
|
||||
converter: type[BaseUnitConverter], from_unit: str, to_unit: str, expected: float
|
||||
) -> None:
|
||||
"""Test unit ratio."""
|
||||
assert converter.get_unit_ratio(from_unit, to_unit) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"value,from_unit,expected,to_unit",
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user