mirror of
https://github.com/home-assistant/core.git
synced 2026-09-25 17:04:04 -04:00
Fix SmartThings AC temperature range unit conversion (#180299)
Co-authored-by: Claude Opus 5 <noreply@anthropic.com> Co-authored-by: TheJulianJES <TheJulianJES@users.noreply.github.com>
This commit is contained in:
co-authored by
Claude Opus 5
TheJulianJES
parent
eeec7a551e
commit
92983e4022
@@ -29,6 +29,10 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.util.unit_conversion import (
|
||||
TemperatureConverter,
|
||||
TemperatureDeltaConverter,
|
||||
)
|
||||
|
||||
from . import FullDevice, SmartThingsConfigEntry
|
||||
from .const import DOMAIN, MAIN, UNIT_MAP
|
||||
@@ -608,27 +612,50 @@ class SmartThingsAirConditioner(SmartThingsEntity, ClimateEntity):
|
||||
return None
|
||||
return setpoint_range.get(key)
|
||||
|
||||
@property
|
||||
def _setpoint_range_unit(self) -> str:
|
||||
"""Return the unit the cooling setpoint range is reported in."""
|
||||
if (
|
||||
unit := self._internal_state[Capability.THERMOSTAT_COOLING_SETPOINT][
|
||||
Attribute.COOLING_SETPOINT_RANGE
|
||||
].unit
|
||||
) is None:
|
||||
return self.temperature_unit
|
||||
return UNIT_MAP[unit]
|
||||
|
||||
@property
|
||||
@override
|
||||
def target_temperature_step(self) -> float | None:
|
||||
"""Return the supported step of target temperature."""
|
||||
return self._get_setpoint_range_value("step")
|
||||
if (step := self._get_setpoint_range_value("step")) is None:
|
||||
return None
|
||||
return TemperatureDeltaConverter.convert(
|
||||
step, self._setpoint_range_unit, self.temperature_unit
|
||||
)
|
||||
|
||||
@property
|
||||
@override
|
||||
def min_temp(self) -> float:
|
||||
"""Return the minimum temperature."""
|
||||
if (minimum := self._get_setpoint_range_value("minimum")) is None:
|
||||
return DEFAULT_MIN_TEMP
|
||||
return minimum
|
||||
return TemperatureConverter.convert(
|
||||
DEFAULT_MIN_TEMP, UnitOfTemperature.CELSIUS, self.temperature_unit
|
||||
)
|
||||
return TemperatureConverter.convert(
|
||||
minimum, self._setpoint_range_unit, self.temperature_unit
|
||||
)
|
||||
|
||||
@property
|
||||
@override
|
||||
def max_temp(self) -> float:
|
||||
"""Return the maximum temperature."""
|
||||
if (maximum := self._get_setpoint_range_value("maximum")) is None:
|
||||
return DEFAULT_MAX_TEMP
|
||||
return maximum
|
||||
return TemperatureConverter.convert(
|
||||
DEFAULT_MAX_TEMP, UnitOfTemperature.CELSIUS, self.temperature_unit
|
||||
)
|
||||
return TemperatureConverter.convert(
|
||||
maximum, self._setpoint_range_unit, self.temperature_unit
|
||||
)
|
||||
|
||||
@property
|
||||
@override
|
||||
|
||||
@@ -51,6 +51,7 @@ from homeassistant.const import (
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM
|
||||
|
||||
from . import (
|
||||
set_attribute_value,
|
||||
@@ -843,6 +844,45 @@ async def test_ac_setpoint_range_update(
|
||||
assert state.attributes[ATTR_TARGET_TEMP_STEP] == 1
|
||||
|
||||
|
||||
@pytest.mark.parametrize("device_fixture", ["aux_ac"])
|
||||
async def test_ac_default_temperature_range_in_device_unit(
|
||||
hass: HomeAssistant,
|
||||
devices: AsyncMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test the default temperature range is expressed in the unit of the device."""
|
||||
hass.config.units = US_CUSTOMARY_SYSTEM
|
||||
devices.get_device_status.return_value[MAIN][Capability.TEMPERATURE_MEASUREMENT][
|
||||
Attribute.TEMPERATURE
|
||||
].unit = "F"
|
||||
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
state = hass.states.get("climate.aux_a_c_on_off")
|
||||
assert state.attributes[ATTR_MIN_TEMP] == 45
|
||||
assert state.attributes[ATTR_MAX_TEMP] == 95
|
||||
|
||||
|
||||
@pytest.mark.parametrize("device_fixture", ["da_ac_rac_01001"])
|
||||
async def test_ac_setpoint_range_converted_to_device_unit(
|
||||
hass: HomeAssistant,
|
||||
devices: AsyncMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test the setpoint range is converted when it uses another unit."""
|
||||
hass.config.units = US_CUSTOMARY_SYSTEM
|
||||
devices.get_device_status.return_value[MAIN][Capability.TEMPERATURE_MEASUREMENT][
|
||||
Attribute.TEMPERATURE
|
||||
].unit = "F"
|
||||
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
state = hass.states.get("climate.theater_aire_dormitorio_principal")
|
||||
assert state.attributes[ATTR_MIN_TEMP] == 61
|
||||
assert state.attributes[ATTR_MAX_TEMP] == 86
|
||||
assert state.attributes[ATTR_TARGET_TEMP_STEP] == 1.8
|
||||
|
||||
|
||||
@pytest.mark.parametrize("device_fixture", ["virtual_thermostat"])
|
||||
async def test_thermostat_set_fan_mode(
|
||||
hass: HomeAssistant,
|
||||
|
||||
Reference in New Issue
Block a user