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