Deprecate CONF_UNIT_SYSTEM_*** constants (#80320)
* Deprecate CONF_UNIT_SYSTEM_*** constants
* Adjust pylint plugin
* Add tests
* Remove single-use function
* Revert logic change
* Revert "Revert logic change"
This reverts commit 60959a0050
.
* Tweak again
This commit is contained in:
parent
284893d942
commit
bff5d1123f
8 changed files with 72 additions and 34 deletions
|
@ -3,8 +3,6 @@ import pytest
|
|||
|
||||
from homeassistant.const import (
|
||||
ACCUMULATED_PRECIPITATION,
|
||||
CONF_UNIT_SYSTEM_IMPERIAL,
|
||||
CONF_UNIT_SYSTEM_METRIC,
|
||||
LENGTH,
|
||||
LENGTH_KILOMETERS,
|
||||
LENGTH_METERS,
|
||||
|
@ -21,7 +19,14 @@ from homeassistant.const import (
|
|||
WIND_SPEED,
|
||||
)
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.util.unit_system import IMPERIAL_SYSTEM, METRIC_SYSTEM, UnitSystem
|
||||
from homeassistant.util.unit_system import (
|
||||
_CONF_UNIT_SYSTEM_IMPERIAL,
|
||||
_CONF_UNIT_SYSTEM_METRIC,
|
||||
IMPERIAL_SYSTEM,
|
||||
METRIC_SYSTEM,
|
||||
UnitSystem,
|
||||
get_unit_system,
|
||||
)
|
||||
|
||||
SYSTEM_NAME = "TEST"
|
||||
INVALID_UNIT = "INVALID"
|
||||
|
@ -317,8 +322,8 @@ def test_is_metric(
|
|||
@pytest.mark.parametrize(
|
||||
"unit_system, expected_name",
|
||||
[
|
||||
(METRIC_SYSTEM, CONF_UNIT_SYSTEM_METRIC),
|
||||
(IMPERIAL_SYSTEM, CONF_UNIT_SYSTEM_IMPERIAL),
|
||||
(METRIC_SYSTEM, _CONF_UNIT_SYSTEM_METRIC),
|
||||
(IMPERIAL_SYSTEM, _CONF_UNIT_SYSTEM_IMPERIAL),
|
||||
],
|
||||
)
|
||||
def test_deprecated_name(
|
||||
|
@ -330,3 +335,22 @@ def test_deprecated_name(
|
|||
"Detected code that accesses the `name` property of the unit system."
|
||||
in caplog.text
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"key, expected_system",
|
||||
[
|
||||
(_CONF_UNIT_SYSTEM_METRIC, METRIC_SYSTEM),
|
||||
(_CONF_UNIT_SYSTEM_IMPERIAL, IMPERIAL_SYSTEM),
|
||||
],
|
||||
)
|
||||
def test_get_unit_system(key: str, expected_system: UnitSystem) -> None:
|
||||
"""Test get_unit_system."""
|
||||
assert get_unit_system(key) is expected_system
|
||||
|
||||
|
||||
@pytest.mark.parametrize("key", [None, "", "invalid_custom"])
|
||||
def test_get_unit_system_invalid(key: str) -> None:
|
||||
"""Test get_unit_system with an invalid key."""
|
||||
with pytest.raises(ValueError, match=f"`{key}` is not a valid unit system key"):
|
||||
_ = get_unit_system(key)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue