From 4769e84bae3c917021be8544a266ec639d8e65fc Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Fri, 14 Oct 2022 13:33:59 +0000 Subject: [PATCH] Remove single-use function --- homeassistant/components/config/core.py | 9 ++++++++- homeassistant/core.py | 2 +- homeassistant/util/unit_system.py | 7 ------- tests/util/test_unit_system.py | 13 ------------- 4 files changed, 9 insertions(+), 22 deletions(-) diff --git a/homeassistant/components/config/core.py b/homeassistant/components/config/core.py index 99f4f2cfadd..d6d97b5caca 100644 --- a/homeassistant/components/config/core.py +++ b/homeassistant/components/config/core.py @@ -76,7 +76,14 @@ async def websocket_detect_config(hass, connection, msg): connection.send_result(msg["id"], info) return - info["unit_system"] = unit_system.get_default_key(location_info.use_metric) + # We don't want any integrations to use the name of the unit system + # so we are using the private attribute here + if location_info.use_metric: + # pylint: disable-next=protected-access + info["unit_system"] = unit_system._CONF_UNIT_SYSTEM_METRIC + else: + # pylint: disable-next=protected-access + info["unit_system"] = unit_system._CONF_UNIT_SYSTEM_IMPERIAL if location_info.latitude: info["latitude"] = location_info.latitude diff --git a/homeassistant/core.py b/homeassistant/core.py index 4bce95debc1..daa89ee1fcd 100644 --- a/homeassistant/core.py +++ b/homeassistant/core.py @@ -2011,7 +2011,7 @@ class Config: "latitude": self.latitude, "longitude": self.longitude, "elevation": self.elevation, - # We don't want any components to use the name of the unit system + # We don't want any integrations to use the name of the unit system # so we are using the private attribute here "unit_system": self.units._name, # pylint: disable=protected-access "location_name": self.location_name, diff --git a/homeassistant/util/unit_system.py b/homeassistant/util/unit_system.py index ed06c219b28..8dad108ccbe 100644 --- a/homeassistant/util/unit_system.py +++ b/homeassistant/util/unit_system.py @@ -220,13 +220,6 @@ def get_unit_system(key: str) -> UnitSystem: raise ValueError(f"`{key}` is not a valid unit system key") -def get_default_key(use_metric: bool) -> str: - """Get default unit system based on location information.""" - if use_metric: - return _CONF_UNIT_SYSTEM_METRIC - return _CONF_UNIT_SYSTEM_IMPERIAL - - validate_unit_system = vol.All( vol.Lower, vol.Any(_CONF_UNIT_SYSTEM_METRIC, _CONF_UNIT_SYSTEM_IMPERIAL) ) diff --git a/tests/util/test_unit_system.py b/tests/util/test_unit_system.py index 29063a10693..3019d6d0ff6 100644 --- a/tests/util/test_unit_system.py +++ b/tests/util/test_unit_system.py @@ -25,7 +25,6 @@ from homeassistant.util.unit_system import ( IMPERIAL_SYSTEM, METRIC_SYSTEM, UnitSystem, - get_default_key, get_unit_system, ) @@ -338,18 +337,6 @@ def test_deprecated_name( ) -@pytest.mark.parametrize( - "use_metric, expected_key", - [ - (True, _CONF_UNIT_SYSTEM_METRIC), - (False, _CONF_UNIT_SYSTEM_IMPERIAL), - ], -) -def test_get_default_key(use_metric: bool, expected_key: str) -> None: - """Test get_default_key.""" - assert get_default_key(use_metric) == expected_key - - @pytest.mark.parametrize( "key, expected_system", [