diff --git a/tests/util/test_unit_system.py b/tests/util/test_unit_system.py index fc8da540d3db0f..2331ff084121e3 100644 --- a/tests/util/test_unit_system.py +++ b/tests/util/test_unit_system.py @@ -389,76 +389,58 @@ def test_get_unit_system_invalid(key: str) -> None: @pytest.mark.parametrize( - "unit_system, device_class, original_unit, state_unit", + "device_class, original_unit, state_unit", ( - (METRIC_SYSTEM, SensorDeviceClass.DISTANCE, LENGTH_FEET, LENGTH_METERS), - (METRIC_SYSTEM, SensorDeviceClass.DISTANCE, LENGTH_INCHES, LENGTH_MILLIMETERS), - (METRIC_SYSTEM, SensorDeviceClass.DISTANCE, LENGTH_MILES, LENGTH_KILOMETERS), - (METRIC_SYSTEM, SensorDeviceClass.DISTANCE, LENGTH_YARD, LENGTH_METERS), - (METRIC_SYSTEM, SensorDeviceClass.DISTANCE, LENGTH_KILOMETERS, None), - (METRIC_SYSTEM, SensorDeviceClass.DISTANCE, "very_long", None), + # Test distance conversion + (SensorDeviceClass.DISTANCE, LENGTH_FEET, LENGTH_METERS), + (SensorDeviceClass.DISTANCE, LENGTH_INCHES, LENGTH_MILLIMETERS), + (SensorDeviceClass.DISTANCE, LENGTH_MILES, LENGTH_KILOMETERS), + (SensorDeviceClass.DISTANCE, LENGTH_YARD, LENGTH_METERS), + (SensorDeviceClass.DISTANCE, LENGTH_KILOMETERS, None), + (SensorDeviceClass.DISTANCE, "very_long", None), # Test speed conversion - ( - METRIC_SYSTEM, - SensorDeviceClass.SPEED, - SPEED_FEET_PER_SECOND, - SPEED_KILOMETERS_PER_HOUR, - ), - ( - METRIC_SYSTEM, - SensorDeviceClass.SPEED, - SPEED_MILES_PER_HOUR, - SPEED_KILOMETERS_PER_HOUR, - ), - (METRIC_SYSTEM, SensorDeviceClass.SPEED, SPEED_KILOMETERS_PER_HOUR, None), - (METRIC_SYSTEM, SensorDeviceClass.SPEED, SPEED_KNOTS, None), - (METRIC_SYSTEM, SensorDeviceClass.SPEED, SPEED_METERS_PER_SECOND, None), - (METRIC_SYSTEM, SensorDeviceClass.SPEED, "very_fast", None), - ( - US_CUSTOMARY_SYSTEM, - SensorDeviceClass.DISTANCE, - LENGTH_CENTIMETERS, - LENGTH_INCHES, - ), - ( - US_CUSTOMARY_SYSTEM, - SensorDeviceClass.DISTANCE, - LENGTH_KILOMETERS, - LENGTH_MILES, - ), - (US_CUSTOMARY_SYSTEM, SensorDeviceClass.DISTANCE, LENGTH_METERS, LENGTH_FEET), - ( - US_CUSTOMARY_SYSTEM, - SensorDeviceClass.DISTANCE, - LENGTH_MILLIMETERS, - LENGTH_INCHES, - ), - (US_CUSTOMARY_SYSTEM, SensorDeviceClass.DISTANCE, LENGTH_MILES, None), - (US_CUSTOMARY_SYSTEM, SensorDeviceClass.DISTANCE, "very_long", None), + (SensorDeviceClass.SPEED, SPEED_FEET_PER_SECOND, SPEED_KILOMETERS_PER_HOUR), + (SensorDeviceClass.SPEED, SPEED_MILES_PER_HOUR, SPEED_KILOMETERS_PER_HOUR), + (SensorDeviceClass.SPEED, SPEED_KILOMETERS_PER_HOUR, None), + (SensorDeviceClass.SPEED, SPEED_KNOTS, None), + (SensorDeviceClass.SPEED, SPEED_METERS_PER_SECOND, None), + (SensorDeviceClass.SPEED, "very_fast", None), + ), +) +def test_get_metric_converted_unit_( + device_class: SensorDeviceClass, + original_unit: str, + state_unit: str | None, +) -> None: + """Test unit conversion rules.""" + unit_system = METRIC_SYSTEM + assert unit_system.get_converted_unit(device_class, original_unit) == state_unit + + +@pytest.mark.parametrize( + "device_class, original_unit, state_unit", + ( + # Test distance conversion + (SensorDeviceClass.DISTANCE, LENGTH_CENTIMETERS, LENGTH_INCHES), + (SensorDeviceClass.DISTANCE, LENGTH_KILOMETERS, LENGTH_MILES), + (SensorDeviceClass.DISTANCE, LENGTH_METERS, LENGTH_FEET), + (SensorDeviceClass.DISTANCE, LENGTH_MILLIMETERS, LENGTH_INCHES), + (SensorDeviceClass.DISTANCE, LENGTH_MILES, None), + (SensorDeviceClass.DISTANCE, "very_long", None), # Test speed conversion - ( - US_CUSTOMARY_SYSTEM, - SensorDeviceClass.SPEED, - SPEED_METERS_PER_SECOND, - SPEED_MILES_PER_HOUR, - ), - ( - US_CUSTOMARY_SYSTEM, - SensorDeviceClass.SPEED, - SPEED_KILOMETERS_PER_HOUR, - SPEED_MILES_PER_HOUR, - ), - (US_CUSTOMARY_SYSTEM, SensorDeviceClass.SPEED, SPEED_FEET_PER_SECOND, None), - (US_CUSTOMARY_SYSTEM, SensorDeviceClass.SPEED, SPEED_KNOTS, None), - (US_CUSTOMARY_SYSTEM, SensorDeviceClass.SPEED, SPEED_MILES_PER_HOUR, None), - (US_CUSTOMARY_SYSTEM, SensorDeviceClass.SPEED, "very_fast", None), + (SensorDeviceClass.SPEED, SPEED_METERS_PER_SECOND, SPEED_MILES_PER_HOUR), + (SensorDeviceClass.SPEED, SPEED_KILOMETERS_PER_HOUR, SPEED_MILES_PER_HOUR), + (SensorDeviceClass.SPEED, SPEED_FEET_PER_SECOND, None), + (SensorDeviceClass.SPEED, SPEED_KNOTS, None), + (SensorDeviceClass.SPEED, SPEED_MILES_PER_HOUR, None), + (SensorDeviceClass.SPEED, "very_fast", None), ), ) -def test_get_converted_unit( - unit_system: UnitSystem, +def test_get_us_converted_unit( device_class: SensorDeviceClass, original_unit: str, state_unit: str | None, ) -> None: """Test unit conversion rules.""" + unit_system = US_CUSTOMARY_SYSTEM assert unit_system.get_converted_unit(device_class, original_unit) == state_unit