mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Support setting hvac_mode and temp in same homekit_controller set_temperature service call (#52195)
* Support setting hvac_mode and temp in same set_temperature service call * Update homeassistant/components/homekit_controller/climate.py Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * Update homeassistant/components/homekit_controller/climate.py Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
parent
040c88f982
commit
7de3e7d1dd
@ -19,6 +19,7 @@ from homeassistant.components.climate import (
|
|||||||
ClimateEntity,
|
ClimateEntity,
|
||||||
)
|
)
|
||||||
from homeassistant.components.climate.const import (
|
from homeassistant.components.climate.const import (
|
||||||
|
ATTR_HVAC_MODE,
|
||||||
ATTR_TARGET_TEMP_HIGH,
|
ATTR_TARGET_TEMP_HIGH,
|
||||||
ATTR_TARGET_TEMP_LOW,
|
ATTR_TARGET_TEMP_LOW,
|
||||||
CURRENT_HVAC_COOL,
|
CURRENT_HVAC_COOL,
|
||||||
@ -342,16 +343,27 @@ class HomeKitClimateEntity(HomeKitEntity, ClimateEntity):
|
|||||||
|
|
||||||
async def async_set_temperature(self, **kwargs):
|
async def async_set_temperature(self, **kwargs):
|
||||||
"""Set new target temperature."""
|
"""Set new target temperature."""
|
||||||
|
chars = {}
|
||||||
|
|
||||||
|
value = self.service.value(CharacteristicsTypes.HEATING_COOLING_TARGET)
|
||||||
|
mode = MODE_HOMEKIT_TO_HASS.get(value)
|
||||||
|
|
||||||
|
if kwargs.get(ATTR_HVAC_MODE, mode) != mode:
|
||||||
|
mode = kwargs[ATTR_HVAC_MODE]
|
||||||
|
chars[CharacteristicsTypes.HEATING_COOLING_TARGET] = MODE_HASS_TO_HOMEKIT[
|
||||||
|
mode
|
||||||
|
]
|
||||||
|
|
||||||
temp = kwargs.get(ATTR_TEMPERATURE)
|
temp = kwargs.get(ATTR_TEMPERATURE)
|
||||||
heat_temp = kwargs.get(ATTR_TARGET_TEMP_LOW)
|
heat_temp = kwargs.get(ATTR_TARGET_TEMP_LOW)
|
||||||
cool_temp = kwargs.get(ATTR_TARGET_TEMP_HIGH)
|
cool_temp = kwargs.get(ATTR_TARGET_TEMP_HIGH)
|
||||||
value = self.service.value(CharacteristicsTypes.HEATING_COOLING_TARGET)
|
|
||||||
if (MODE_HOMEKIT_TO_HASS.get(value) in {HVAC_MODE_HEAT_COOL}) and (
|
if (mode == HVAC_MODE_HEAT_COOL) and (
|
||||||
SUPPORT_TARGET_TEMPERATURE_RANGE & self.supported_features
|
SUPPORT_TARGET_TEMPERATURE_RANGE & self.supported_features
|
||||||
):
|
):
|
||||||
if temp is None:
|
if temp is None:
|
||||||
temp = (cool_temp + heat_temp) / 2
|
temp = (cool_temp + heat_temp) / 2
|
||||||
await self.async_put_characteristics(
|
chars.update(
|
||||||
{
|
{
|
||||||
CharacteristicsTypes.TEMPERATURE_HEATING_THRESHOLD: heat_temp,
|
CharacteristicsTypes.TEMPERATURE_HEATING_THRESHOLD: heat_temp,
|
||||||
CharacteristicsTypes.TEMPERATURE_COOLING_THRESHOLD: cool_temp,
|
CharacteristicsTypes.TEMPERATURE_COOLING_THRESHOLD: cool_temp,
|
||||||
@ -359,9 +371,9 @@ class HomeKitClimateEntity(HomeKitEntity, ClimateEntity):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
await self.async_put_characteristics(
|
chars[CharacteristicsTypes.TEMPERATURE_TARGET] = temp
|
||||||
{CharacteristicsTypes.TEMPERATURE_TARGET: temp}
|
|
||||||
)
|
await self.async_put_characteristics(chars)
|
||||||
|
|
||||||
async def async_set_humidity(self, humidity):
|
async def async_set_humidity(self, humidity):
|
||||||
"""Set new target humidity."""
|
"""Set new target humidity."""
|
||||||
|
@ -271,7 +271,6 @@ async def test_climate_cannot_set_thermostat_temp_range_in_wrong_mode(hass, utcn
|
|||||||
SERVICE_SET_TEMPERATURE,
|
SERVICE_SET_TEMPERATURE,
|
||||||
{
|
{
|
||||||
"entity_id": "climate.testdevice",
|
"entity_id": "climate.testdevice",
|
||||||
"hvac_mode": HVAC_MODE_HEAT_COOL,
|
|
||||||
"temperature": 22,
|
"temperature": 22,
|
||||||
"target_temp_low": 20,
|
"target_temp_low": 20,
|
||||||
"target_temp_high": 24,
|
"target_temp_high": 24,
|
||||||
@ -370,6 +369,35 @@ async def test_climate_set_thermostat_temp_on_sspa_device(hass, utcnow):
|
|||||||
)
|
)
|
||||||
assert helper.characteristics[TEMPERATURE_TARGET].value == 21
|
assert helper.characteristics[TEMPERATURE_TARGET].value == 21
|
||||||
|
|
||||||
|
await hass.services.async_call(
|
||||||
|
DOMAIN,
|
||||||
|
SERVICE_SET_TEMPERATURE,
|
||||||
|
{
|
||||||
|
"entity_id": "climate.testdevice",
|
||||||
|
"temperature": 22,
|
||||||
|
},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
assert helper.characteristics[TEMPERATURE_TARGET].value == 22
|
||||||
|
|
||||||
|
|
||||||
|
async def test_climate_set_mode_via_temp(hass, utcnow):
|
||||||
|
"""Test setting temperature and mode at same tims."""
|
||||||
|
helper = await setup_test_component(hass, create_thermostat_single_set_point_auto)
|
||||||
|
|
||||||
|
await hass.services.async_call(
|
||||||
|
DOMAIN,
|
||||||
|
SERVICE_SET_TEMPERATURE,
|
||||||
|
{
|
||||||
|
"entity_id": "climate.testdevice",
|
||||||
|
"temperature": 21,
|
||||||
|
"hvac_mode": HVAC_MODE_HEAT,
|
||||||
|
},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
assert helper.characteristics[TEMPERATURE_TARGET].value == 21
|
||||||
|
assert helper.characteristics[HEATING_COOLING_TARGET].value == 1
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
SERVICE_SET_TEMPERATURE,
|
SERVICE_SET_TEMPERATURE,
|
||||||
@ -381,6 +409,7 @@ async def test_climate_set_thermostat_temp_on_sspa_device(hass, utcnow):
|
|||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
assert helper.characteristics[TEMPERATURE_TARGET].value == 22
|
assert helper.characteristics[TEMPERATURE_TARGET].value == 22
|
||||||
|
assert helper.characteristics[HEATING_COOLING_TARGET].value == 3
|
||||||
|
|
||||||
|
|
||||||
async def test_climate_change_thermostat_humidity(hass, utcnow):
|
async def test_climate_change_thermostat_humidity(hass, utcnow):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user