diff --git a/homeassistant/util/unit_system.py b/homeassistant/util/unit_system.py index 194b8d82dbb..fcb8c0a4f16 100644 --- a/homeassistant/util/unit_system.py +++ b/homeassistant/util/unit_system.py @@ -23,7 +23,6 @@ from homeassistant.const import ( UnitOfTemperature, UnitOfVolume, ) -from homeassistant.helpers.frame import report from .unit_conversion import ( DistanceConverter, @@ -121,35 +120,6 @@ class UnitSystem: self.wind_speed_unit = wind_speed self._conversions = conversions - @property - def name(self) -> str: - """Return the name of the unit system.""" - report( - ( - "accesses the `name` property of the unit system. " - "This is deprecated and will stop working in Home Assistant 2023.1. " - "Please adjust to use instance check instead." - ), - error_if_core=False, - ) - if self is IMPERIAL_SYSTEM: - # kept for compatibility reasons, with associated warning above - return _CONF_UNIT_SYSTEM_IMPERIAL - return self._name - - @property - def is_metric(self) -> bool: - """Determine if this is the metric unit system.""" - report( - ( - "accesses the `is_metric` property of the unit system. " - "This is deprecated and will stop working in Home Assistant 2023.1. " - "Please adjust to use instance check instead." - ), - error_if_core=False, - ) - return self is METRIC_SYSTEM - def temperature(self, temperature: float, from_unit: str) -> float: """Convert the given temperature to this unit system.""" if not isinstance(temperature, Number): diff --git a/tests/components/config/test_core.py b/tests/components/config/test_core.py index 67977c96a2b..f3283d32972 100644 --- a/tests/components/config/test_core.py +++ b/tests/components/config/test_core.py @@ -9,6 +9,7 @@ from homeassistant.components import config from homeassistant.components.websocket_api.const import TYPE_RESULT from homeassistant.const import CONF_UNIT_SYSTEM, CONF_UNIT_SYSTEM_IMPERIAL from homeassistant.util import dt as dt_util, location +from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM @pytest.fixture @@ -55,7 +56,7 @@ async def test_websocket_core_update(hass, client): assert hass.config.longitude != 50 assert hass.config.elevation != 25 assert hass.config.location_name != "Huis" - assert hass.config.units.name != CONF_UNIT_SYSTEM_IMPERIAL + assert hass.config.units is not US_CUSTOMARY_SYSTEM assert hass.config.time_zone != "America/New_York" assert hass.config.external_url != "https://www.example.com" assert hass.config.internal_url != "http://example.com" @@ -91,7 +92,7 @@ async def test_websocket_core_update(hass, client): assert hass.config.longitude == 50 assert hass.config.elevation == 25 assert hass.config.location_name == "Huis" - assert hass.config.units.name == CONF_UNIT_SYSTEM_IMPERIAL + assert hass.config.units is US_CUSTOMARY_SYSTEM assert hass.config.external_url == "https://www.example.com" assert hass.config.internal_url == "http://example.local" assert hass.config.currency == "USD" diff --git a/tests/test_config.py b/tests/test_config.py index 00b0ae63c0b..1d804736c9d 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -412,7 +412,7 @@ async def test_loading_configuration_from_storage(hass, hass_storage): assert hass.config.longitude == 13 assert hass.config.elevation == 10 assert hass.config.location_name == "Home" - assert hass.config.units.name == CONF_UNIT_SYSTEM_METRIC + assert hass.config.units is METRIC_SYSTEM assert hass.config.time_zone == "Europe/Copenhagen" assert hass.config.external_url == "https://www.example.com" assert hass.config.internal_url == "http://example.local" @@ -446,7 +446,7 @@ async def test_loading_configuration_from_storage_with_yaml_only(hass, hass_stor assert hass.config.longitude == 13 assert hass.config.elevation == 10 assert hass.config.location_name == "Home" - assert hass.config.units.name == CONF_UNIT_SYSTEM_METRIC + assert hass.config.units is METRIC_SYSTEM assert hass.config.time_zone == "Europe/Copenhagen" assert len(hass.config.allowlist_external_dirs) == 3 assert "/etc" in hass.config.allowlist_external_dirs @@ -517,7 +517,7 @@ async def test_override_stored_configuration(hass, hass_storage): assert hass.config.longitude == 13 assert hass.config.elevation == 10 assert hass.config.location_name == "Home" - assert hass.config.units.name == CONF_UNIT_SYSTEM_METRIC + assert hass.config.units is METRIC_SYSTEM assert hass.config.time_zone == "Europe/Copenhagen" assert len(hass.config.allowlist_external_dirs) == 3 assert "/etc" in hass.config.allowlist_external_dirs @@ -550,7 +550,7 @@ async def test_loading_configuration(hass): assert hass.config.longitude == 50 assert hass.config.elevation == 25 assert hass.config.location_name == "Huis" - assert hass.config.units.name == CONF_UNIT_SYSTEM_IMPERIAL + assert hass.config.units is US_CUSTOMARY_SYSTEM assert hass.config.time_zone == "America/New_York" assert hass.config.external_url == "https://www.example.com" assert hass.config.internal_url == "http://example.local" diff --git a/tests/util/test_unit_system.py b/tests/util/test_unit_system.py index 4813bc34a3a..0c8ce7a191b 100644 --- a/tests/util/test_unit_system.py +++ b/tests/util/test_unit_system.py @@ -311,51 +311,6 @@ def test_properties(): assert METRIC_SYSTEM.accumulated_precipitation_unit == UnitOfLength.MILLIMETERS -@pytest.mark.parametrize( - "unit_system, expected_flag", - [ - (METRIC_SYSTEM, True), - (IMPERIAL_SYSTEM, False), - ], -) -def test_is_metric( - caplog: pytest.LogCaptureFixture, unit_system: UnitSystem, expected_flag: bool -): - """Test the is metric flag.""" - assert unit_system.is_metric == expected_flag - assert ( - "Detected code that accesses the `is_metric` property of the unit system." - in caplog.text - ) - - -@pytest.mark.parametrize( - "unit_system, expected_name, expected_private_name", - [ - (METRIC_SYSTEM, _CONF_UNIT_SYSTEM_METRIC, _CONF_UNIT_SYSTEM_METRIC), - (IMPERIAL_SYSTEM, _CONF_UNIT_SYSTEM_IMPERIAL, _CONF_UNIT_SYSTEM_US_CUSTOMARY), - ( - US_CUSTOMARY_SYSTEM, - _CONF_UNIT_SYSTEM_IMPERIAL, - _CONF_UNIT_SYSTEM_US_CUSTOMARY, - ), - ], -) -def test_deprecated_name( - caplog: pytest.LogCaptureFixture, - unit_system: UnitSystem, - expected_name: str, - expected_private_name: str, -) -> None: - """Test the name is deprecated.""" - assert unit_system.name == expected_name - assert unit_system._name == expected_private_name - assert ( - "Detected code that accesses the `name` property of the unit system." - in caplog.text - ) - - @pytest.mark.parametrize( "key, expected_system", [