Deprecate is_metric property of unit system (#80313)

pull/80318/head
epenet 2022-10-14 13:44:18 +02:00 committed by GitHub
parent a63c9e8fb9
commit 6a757662e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 4 deletions

View File

@ -131,7 +131,13 @@ class UnitSystem:
@property
def is_metric(self) -> bool:
"""Determine if this is the metric unit system."""
return self._name == CONF_UNIT_SYSTEM_METRIC
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."""

View File

@ -296,10 +296,22 @@ def test_properties():
assert METRIC_SYSTEM.accumulated_precipitation_unit == LENGTH_MILLIMETERS
def test_is_metric():
@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 METRIC_SYSTEM.is_metric
assert not IMPERIAL_SYSTEM.is_metric
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(