Enforce kwargs in unit system initialisation (#80620)
* Enforce kwargs in unit system initialisation * Fix tests * Sort kwargs in unit_systempull/80870/head
parent
d78c2a31a1
commit
8a1cc05e0c
|
@ -9,15 +9,15 @@ import voluptuous as vol
|
|||
from homeassistant.const import (
|
||||
ACCUMULATED_PRECIPITATION,
|
||||
LENGTH,
|
||||
LENGTH_INCHES,
|
||||
LENGTH_KILOMETERS,
|
||||
LENGTH_MILES,
|
||||
LENGTH_MILLIMETERS,
|
||||
MASS,
|
||||
MASS_GRAMS,
|
||||
MASS_KILOGRAMS,
|
||||
MASS_OUNCES,
|
||||
MASS_POUNDS,
|
||||
PRECIPITATION_INCHES,
|
||||
PRECIPITATION_MILLIMETERS,
|
||||
PRESSURE,
|
||||
PRESSURE_PA,
|
||||
PRESSURE_PSI,
|
||||
|
@ -87,13 +87,14 @@ class UnitSystem:
|
|||
def __init__(
|
||||
self,
|
||||
name: str,
|
||||
temperature: str,
|
||||
*,
|
||||
accumulated_precipitation: str,
|
||||
length: str,
|
||||
wind_speed: str,
|
||||
volume: str,
|
||||
mass: str,
|
||||
pressure: str,
|
||||
accumulated_precipitation: str,
|
||||
temperature: str,
|
||||
volume: str,
|
||||
wind_speed: str,
|
||||
) -> None:
|
||||
"""Initialize the unit system object."""
|
||||
errors: str = ", ".join(
|
||||
|
@ -241,24 +242,24 @@ validate_unit_system = vol.All(
|
|||
|
||||
METRIC_SYSTEM = UnitSystem(
|
||||
_CONF_UNIT_SYSTEM_METRIC,
|
||||
TEMP_CELSIUS,
|
||||
LENGTH_KILOMETERS,
|
||||
SPEED_METERS_PER_SECOND,
|
||||
VOLUME_LITERS,
|
||||
MASS_GRAMS,
|
||||
PRESSURE_PA,
|
||||
LENGTH_MILLIMETERS,
|
||||
accumulated_precipitation=PRECIPITATION_MILLIMETERS,
|
||||
length=LENGTH_KILOMETERS,
|
||||
mass=MASS_GRAMS,
|
||||
pressure=PRESSURE_PA,
|
||||
temperature=TEMP_CELSIUS,
|
||||
volume=VOLUME_LITERS,
|
||||
wind_speed=SPEED_METERS_PER_SECOND,
|
||||
)
|
||||
|
||||
US_CUSTOMARY_SYSTEM = UnitSystem(
|
||||
_CONF_UNIT_SYSTEM_US_CUSTOMARY,
|
||||
TEMP_FAHRENHEIT,
|
||||
LENGTH_MILES,
|
||||
SPEED_MILES_PER_HOUR,
|
||||
VOLUME_GALLONS,
|
||||
MASS_POUNDS,
|
||||
PRESSURE_PSI,
|
||||
LENGTH_INCHES,
|
||||
accumulated_precipitation=PRECIPITATION_INCHES,
|
||||
length=LENGTH_MILES,
|
||||
mass=MASS_POUNDS,
|
||||
pressure=PRESSURE_PSI,
|
||||
temperature=TEMP_FAHRENHEIT,
|
||||
volume=VOLUME_GALLONS,
|
||||
wind_speed=SPEED_MILES_PER_HOUR,
|
||||
)
|
||||
|
||||
IMPERIAL_SYSTEM = US_CUSTOMARY_SYSTEM
|
||||
|
|
|
@ -43,13 +43,13 @@ def _set_up_units(hass):
|
|||
"""Set up the tests."""
|
||||
hass.config.units = UnitSystem(
|
||||
"custom",
|
||||
TEMP_CELSIUS,
|
||||
LENGTH_METERS,
|
||||
SPEED_KILOMETERS_PER_HOUR,
|
||||
VOLUME_LITERS,
|
||||
MASS_GRAMS,
|
||||
PRESSURE_PA,
|
||||
LENGTH_MILLIMETERS,
|
||||
temperature=TEMP_CELSIUS,
|
||||
length=LENGTH_METERS,
|
||||
wind_speed=SPEED_KILOMETERS_PER_HOUR,
|
||||
volume=VOLUME_LITERS,
|
||||
mass=MASS_GRAMS,
|
||||
pressure=PRESSURE_PA,
|
||||
accumulated_precipitation=LENGTH_MILLIMETERS,
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -39,85 +39,85 @@ def test_invalid_units():
|
|||
with pytest.raises(ValueError):
|
||||
UnitSystem(
|
||||
SYSTEM_NAME,
|
||||
INVALID_UNIT,
|
||||
LENGTH_METERS,
|
||||
SPEED_METERS_PER_SECOND,
|
||||
VOLUME_LITERS,
|
||||
MASS_GRAMS,
|
||||
PRESSURE_PA,
|
||||
LENGTH_MILLIMETERS,
|
||||
temperature=INVALID_UNIT,
|
||||
length=LENGTH_METERS,
|
||||
wind_speed=SPEED_METERS_PER_SECOND,
|
||||
volume=VOLUME_LITERS,
|
||||
mass=MASS_GRAMS,
|
||||
pressure=PRESSURE_PA,
|
||||
accumulated_precipitation=LENGTH_MILLIMETERS,
|
||||
)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
UnitSystem(
|
||||
SYSTEM_NAME,
|
||||
TEMP_CELSIUS,
|
||||
INVALID_UNIT,
|
||||
SPEED_METERS_PER_SECOND,
|
||||
VOLUME_LITERS,
|
||||
MASS_GRAMS,
|
||||
PRESSURE_PA,
|
||||
LENGTH_MILLIMETERS,
|
||||
temperature=TEMP_CELSIUS,
|
||||
length=INVALID_UNIT,
|
||||
wind_speed=SPEED_METERS_PER_SECOND,
|
||||
volume=VOLUME_LITERS,
|
||||
mass=MASS_GRAMS,
|
||||
pressure=PRESSURE_PA,
|
||||
accumulated_precipitation=LENGTH_MILLIMETERS,
|
||||
)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
UnitSystem(
|
||||
SYSTEM_NAME,
|
||||
TEMP_CELSIUS,
|
||||
LENGTH_METERS,
|
||||
INVALID_UNIT,
|
||||
VOLUME_LITERS,
|
||||
MASS_GRAMS,
|
||||
PRESSURE_PA,
|
||||
LENGTH_MILLIMETERS,
|
||||
temperature=TEMP_CELSIUS,
|
||||
length=LENGTH_METERS,
|
||||
wind_speed=INVALID_UNIT,
|
||||
volume=VOLUME_LITERS,
|
||||
mass=MASS_GRAMS,
|
||||
pressure=PRESSURE_PA,
|
||||
accumulated_precipitation=LENGTH_MILLIMETERS,
|
||||
)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
UnitSystem(
|
||||
SYSTEM_NAME,
|
||||
TEMP_CELSIUS,
|
||||
LENGTH_METERS,
|
||||
SPEED_METERS_PER_SECOND,
|
||||
INVALID_UNIT,
|
||||
MASS_GRAMS,
|
||||
PRESSURE_PA,
|
||||
LENGTH_MILLIMETERS,
|
||||
temperature=TEMP_CELSIUS,
|
||||
length=LENGTH_METERS,
|
||||
wind_speed=SPEED_METERS_PER_SECOND,
|
||||
volume=INVALID_UNIT,
|
||||
mass=MASS_GRAMS,
|
||||
pressure=PRESSURE_PA,
|
||||
accumulated_precipitation=LENGTH_MILLIMETERS,
|
||||
)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
UnitSystem(
|
||||
SYSTEM_NAME,
|
||||
TEMP_CELSIUS,
|
||||
LENGTH_METERS,
|
||||
SPEED_METERS_PER_SECOND,
|
||||
VOLUME_LITERS,
|
||||
INVALID_UNIT,
|
||||
PRESSURE_PA,
|
||||
LENGTH_MILLIMETERS,
|
||||
temperature=TEMP_CELSIUS,
|
||||
length=LENGTH_METERS,
|
||||
wind_speed=SPEED_METERS_PER_SECOND,
|
||||
volume=VOLUME_LITERS,
|
||||
mass=INVALID_UNIT,
|
||||
pressure=PRESSURE_PA,
|
||||
accumulated_precipitation=LENGTH_MILLIMETERS,
|
||||
)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
UnitSystem(
|
||||
SYSTEM_NAME,
|
||||
TEMP_CELSIUS,
|
||||
LENGTH_METERS,
|
||||
SPEED_METERS_PER_SECOND,
|
||||
VOLUME_LITERS,
|
||||
MASS_GRAMS,
|
||||
INVALID_UNIT,
|
||||
LENGTH_MILLIMETERS,
|
||||
temperature=TEMP_CELSIUS,
|
||||
length=LENGTH_METERS,
|
||||
wind_speed=SPEED_METERS_PER_SECOND,
|
||||
volume=VOLUME_LITERS,
|
||||
mass=MASS_GRAMS,
|
||||
pressure=INVALID_UNIT,
|
||||
accumulated_precipitation=LENGTH_MILLIMETERS,
|
||||
)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
UnitSystem(
|
||||
SYSTEM_NAME,
|
||||
TEMP_CELSIUS,
|
||||
LENGTH_METERS,
|
||||
SPEED_METERS_PER_SECOND,
|
||||
VOLUME_LITERS,
|
||||
MASS_GRAMS,
|
||||
PRESSURE_PA,
|
||||
INVALID_UNIT,
|
||||
temperature=TEMP_CELSIUS,
|
||||
length=LENGTH_METERS,
|
||||
wind_speed=SPEED_METERS_PER_SECOND,
|
||||
volume=VOLUME_LITERS,
|
||||
mass=MASS_GRAMS,
|
||||
pressure=PRESSURE_PA,
|
||||
accumulated_precipitation=INVALID_UNIT,
|
||||
)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue