mirror of
https://github.com/home-assistant/core.git
synced 2025-11-08 18:39:30 +00:00
Add suggested_unit_of_measurement attribute to sensors (#80638)
* Add suggested_unit_of_measurement attribute to sensors * Lazy calculation of initial entity options * Add type alias for entity options * Small tweak * Add tests * Store suggested_unit_of_measurement in its own option key * Adapt to renaming of IMPERIAL_SYSTEM * Fix rebase mistakes * Apply suggestions from code review Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
This commit is contained in:
@@ -39,85 +39,92 @@ def test_invalid_units():
|
||||
with pytest.raises(ValueError):
|
||||
UnitSystem(
|
||||
SYSTEM_NAME,
|
||||
accumulated_precipitation=LENGTH_MILLIMETERS,
|
||||
length=LENGTH_METERS,
|
||||
length_conversions={},
|
||||
mass=MASS_GRAMS,
|
||||
pressure=PRESSURE_PA,
|
||||
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,
|
||||
wind_speed=SPEED_METERS_PER_SECOND,
|
||||
)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
UnitSystem(
|
||||
SYSTEM_NAME,
|
||||
temperature=TEMP_CELSIUS,
|
||||
accumulated_precipitation=LENGTH_MILLIMETERS,
|
||||
length=INVALID_UNIT,
|
||||
wind_speed=SPEED_METERS_PER_SECOND,
|
||||
volume=VOLUME_LITERS,
|
||||
length_conversions={},
|
||||
mass=MASS_GRAMS,
|
||||
pressure=PRESSURE_PA,
|
||||
accumulated_precipitation=LENGTH_MILLIMETERS,
|
||||
temperature=TEMP_CELSIUS,
|
||||
volume=VOLUME_LITERS,
|
||||
wind_speed=SPEED_METERS_PER_SECOND,
|
||||
)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
UnitSystem(
|
||||
SYSTEM_NAME,
|
||||
temperature=TEMP_CELSIUS,
|
||||
accumulated_precipitation=LENGTH_MILLIMETERS,
|
||||
length=LENGTH_METERS,
|
||||
length_conversions={},
|
||||
mass=MASS_GRAMS,
|
||||
pressure=PRESSURE_PA,
|
||||
temperature=TEMP_CELSIUS,
|
||||
volume=VOLUME_LITERS,
|
||||
wind_speed=INVALID_UNIT,
|
||||
volume=VOLUME_LITERS,
|
||||
mass=MASS_GRAMS,
|
||||
pressure=PRESSURE_PA,
|
||||
accumulated_precipitation=LENGTH_MILLIMETERS,
|
||||
)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
UnitSystem(
|
||||
SYSTEM_NAME,
|
||||
temperature=TEMP_CELSIUS,
|
||||
accumulated_precipitation=LENGTH_MILLIMETERS,
|
||||
length=LENGTH_METERS,
|
||||
wind_speed=SPEED_METERS_PER_SECOND,
|
||||
length_conversions={},
|
||||
mass=MASS_GRAMS,
|
||||
pressure=PRESSURE_PA,
|
||||
temperature=TEMP_CELSIUS,
|
||||
volume=INVALID_UNIT,
|
||||
mass=MASS_GRAMS,
|
||||
pressure=PRESSURE_PA,
|
||||
accumulated_precipitation=LENGTH_MILLIMETERS,
|
||||
wind_speed=SPEED_METERS_PER_SECOND,
|
||||
)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
UnitSystem(
|
||||
SYSTEM_NAME,
|
||||
temperature=TEMP_CELSIUS,
|
||||
accumulated_precipitation=LENGTH_MILLIMETERS,
|
||||
length=LENGTH_METERS,
|
||||
wind_speed=SPEED_METERS_PER_SECOND,
|
||||
volume=VOLUME_LITERS,
|
||||
length_conversions={},
|
||||
mass=INVALID_UNIT,
|
||||
pressure=PRESSURE_PA,
|
||||
accumulated_precipitation=LENGTH_MILLIMETERS,
|
||||
temperature=TEMP_CELSIUS,
|
||||
volume=VOLUME_LITERS,
|
||||
wind_speed=SPEED_METERS_PER_SECOND,
|
||||
)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
UnitSystem(
|
||||
SYSTEM_NAME,
|
||||
temperature=TEMP_CELSIUS,
|
||||
accumulated_precipitation=LENGTH_MILLIMETERS,
|
||||
length=LENGTH_METERS,
|
||||
wind_speed=SPEED_METERS_PER_SECOND,
|
||||
volume=VOLUME_LITERS,
|
||||
length_conversions={},
|
||||
mass=MASS_GRAMS,
|
||||
pressure=INVALID_UNIT,
|
||||
accumulated_precipitation=LENGTH_MILLIMETERS,
|
||||
temperature=TEMP_CELSIUS,
|
||||
volume=VOLUME_LITERS,
|
||||
wind_speed=SPEED_METERS_PER_SECOND,
|
||||
)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
UnitSystem(
|
||||
SYSTEM_NAME,
|
||||
temperature=TEMP_CELSIUS,
|
||||
accumulated_precipitation=INVALID_UNIT,
|
||||
length=LENGTH_METERS,
|
||||
wind_speed=SPEED_METERS_PER_SECOND,
|
||||
volume=VOLUME_LITERS,
|
||||
length_conversions={},
|
||||
mass=MASS_GRAMS,
|
||||
pressure=PRESSURE_PA,
|
||||
accumulated_precipitation=INVALID_UNIT,
|
||||
temperature=TEMP_CELSIUS,
|
||||
volume=VOLUME_LITERS,
|
||||
wind_speed=SPEED_METERS_PER_SECOND,
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user