Deprecate is_metric property of unit system (#80313)
parent
a63c9e8fb9
commit
6a757662e4
|
@ -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."""
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue