From e84e5f134ee6ccd04ad098a16c41dd2ed141371c Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 20 Oct 2022 15:42:23 +0200 Subject: [PATCH] Use US_CUSTOMARY_SYSTEM in tests (#80658) * Use US_CUSTOMARY_SYSTEM in tests * Don't update test_unit_system --- tests/components/accuweather/test_sensor.py | 4 +- tests/components/alexa/test_smart_home.py | 4 +- .../bmw_connected_drive/test_sensor.py | 2 +- tests/components/demo/test_init.py | 4 +- tests/components/demo/test_water_heater.py | 4 +- tests/components/gdacs/test_geo_location.py | 4 +- .../generic_thermostat/test_climate.py | 4 +- .../geonetnz_quakes/test_geo_location.py | 4 +- .../geonetnz_volcano/test_sensor.py | 4 +- .../google_travel_time/test_sensor.py | 8 ++- .../here_travel_time/test_config_flow.py | 8 ++- tests/components/mazda/test_sensor.py | 4 +- tests/components/mobile_app/test_sensor.py | 8 +-- tests/components/mysensors/test_sensor.py | 8 ++- tests/components/number/test_init.py | 6 +- tests/components/nws/test_sensor.py | 4 +- tests/components/nws/test_weather.py | 4 +- .../components/recorder/test_websocket_api.py | 58 +++++++++++++----- tests/components/sensor/test_init.py | 6 +- tests/components/sensor/test_recorder.py | 60 +++++++++++-------- tests/components/subaru/test_sensor.py | 4 +- tests/components/tomorrowio/test_sensor.py | 4 +- tests/components/weather/test_init.py | 24 ++++---- 23 files changed, 147 insertions(+), 93 deletions(-) diff --git a/tests/components/accuweather/test_sensor.py b/tests/components/accuweather/test_sensor.py index ababaea5443..aba5c4437ed 100644 --- a/tests/components/accuweather/test_sensor.py +++ b/tests/components/accuweather/test_sensor.py @@ -30,7 +30,7 @@ from homeassistant.const import ( from homeassistant.helpers import entity_registry as er from homeassistant.setup import async_setup_component from homeassistant.util.dt import utcnow -from homeassistant.util.unit_system import IMPERIAL_SYSTEM +from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM from . import init_integration @@ -704,7 +704,7 @@ async def test_manual_update_entity(hass): async def test_sensor_imperial_units(hass): """Test states of the sensor without forecast.""" - hass.config.units = IMPERIAL_SYSTEM + hass.config.units = US_CUSTOMARY_SYSTEM await init_integration(hass) state = hass.states.get("sensor.home_cloud_ceiling") diff --git a/tests/components/alexa/test_smart_home.py b/tests/components/alexa/test_smart_home.py index 9d329e76c45..e2ae8741f20 100644 --- a/tests/components/alexa/test_smart_home.py +++ b/tests/components/alexa/test_smart_home.py @@ -30,7 +30,7 @@ from homeassistant.const import STATE_UNKNOWN, TEMP_FAHRENHEIT from homeassistant.core import Context from homeassistant.helpers import entityfilter from homeassistant.setup import async_setup_component -from homeassistant.util.unit_system import IMPERIAL_SYSTEM +from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM from .test_common import ( MockConfig, @@ -2020,7 +2020,7 @@ async def test_unknown_sensor(hass): async def test_thermostat(hass): """Test thermostat discovery.""" - hass.config.units = IMPERIAL_SYSTEM + hass.config.units = US_CUSTOMARY_SYSTEM device = ( "climate.test_thermostat", "cool", diff --git a/tests/components/bmw_connected_drive/test_sensor.py b/tests/components/bmw_connected_drive/test_sensor.py index 90b3f725a6d..f1b0011656f 100644 --- a/tests/components/bmw_connected_drive/test_sensor.py +++ b/tests/components/bmw_connected_drive/test_sensor.py @@ -3,8 +3,8 @@ import pytest from homeassistant.core import HomeAssistant from homeassistant.util.unit_system import ( - IMPERIAL_SYSTEM as IMPERIAL, METRIC_SYSTEM as METRIC, + US_CUSTOMARY_SYSTEM as IMPERIAL, UnitSystem, ) diff --git a/tests/components/demo/test_init.py b/tests/components/demo/test_init.py index 1bec552a55f..c1b9d4c436e 100644 --- a/tests/components/demo/test_init.py +++ b/tests/components/demo/test_init.py @@ -17,7 +17,7 @@ from homeassistant.components.repairs import DOMAIN as REPAIRS_DOMAIN from homeassistant.helpers.json import JSONEncoder from homeassistant.setup import async_setup_component import homeassistant.util.dt as dt_util -from homeassistant.util.unit_system import IMPERIAL_SYSTEM +from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM from tests.components.recorder.common import async_wait_recording_done @@ -84,7 +84,7 @@ async def test_demo_statistics(recorder_mock, mock_history, hass): async def test_demo_statistics_growth(recorder_mock, mock_history, hass): """Test that the demo sum statistics adds to the previous state.""" - hass.config.units = IMPERIAL_SYSTEM + hass.config.units = US_CUSTOMARY_SYSTEM now = dt_util.now() last_week = now - datetime.timedelta(days=7) diff --git a/tests/components/demo/test_water_heater.py b/tests/components/demo/test_water_heater.py index a6b4d999ddb..75103fca920 100644 --- a/tests/components/demo/test_water_heater.py +++ b/tests/components/demo/test_water_heater.py @@ -4,7 +4,7 @@ import voluptuous as vol from homeassistant.components import water_heater from homeassistant.setup import async_setup_component -from homeassistant.util.unit_system import IMPERIAL_SYSTEM +from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM from tests.components.water_heater import common @@ -15,7 +15,7 @@ ENTITY_WATER_HEATER_CELSIUS = "water_heater.demo_water_heater_celsius" @pytest.fixture(autouse=True) async def setup_comp(hass): """Set up demo component.""" - hass.config.units = IMPERIAL_SYSTEM + hass.config.units = US_CUSTOMARY_SYSTEM assert await async_setup_component( hass, water_heater.DOMAIN, {"water_heater": {"platform": "demo"}} ) diff --git a/tests/components/gdacs/test_geo_location.py b/tests/components/gdacs/test_geo_location.py index d55141ebe56..83b9efde1e8 100644 --- a/tests/components/gdacs/test_geo_location.py +++ b/tests/components/gdacs/test_geo_location.py @@ -34,7 +34,7 @@ from homeassistant.const import ( from homeassistant.helpers import entity_registry as er from homeassistant.setup import async_setup_component import homeassistant.util.dt as dt_util -from homeassistant.util.unit_system import IMPERIAL_SYSTEM +from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM from . import _generate_mock_feed_entry @@ -208,7 +208,7 @@ async def test_setup(hass): async def test_setup_imperial(hass): """Test the setup of the integration using imperial unit system.""" - hass.config.units = IMPERIAL_SYSTEM + hass.config.units = US_CUSTOMARY_SYSTEM # Set up some mock feed entries for this test. mock_entry_1 = _generate_mock_feed_entry( "1234", diff --git a/tests/components/generic_thermostat/test_climate.py b/tests/components/generic_thermostat/test_climate.py index f6a8795a29d..52714ab15a2 100644 --- a/tests/components/generic_thermostat/test_climate.py +++ b/tests/components/generic_thermostat/test_climate.py @@ -37,7 +37,7 @@ from homeassistant.core import DOMAIN as HASS_DOMAIN, CoreState, State, callback from homeassistant.helpers import entity_registry as er from homeassistant.setup import async_setup_component from homeassistant.util import dt as dt_util -from homeassistant.util.unit_system import IMPERIAL_SYSTEM, METRIC_SYSTEM +from homeassistant.util.unit_system import METRIC_SYSTEM, US_CUSTOMARY_SYSTEM from tests.common import ( assert_setup_component, @@ -1201,7 +1201,7 @@ async def setup_comp_9(hass): async def test_precision(hass, setup_comp_9): """Test that setting precision to tenths works as intended.""" - hass.config.units = IMPERIAL_SYSTEM + hass.config.units = US_CUSTOMARY_SYSTEM await common.async_set_temperature(hass, 23.27) state = hass.states.get(ENTITY) assert state.attributes.get("temperature") == 23.3 diff --git a/tests/components/geonetnz_quakes/test_geo_location.py b/tests/components/geonetnz_quakes/test_geo_location.py index 130964b4eeb..327829d3d4b 100644 --- a/tests/components/geonetnz_quakes/test_geo_location.py +++ b/tests/components/geonetnz_quakes/test_geo_location.py @@ -28,7 +28,7 @@ from homeassistant.const import ( from homeassistant.helpers import entity_registry as er from homeassistant.setup import async_setup_component import homeassistant.util.dt as dt_util -from homeassistant.util.unit_system import IMPERIAL_SYSTEM +from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM from . import _generate_mock_feed_entry @@ -171,7 +171,7 @@ async def test_setup(hass): async def test_setup_imperial(hass): """Test the setup of the integration using imperial unit system.""" - hass.config.units = IMPERIAL_SYSTEM + hass.config.units = US_CUSTOMARY_SYSTEM # Set up some mock feed entries for this test. mock_entry_1 = _generate_mock_feed_entry("1234", "Title 1", 15.5, (38.0, -3.0)) diff --git a/tests/components/geonetnz_volcano/test_sensor.py b/tests/components/geonetnz_volcano/test_sensor.py index dbb6834c596..9b53cb9cc9b 100644 --- a/tests/components/geonetnz_volcano/test_sensor.py +++ b/tests/components/geonetnz_volcano/test_sensor.py @@ -23,7 +23,7 @@ from homeassistant.const import ( ) from homeassistant.setup import async_setup_component import homeassistant.util.dt as dt_util -from homeassistant.util.unit_system import IMPERIAL_SYSTEM +from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM from . import _generate_mock_feed_entry @@ -150,7 +150,7 @@ async def test_setup(hass): async def test_setup_imperial(hass): """Test the setup of the integration using imperial unit system.""" - hass.config.units = IMPERIAL_SYSTEM + hass.config.units = US_CUSTOMARY_SYSTEM # Set up some mock feed entries for this test. mock_entry_1 = _generate_mock_feed_entry("1234", "Title 1", 1, 15.5, (38.0, -3.0)) diff --git a/tests/components/google_travel_time/test_sensor.py b/tests/components/google_travel_time/test_sensor.py index 73bea673880..8d560d895f2 100644 --- a/tests/components/google_travel_time/test_sensor.py +++ b/tests/components/google_travel_time/test_sensor.py @@ -12,7 +12,11 @@ from homeassistant.components.google_travel_time.const import ( ) from homeassistant.const import CONF_UNIT_SYSTEM_IMPERIAL, CONF_UNIT_SYSTEM_METRIC from homeassistant.core import HomeAssistant -from homeassistant.util.unit_system import IMPERIAL_SYSTEM, METRIC_SYSTEM, UnitSystem +from homeassistant.util.unit_system import ( + METRIC_SYSTEM, + US_CUSTOMARY_SYSTEM, + UnitSystem, +) from .const import MOCK_CONFIG @@ -227,7 +231,7 @@ async def test_sensor_deprecation_warning(hass, caplog): "unit_system, expected_unit_option", [ (METRIC_SYSTEM, CONF_UNIT_SYSTEM_METRIC), - (IMPERIAL_SYSTEM, CONF_UNIT_SYSTEM_IMPERIAL), + (US_CUSTOMARY_SYSTEM, CONF_UNIT_SYSTEM_IMPERIAL), ], ) async def test_sensor_unit_system( diff --git a/tests/components/here_travel_time/test_config_flow.py b/tests/components/here_travel_time/test_config_flow.py index 1777258c6e9..120ffd828bc 100644 --- a/tests/components/here_travel_time/test_config_flow.py +++ b/tests/components/here_travel_time/test_config_flow.py @@ -31,7 +31,11 @@ from homeassistant.const import ( CONF_UNIT_SYSTEM_METRIC, ) from homeassistant.core import HomeAssistant -from homeassistant.util.unit_system import IMPERIAL_SYSTEM, METRIC_SYSTEM, UnitSystem +from homeassistant.util.unit_system import ( + METRIC_SYSTEM, + US_CUSTOMARY_SYSTEM, + UnitSystem, +) from .const import ( API_KEY, @@ -232,7 +236,7 @@ async def test_step_destination_coordinates( "unit_system, expected_unit_option", [ (METRIC_SYSTEM, CONF_UNIT_SYSTEM_METRIC), - (IMPERIAL_SYSTEM, CONF_UNIT_SYSTEM_IMPERIAL), + (US_CUSTOMARY_SYSTEM, CONF_UNIT_SYSTEM_IMPERIAL), ], ) async def test_step_destination_entity( diff --git a/tests/components/mazda/test_sensor.py b/tests/components/mazda/test_sensor.py index 2284101fa84..4484e6b7783 100644 --- a/tests/components/mazda/test_sensor.py +++ b/tests/components/mazda/test_sensor.py @@ -16,7 +16,7 @@ from homeassistant.const import ( PRESSURE_PSI, ) from homeassistant.helpers import entity_registry as er -from homeassistant.util.unit_system import IMPERIAL_SYSTEM +from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM from . import init_integration @@ -132,7 +132,7 @@ async def test_sensors(hass): async def test_sensors_imperial_units(hass): """Test that the sensors work properly with imperial units.""" - hass.config.units = IMPERIAL_SYSTEM + hass.config.units = US_CUSTOMARY_SYSTEM await init_integration(hass) diff --git a/tests/components/mobile_app/test_sensor.py b/tests/components/mobile_app/test_sensor.py index 930fb522c4c..13e11db3eff 100644 --- a/tests/components/mobile_app/test_sensor.py +++ b/tests/components/mobile_app/test_sensor.py @@ -13,14 +13,14 @@ from homeassistant.const import ( TEMP_FAHRENHEIT, ) from homeassistant.helpers import device_registry as dr, entity_registry as er -from homeassistant.util.unit_system import IMPERIAL_SYSTEM, METRIC_SYSTEM +from homeassistant.util.unit_system import METRIC_SYSTEM, US_CUSTOMARY_SYSTEM @pytest.mark.parametrize( "unit_system, state_unit, state1, state2", ( (METRIC_SYSTEM, TEMP_CELSIUS, "100", "123"), - (IMPERIAL_SYSTEM, TEMP_FAHRENHEIT, "212", "253"), + (US_CUSTOMARY_SYSTEM, TEMP_FAHRENHEIT, "212", "253"), ), ) async def test_sensor( @@ -124,9 +124,9 @@ async def test_sensor( "unique_id, unit_system, state_unit, state1, state2", ( ("battery_temperature", METRIC_SYSTEM, TEMP_CELSIUS, "100", "123"), - ("battery_temperature", IMPERIAL_SYSTEM, TEMP_FAHRENHEIT, "212", "253"), + ("battery_temperature", US_CUSTOMARY_SYSTEM, TEMP_FAHRENHEIT, "212", "253"), # The unique_id doesn't match that of the mobile app's battery temperature sensor - ("battery_temp", IMPERIAL_SYSTEM, TEMP_FAHRENHEIT, "212", "123"), + ("battery_temp", US_CUSTOMARY_SYSTEM, TEMP_FAHRENHEIT, "212", "123"), ), ) async def test_sensor_migration( diff --git a/tests/components/mysensors/test_sensor.py b/tests/components/mysensors/test_sensor.py index 58258682d5b..3a1b7b56872 100644 --- a/tests/components/mysensors/test_sensor.py +++ b/tests/components/mysensors/test_sensor.py @@ -21,7 +21,11 @@ from homeassistant.const import ( TEMP_FAHRENHEIT, ) from homeassistant.core import HomeAssistant -from homeassistant.util.unit_system import IMPERIAL_SYSTEM, METRIC_SYSTEM, UnitSystem +from homeassistant.util.unit_system import ( + METRIC_SYSTEM, + US_CUSTOMARY_SYSTEM, + UnitSystem, +) from tests.common import MockConfigEntry @@ -124,7 +128,7 @@ async def test_distance_sensor( @pytest.mark.parametrize( "unit_system, unit", - [(METRIC_SYSTEM, TEMP_CELSIUS), (IMPERIAL_SYSTEM, TEMP_FAHRENHEIT)], + [(METRIC_SYSTEM, TEMP_CELSIUS), (US_CUSTOMARY_SYSTEM, TEMP_FAHRENHEIT)], ) async def test_temperature_sensor( hass: HomeAssistant, diff --git a/tests/components/number/test_init.py b/tests/components/number/test_init.py index 8d7f8a91ae8..98b30616952 100644 --- a/tests/components/number/test_init.py +++ b/tests/components/number/test_init.py @@ -25,7 +25,7 @@ from homeassistant.core import HomeAssistant, State from homeassistant.helpers import entity_registry as er from homeassistant.helpers.restore_state import STORAGE_KEY as RESTORE_STATE_KEY from homeassistant.setup import async_setup_component -from homeassistant.util.unit_system import IMPERIAL_SYSTEM, METRIC_SYSTEM +from homeassistant.util.unit_system import METRIC_SYSTEM, US_CUSTOMARY_SYSTEM from tests.common import mock_restore_cache_with_extra_data @@ -435,7 +435,7 @@ async def test_deprecated_methods( "native_min_value, state_min_value, native_step, state_step", [ ( - IMPERIAL_SYSTEM, + US_CUSTOMARY_SYSTEM, TEMP_FAHRENHEIT, TEMP_FAHRENHEIT, 100, @@ -450,7 +450,7 @@ async def test_deprecated_methods( 3, ), ( - IMPERIAL_SYSTEM, + US_CUSTOMARY_SYSTEM, TEMP_CELSIUS, TEMP_FAHRENHEIT, 38, diff --git a/tests/components/nws/test_sensor.py b/tests/components/nws/test_sensor.py index 78d39575522..9597618ccc8 100644 --- a/tests/components/nws/test_sensor.py +++ b/tests/components/nws/test_sensor.py @@ -6,7 +6,7 @@ from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN from homeassistant.const import ATTR_ATTRIBUTION, STATE_UNKNOWN from homeassistant.helpers import entity_registry as er from homeassistant.util import slugify -from homeassistant.util.unit_system import IMPERIAL_SYSTEM, METRIC_SYSTEM +from homeassistant.util.unit_system import METRIC_SYSTEM, US_CUSTOMARY_SYSTEM from .const import ( EXPECTED_FORECAST_IMPERIAL, @@ -24,7 +24,7 @@ from tests.common import MockConfigEntry "units,result_observation,result_forecast", [ ( - IMPERIAL_SYSTEM, + US_CUSTOMARY_SYSTEM, SENSOR_EXPECTED_OBSERVATION_IMPERIAL, EXPECTED_FORECAST_IMPERIAL, ), diff --git a/tests/components/nws/test_weather.py b/tests/components/nws/test_weather.py index 3f3e9a649f3..b3a9a4bc9f1 100644 --- a/tests/components/nws/test_weather.py +++ b/tests/components/nws/test_weather.py @@ -15,7 +15,7 @@ from homeassistant.const import STATE_UNAVAILABLE, STATE_UNKNOWN from homeassistant.helpers import entity_registry as er from homeassistant.setup import async_setup_component import homeassistant.util.dt as dt_util -from homeassistant.util.unit_system import IMPERIAL_SYSTEM, METRIC_SYSTEM +from homeassistant.util.unit_system import METRIC_SYSTEM, US_CUSTOMARY_SYSTEM from .const import ( EXPECTED_FORECAST_IMPERIAL, @@ -34,7 +34,7 @@ from tests.common import MockConfigEntry, async_fire_time_changed "units,result_observation,result_forecast", [ ( - IMPERIAL_SYSTEM, + US_CUSTOMARY_SYSTEM, WEATHER_EXPECTED_OBSERVATION_IMPERIAL, EXPECTED_FORECAST_IMPERIAL, ), diff --git a/tests/components/recorder/test_websocket_api.py b/tests/components/recorder/test_websocket_api.py index eeffc7ea7dd..58cf0e5c663 100644 --- a/tests/components/recorder/test_websocket_api.py +++ b/tests/components/recorder/test_websocket_api.py @@ -19,7 +19,7 @@ from homeassistant.components.recorder.statistics import ( from homeassistant.helpers import recorder as recorder_helper from homeassistant.setup import async_setup_component import homeassistant.util.dt as dt_util -from homeassistant.util.unit_system import IMPERIAL_SYSTEM, METRIC_SYSTEM +from homeassistant.util.unit_system import METRIC_SYSTEM, US_CUSTOMARY_SYSTEM from .common import ( async_recorder_block_till_done, @@ -126,7 +126,7 @@ async def test_statistics_during_period(recorder_mock, hass, hass_ws_client): """Test statistics_during_period.""" now = dt_util.utcnow() - hass.config.units = IMPERIAL_SYSTEM + hass.config.units = US_CUSTOMARY_SYSTEM await async_setup_component(hass, "sensor", {}) await async_recorder_block_till_done(hass) hass.states.async_set("sensor.test", 10, attributes=POWER_SENSOR_KW_ATTRIBUTES) @@ -431,7 +431,7 @@ async def test_statistics_during_period_in_the_past( hass.config.set_time_zone("UTC") now = dt_util.utcnow().replace() - hass.config.units = IMPERIAL_SYSTEM + hass.config.units = US_CUSTOMARY_SYSTEM await async_setup_component(hass, "sensor", {}) await async_recorder_block_till_done(hass) @@ -589,27 +589,57 @@ async def test_statistics_during_period_bad_end_time( @pytest.mark.parametrize( "units, attributes, display_unit, statistics_unit, unit_class", [ - (IMPERIAL_SYSTEM, DISTANCE_SENSOR_M_ATTRIBUTES, "m", "m", "distance"), + (US_CUSTOMARY_SYSTEM, DISTANCE_SENSOR_M_ATTRIBUTES, "m", "m", "distance"), (METRIC_SYSTEM, DISTANCE_SENSOR_M_ATTRIBUTES, "m", "m", "distance"), - (IMPERIAL_SYSTEM, DISTANCE_SENSOR_FT_ATTRIBUTES, "ft", "ft", "distance"), + ( + US_CUSTOMARY_SYSTEM, + DISTANCE_SENSOR_FT_ATTRIBUTES, + "ft", + "ft", + "distance", + ), (METRIC_SYSTEM, DISTANCE_SENSOR_FT_ATTRIBUTES, "ft", "ft", "distance"), - (IMPERIAL_SYSTEM, ENERGY_SENSOR_WH_ATTRIBUTES, "Wh", "Wh", "energy"), + (US_CUSTOMARY_SYSTEM, ENERGY_SENSOR_WH_ATTRIBUTES, "Wh", "Wh", "energy"), (METRIC_SYSTEM, ENERGY_SENSOR_WH_ATTRIBUTES, "Wh", "Wh", "energy"), - (IMPERIAL_SYSTEM, GAS_SENSOR_FT3_ATTRIBUTES, "ft³", "ft³", "volume"), + (US_CUSTOMARY_SYSTEM, GAS_SENSOR_FT3_ATTRIBUTES, "ft³", "ft³", "volume"), (METRIC_SYSTEM, GAS_SENSOR_FT3_ATTRIBUTES, "ft³", "ft³", "volume"), - (IMPERIAL_SYSTEM, POWER_SENSOR_KW_ATTRIBUTES, "kW", "kW", "power"), + (US_CUSTOMARY_SYSTEM, POWER_SENSOR_KW_ATTRIBUTES, "kW", "kW", "power"), (METRIC_SYSTEM, POWER_SENSOR_KW_ATTRIBUTES, "kW", "kW", "power"), - (IMPERIAL_SYSTEM, PRESSURE_SENSOR_HPA_ATTRIBUTES, "hPa", "hPa", "pressure"), + ( + US_CUSTOMARY_SYSTEM, + PRESSURE_SENSOR_HPA_ATTRIBUTES, + "hPa", + "hPa", + "pressure", + ), (METRIC_SYSTEM, PRESSURE_SENSOR_HPA_ATTRIBUTES, "hPa", "hPa", "pressure"), - (IMPERIAL_SYSTEM, SPEED_SENSOR_KPH_ATTRIBUTES, "km/h", "km/h", "speed"), + (US_CUSTOMARY_SYSTEM, SPEED_SENSOR_KPH_ATTRIBUTES, "km/h", "km/h", "speed"), (METRIC_SYSTEM, SPEED_SENSOR_KPH_ATTRIBUTES, "km/h", "km/h", "speed"), - (IMPERIAL_SYSTEM, TEMPERATURE_SENSOR_C_ATTRIBUTES, "°C", "°C", "temperature"), + ( + US_CUSTOMARY_SYSTEM, + TEMPERATURE_SENSOR_C_ATTRIBUTES, + "°C", + "°C", + "temperature", + ), (METRIC_SYSTEM, TEMPERATURE_SENSOR_C_ATTRIBUTES, "°C", "°C", "temperature"), - (IMPERIAL_SYSTEM, TEMPERATURE_SENSOR_F_ATTRIBUTES, "°F", "°F", "temperature"), + ( + US_CUSTOMARY_SYSTEM, + TEMPERATURE_SENSOR_F_ATTRIBUTES, + "°F", + "°F", + "temperature", + ), (METRIC_SYSTEM, TEMPERATURE_SENSOR_F_ATTRIBUTES, "°F", "°F", "temperature"), - (IMPERIAL_SYSTEM, VOLUME_SENSOR_FT3_ATTRIBUTES, "ft³", "ft³", "volume"), + (US_CUSTOMARY_SYSTEM, VOLUME_SENSOR_FT3_ATTRIBUTES, "ft³", "ft³", "volume"), (METRIC_SYSTEM, VOLUME_SENSOR_FT3_ATTRIBUTES, "ft³", "ft³", "volume"), - (IMPERIAL_SYSTEM, VOLUME_SENSOR_FT3_ATTRIBUTES_TOTAL, "ft³", "ft³", "volume"), + ( + US_CUSTOMARY_SYSTEM, + VOLUME_SENSOR_FT3_ATTRIBUTES_TOTAL, + "ft³", + "ft³", + "volume", + ), (METRIC_SYSTEM, VOLUME_SENSOR_FT3_ATTRIBUTES_TOTAL, "ft³", "ft³", "volume"), ], ) diff --git a/tests/components/sensor/test_init.py b/tests/components/sensor/test_init.py index a9ea9ce0fbe..0fe60ef98c7 100644 --- a/tests/components/sensor/test_init.py +++ b/tests/components/sensor/test_init.py @@ -35,7 +35,7 @@ from homeassistant.helpers import entity_registry as er from homeassistant.helpers.restore_state import STORAGE_KEY as RESTORE_STATE_KEY from homeassistant.setup import async_setup_component from homeassistant.util import dt as dt_util -from homeassistant.util.unit_system import IMPERIAL_SYSTEM, METRIC_SYSTEM +from homeassistant.util.unit_system import METRIC_SYSTEM, US_CUSTOMARY_SYSTEM from tests.common import mock_restore_cache_with_extra_data @@ -43,8 +43,8 @@ from tests.common import mock_restore_cache_with_extra_data @pytest.mark.parametrize( "unit_system,native_unit,state_unit,native_value,state_value", [ - (IMPERIAL_SYSTEM, TEMP_FAHRENHEIT, TEMP_FAHRENHEIT, 100, 100), - (IMPERIAL_SYSTEM, TEMP_CELSIUS, TEMP_FAHRENHEIT, 38, 100), + (US_CUSTOMARY_SYSTEM, TEMP_FAHRENHEIT, TEMP_FAHRENHEIT, 100, 100), + (US_CUSTOMARY_SYSTEM, TEMP_CELSIUS, TEMP_FAHRENHEIT, 38, 100), (METRIC_SYSTEM, TEMP_FAHRENHEIT, TEMP_CELSIUS, 100, 38), (METRIC_SYSTEM, TEMP_CELSIUS, TEMP_CELSIUS, 38, 38), ], diff --git a/tests/components/sensor/test_recorder.py b/tests/components/sensor/test_recorder.py index a49882a0eb3..e04d41f4c2a 100644 --- a/tests/components/sensor/test_recorder.py +++ b/tests/components/sensor/test_recorder.py @@ -26,7 +26,7 @@ from homeassistant.components.recorder.util import get_instance, session_scope from homeassistant.const import STATE_UNAVAILABLE from homeassistant.setup import async_setup_component, setup_component import homeassistant.util.dt as dt_util -from homeassistant.util.unit_system import IMPERIAL_SYSTEM, METRIC_SYSTEM +from homeassistant.util.unit_system import METRIC_SYSTEM, US_CUSTOMARY_SYSTEM from tests.components.recorder.common import ( async_recorder_block_till_done, @@ -403,18 +403,18 @@ def test_compile_hourly_statistics_wrong_unit(hass_recorder, caplog, attributes) @pytest.mark.parametrize( "units, device_class, state_unit, display_unit, statistics_unit, unit_class, factor", [ - (IMPERIAL_SYSTEM, "distance", "m", "m", "m", "distance", 1), - (IMPERIAL_SYSTEM, "distance", "mi", "mi", "mi", "distance", 1), - (IMPERIAL_SYSTEM, "energy", "kWh", "kWh", "kWh", "energy", 1), - (IMPERIAL_SYSTEM, "energy", "Wh", "Wh", "Wh", "energy", 1), - (IMPERIAL_SYSTEM, "gas", "m³", "m³", "m³", "volume", 1), - (IMPERIAL_SYSTEM, "gas", "ft³", "ft³", "ft³", "volume", 1), - (IMPERIAL_SYSTEM, "monetary", "EUR", "EUR", "EUR", None, 1), - (IMPERIAL_SYSTEM, "monetary", "SEK", "SEK", "SEK", None, 1), - (IMPERIAL_SYSTEM, "volume", "m³", "m³", "m³", "volume", 1), - (IMPERIAL_SYSTEM, "volume", "ft³", "ft³", "ft³", "volume", 1), - (IMPERIAL_SYSTEM, "weight", "g", "g", "g", "mass", 1), - (IMPERIAL_SYSTEM, "weight", "oz", "oz", "oz", "mass", 1), + (US_CUSTOMARY_SYSTEM, "distance", "m", "m", "m", "distance", 1), + (US_CUSTOMARY_SYSTEM, "distance", "mi", "mi", "mi", "distance", 1), + (US_CUSTOMARY_SYSTEM, "energy", "kWh", "kWh", "kWh", "energy", 1), + (US_CUSTOMARY_SYSTEM, "energy", "Wh", "Wh", "Wh", "energy", 1), + (US_CUSTOMARY_SYSTEM, "gas", "m³", "m³", "m³", "volume", 1), + (US_CUSTOMARY_SYSTEM, "gas", "ft³", "ft³", "ft³", "volume", 1), + (US_CUSTOMARY_SYSTEM, "monetary", "EUR", "EUR", "EUR", None, 1), + (US_CUSTOMARY_SYSTEM, "monetary", "SEK", "SEK", "SEK", None, 1), + (US_CUSTOMARY_SYSTEM, "volume", "m³", "m³", "m³", "volume", 1), + (US_CUSTOMARY_SYSTEM, "volume", "ft³", "ft³", "ft³", "volume", 1), + (US_CUSTOMARY_SYSTEM, "weight", "g", "g", "g", "mass", 1), + (US_CUSTOMARY_SYSTEM, "weight", "oz", "oz", "oz", "mass", 1), (METRIC_SYSTEM, "distance", "m", "m", "m", "distance", 1), (METRIC_SYSTEM, "distance", "mi", "mi", "mi", "distance", 1), (METRIC_SYSTEM, "energy", "kWh", "kWh", "kWh", "energy", 1), @@ -3307,12 +3307,18 @@ def record_states(hass, zero, entity_id, attributes, seq=None): @pytest.mark.parametrize( "units, attributes, unit, unit2, supported_unit", [ - (IMPERIAL_SYSTEM, POWER_SENSOR_ATTRIBUTES, "W", "kW", "W, kW"), + (US_CUSTOMARY_SYSTEM, POWER_SENSOR_ATTRIBUTES, "W", "kW", "W, kW"), (METRIC_SYSTEM, POWER_SENSOR_ATTRIBUTES, "W", "kW", "W, kW"), - (IMPERIAL_SYSTEM, TEMPERATURE_SENSOR_ATTRIBUTES, "°F", "K", "K, °C, °F"), + ( + US_CUSTOMARY_SYSTEM, + TEMPERATURE_SENSOR_ATTRIBUTES, + "°F", + "K", + "K, °C, °F", + ), (METRIC_SYSTEM, TEMPERATURE_SENSOR_ATTRIBUTES, "°C", "K", "K, °C, °F"), ( - IMPERIAL_SYSTEM, + US_CUSTOMARY_SYSTEM, PRESSURE_SENSOR_ATTRIBUTES, "psi", "bar", @@ -3439,7 +3445,7 @@ async def test_validate_unit_change_convertible( @pytest.mark.parametrize( "units, attributes", [ - (IMPERIAL_SYSTEM, POWER_SENSOR_ATTRIBUTES), + (US_CUSTOMARY_SYSTEM, POWER_SENSOR_ATTRIBUTES), ], ) async def test_validate_statistics_unit_ignore_device_class( @@ -3493,12 +3499,18 @@ async def test_validate_statistics_unit_ignore_device_class( @pytest.mark.parametrize( "units, attributes, unit, unit2, supported_unit", [ - (IMPERIAL_SYSTEM, POWER_SENSOR_ATTRIBUTES, "W", "kW", "W, kW"), + (US_CUSTOMARY_SYSTEM, POWER_SENSOR_ATTRIBUTES, "W", "kW", "W, kW"), (METRIC_SYSTEM, POWER_SENSOR_ATTRIBUTES, "W", "kW", "W, kW"), - (IMPERIAL_SYSTEM, TEMPERATURE_SENSOR_ATTRIBUTES, "°F", "K", "K, °C, °F"), + ( + US_CUSTOMARY_SYSTEM, + TEMPERATURE_SENSOR_ATTRIBUTES, + "°F", + "K", + "K, °C, °F", + ), (METRIC_SYSTEM, TEMPERATURE_SENSOR_ATTRIBUTES, "°C", "K", "K, °C, °F"), ( - IMPERIAL_SYSTEM, + US_CUSTOMARY_SYSTEM, PRESSURE_SENSOR_ATTRIBUTES, "psi", "bar", @@ -3625,7 +3637,7 @@ async def test_validate_statistics_unit_change_no_device_class( @pytest.mark.parametrize( "units, attributes, unit", [ - (IMPERIAL_SYSTEM, POWER_SENSOR_ATTRIBUTES, "W"), + (US_CUSTOMARY_SYSTEM, POWER_SENSOR_ATTRIBUTES, "W"), ], ) async def test_validate_statistics_unsupported_state_class( @@ -3689,7 +3701,7 @@ async def test_validate_statistics_unsupported_state_class( @pytest.mark.parametrize( "units, attributes, unit", [ - (IMPERIAL_SYSTEM, POWER_SENSOR_ATTRIBUTES, "W"), + (US_CUSTOMARY_SYSTEM, POWER_SENSOR_ATTRIBUTES, "W"), ], ) async def test_validate_statistics_sensor_no_longer_recorded( @@ -3750,7 +3762,7 @@ async def test_validate_statistics_sensor_no_longer_recorded( @pytest.mark.parametrize( "units, attributes, unit", [ - (IMPERIAL_SYSTEM, POWER_SENSOR_ATTRIBUTES, "W"), + (US_CUSTOMARY_SYSTEM, POWER_SENSOR_ATTRIBUTES, "W"), ], ) async def test_validate_statistics_sensor_not_recorded( @@ -3808,7 +3820,7 @@ async def test_validate_statistics_sensor_not_recorded( @pytest.mark.parametrize( "units, attributes, unit", [ - (IMPERIAL_SYSTEM, POWER_SENSOR_ATTRIBUTES, "W"), + (US_CUSTOMARY_SYSTEM, POWER_SENSOR_ATTRIBUTES, "W"), ], ) async def test_validate_statistics_sensor_removed( diff --git a/tests/components/subaru/test_sensor.py b/tests/components/subaru/test_sensor.py index 3f0cb773461..aec9e6ede7a 100644 --- a/tests/components/subaru/test_sensor.py +++ b/tests/components/subaru/test_sensor.py @@ -7,7 +7,7 @@ from homeassistant.components.subaru.sensor import ( SAFETY_SENSORS, ) from homeassistant.util import slugify -from homeassistant.util.unit_system import IMPERIAL_SYSTEM +from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM from .api_responses import ( EXPECTED_STATE_EV_IMPERIAL, @@ -25,7 +25,7 @@ from .conftest import ( async def test_sensors_ev_imperial(hass, ev_entry): """Test sensors supporting imperial units.""" - hass.config.units = IMPERIAL_SYSTEM + hass.config.units = US_CUSTOMARY_SYSTEM with patch(MOCK_API_FETCH), patch( MOCK_API_GET_DATA, return_value=VEHICLE_STATUS_EV diff --git a/tests/components/tomorrowio/test_sensor.py b/tests/components/tomorrowio/test_sensor.py index 51b3db00c6e..7721e5d36ac 100644 --- a/tests/components/tomorrowio/test_sensor.py +++ b/tests/components/tomorrowio/test_sensor.py @@ -25,7 +25,7 @@ from homeassistant.const import ATTR_ATTRIBUTION, CONF_NAME from homeassistant.core import HomeAssistant, State, callback from homeassistant.helpers.entity_registry import async_get from homeassistant.util import dt as dt_util -from homeassistant.util.unit_system import IMPERIAL_SYSTEM +from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM from .const import API_V4_ENTRY_DATA @@ -172,7 +172,7 @@ async def test_v4_sensor(hass: HomeAssistant) -> None: async def test_v4_sensor_imperial(hass: HomeAssistant) -> None: """Test v4 sensor data.""" - hass.config.units = IMPERIAL_SYSTEM + hass.config.units = US_CUSTOMARY_SYSTEM await _setup(hass, V4_FIELDS, API_V4_ENTRY_DATA) check_sensor_state(hass, O3, "91.35") check_sensor_state(hass, CO, "0.0") diff --git a/tests/components/weather/test_init.py b/tests/components/weather/test_init.py index 814d3b7857c..4b4f3a82d07 100644 --- a/tests/components/weather/test_init.py +++ b/tests/components/weather/test_init.py @@ -54,7 +54,7 @@ from homeassistant.util.distance import convert as convert_distance from homeassistant.util.pressure import convert as convert_pressure from homeassistant.util.speed import convert as convert_speed from homeassistant.util.temperature import convert as convert_temperature -from homeassistant.util.unit_system import IMPERIAL_SYSTEM, METRIC_SYSTEM +from homeassistant.util.unit_system import METRIC_SYSTEM, US_CUSTOMARY_SYSTEM from tests.testing_config.custom_components.test import weather as WeatherPlatform @@ -143,7 +143,7 @@ async def create_entity(hass: HomeAssistant, **kwargs): @pytest.mark.parametrize("native_unit", (TEMP_FAHRENHEIT, TEMP_CELSIUS)) @pytest.mark.parametrize( "state_unit, unit_system", - ((TEMP_CELSIUS, METRIC_SYSTEM), (TEMP_FAHRENHEIT, IMPERIAL_SYSTEM)), + ((TEMP_CELSIUS, METRIC_SYSTEM), (TEMP_FAHRENHEIT, US_CUSTOMARY_SYSTEM)), ) async def test_temperature( hass: HomeAssistant, @@ -176,7 +176,7 @@ async def test_temperature( @pytest.mark.parametrize("native_unit", (None,)) @pytest.mark.parametrize( "state_unit, unit_system", - ((TEMP_CELSIUS, METRIC_SYSTEM), (TEMP_FAHRENHEIT, IMPERIAL_SYSTEM)), + ((TEMP_CELSIUS, METRIC_SYSTEM), (TEMP_FAHRENHEIT, US_CUSTOMARY_SYSTEM)), ) async def test_temperature_no_unit( hass: HomeAssistant, @@ -209,7 +209,7 @@ async def test_temperature_no_unit( @pytest.mark.parametrize("native_unit", (PRESSURE_INHG, PRESSURE_INHG)) @pytest.mark.parametrize( "state_unit, unit_system", - ((PRESSURE_HPA, METRIC_SYSTEM), (PRESSURE_INHG, IMPERIAL_SYSTEM)), + ((PRESSURE_HPA, METRIC_SYSTEM), (PRESSURE_INHG, US_CUSTOMARY_SYSTEM)), ) async def test_pressure( hass: HomeAssistant, @@ -237,7 +237,7 @@ async def test_pressure( @pytest.mark.parametrize("native_unit", (None,)) @pytest.mark.parametrize( "state_unit, unit_system", - ((PRESSURE_HPA, METRIC_SYSTEM), (PRESSURE_INHG, IMPERIAL_SYSTEM)), + ((PRESSURE_HPA, METRIC_SYSTEM), (PRESSURE_INHG, US_CUSTOMARY_SYSTEM)), ) async def test_pressure_no_unit( hass: HomeAssistant, @@ -270,7 +270,7 @@ async def test_pressure_no_unit( "state_unit, unit_system", ( (SPEED_KILOMETERS_PER_HOUR, METRIC_SYSTEM), - (SPEED_MILES_PER_HOUR, IMPERIAL_SYSTEM), + (SPEED_MILES_PER_HOUR, US_CUSTOMARY_SYSTEM), ), ) async def test_wind_speed( @@ -304,7 +304,7 @@ async def test_wind_speed( "state_unit, unit_system", ( (SPEED_KILOMETERS_PER_HOUR, METRIC_SYSTEM), - (SPEED_MILES_PER_HOUR, IMPERIAL_SYSTEM), + (SPEED_MILES_PER_HOUR, US_CUSTOMARY_SYSTEM), ), ) async def test_wind_speed_no_unit( @@ -338,7 +338,7 @@ async def test_wind_speed_no_unit( "state_unit, unit_system", ( (LENGTH_KILOMETERS, METRIC_SYSTEM), - (LENGTH_MILES, IMPERIAL_SYSTEM), + (LENGTH_MILES, US_CUSTOMARY_SYSTEM), ), ) async def test_visibility( @@ -369,7 +369,7 @@ async def test_visibility( "state_unit, unit_system", ( (LENGTH_KILOMETERS, METRIC_SYSTEM), - (LENGTH_MILES, IMPERIAL_SYSTEM), + (LENGTH_MILES, US_CUSTOMARY_SYSTEM), ), ) async def test_visibility_no_unit( @@ -400,7 +400,7 @@ async def test_visibility_no_unit( "state_unit, unit_system", ( (LENGTH_MILLIMETERS, METRIC_SYSTEM), - (LENGTH_INCHES, IMPERIAL_SYSTEM), + (LENGTH_INCHES, US_CUSTOMARY_SYSTEM), ), ) async def test_precipitation( @@ -431,7 +431,7 @@ async def test_precipitation( "state_unit, unit_system", ( (LENGTH_MILLIMETERS, METRIC_SYSTEM), - (LENGTH_INCHES, IMPERIAL_SYSTEM), + (LENGTH_INCHES, US_CUSTOMARY_SYSTEM), ), ) async def test_precipitation_no_unit( @@ -719,7 +719,7 @@ async def test_backwards_compatibility_convert_values( precipitation_value = 1 precipitation_unit = LENGTH_MILLIMETERS - hass.config.units = IMPERIAL_SYSTEM + hass.config.units = US_CUSTOMARY_SYSTEM platform: WeatherPlatform = getattr(hass.components, "test.weather") platform.init(empty=True)