mirror of
https://github.com/Electric-Special/ha-core.git
synced 2026-03-21 08:06:00 +01:00
Deprecate TemperatureConverter.convert_interval (#155689)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Erik Montnemery <erik@montnemery.com> Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
This commit is contained in:
@@ -58,7 +58,10 @@ from homeassistant.const import (
|
||||
from homeassistant.helpers import network
|
||||
from homeassistant.util import color as color_util, dt as dt_util
|
||||
from homeassistant.util.decorator import Registry
|
||||
from homeassistant.util.unit_conversion import TemperatureConverter
|
||||
from homeassistant.util.unit_conversion import (
|
||||
TemperatureConverter,
|
||||
TemperatureDeltaConverter,
|
||||
)
|
||||
|
||||
from .config import AbstractConfig
|
||||
from .const import (
|
||||
@@ -844,7 +847,7 @@ def temperature_from_object(
|
||||
temp -= 273.15
|
||||
|
||||
if interval:
|
||||
return TemperatureConverter.convert_interval(temp, from_unit, to_unit)
|
||||
return TemperatureDeltaConverter.convert(temp, from_unit, to_unit)
|
||||
return TemperatureConverter.convert(temp, from_unit, to_unit)
|
||||
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ from homeassistant.const import (
|
||||
UnitOfVolumetricFlux,
|
||||
)
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.deprecation import deprecated_function
|
||||
|
||||
# Distance conversion constants
|
||||
_MM_TO_M = 0.001 # 1 mm = 0.001 m
|
||||
@@ -707,6 +708,9 @@ class TemperatureConverter(BaseUnitConverter):
|
||||
)
|
||||
|
||||
@classmethod
|
||||
@deprecated_function(
|
||||
"TemperatureDeltaConverter.convert", breaks_in_ha_version="2026.12.0"
|
||||
)
|
||||
def convert_interval(cls, interval: float, from_unit: str, to_unit: str) -> float:
|
||||
"""Convert a temperature interval from one unit to another.
|
||||
|
||||
|
||||
@@ -1302,11 +1302,19 @@ def test_unit_conversion_factory_allow_none(
|
||||
],
|
||||
)
|
||||
def test_temperature_convert_with_interval(
|
||||
value: float, from_unit: str, expected: float, to_unit: str
|
||||
value: float,
|
||||
from_unit: str,
|
||||
expected: float,
|
||||
to_unit: str,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test conversion to other units."""
|
||||
expected = pytest.approx(expected)
|
||||
assert TemperatureConverter.convert_interval(value, from_unit, to_unit) == expected
|
||||
assert (
|
||||
"The deprecated function convert_interval was called. It will be removed "
|
||||
"in HA Core 2026.12.0. Use TemperatureDeltaConverter.convert instead"
|
||||
) in caplog.text
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
Reference in New Issue
Block a user