1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Add async_turn_on/off methods for KNX climate entities (#117882)

Add async_turn_on/off methods for KNX climate entities
This commit is contained in:
Matthias Alphart
2024-05-21 23:54:43 +02:00
committed by GitHub
parent c2b3bf3fb9
commit b94735a445
2 changed files with 155 additions and 24 deletions

View File

@@ -1,5 +1,7 @@
"""Test KNX climate."""
import pytest
from homeassistant.components.climate import PRESET_ECO, PRESET_SLEEP, HVACMode
from homeassistant.components.knx.schema import ClimateSchema
from homeassistant.const import CONF_NAME, STATE_IDLE
@@ -52,6 +54,94 @@ async def test_climate_basic_temperature_set(
assert len(events) == 1
@pytest.mark.parametrize("heat_cool", [False, True])
async def test_climate_on_off(
hass: HomeAssistant, knx: KNXTestKit, heat_cool: bool
) -> None:
"""Test KNX climate on/off."""
await knx.setup_integration(
{
ClimateSchema.PLATFORM: {
CONF_NAME: "test",
ClimateSchema.CONF_TEMPERATURE_ADDRESS: "1/2/3",
ClimateSchema.CONF_TARGET_TEMPERATURE_ADDRESS: "1/2/4",
ClimateSchema.CONF_TARGET_TEMPERATURE_STATE_ADDRESS: "1/2/5",
ClimateSchema.CONF_ON_OFF_ADDRESS: "1/2/8",
ClimateSchema.CONF_ON_OFF_STATE_ADDRESS: "1/2/9",
}
| (
{
ClimateSchema.CONF_HEAT_COOL_ADDRESS: "1/2/10",
ClimateSchema.CONF_HEAT_COOL_STATE_ADDRESS: "1/2/11",
}
if heat_cool
else {}
)
}
)
await hass.async_block_till_done()
# read heat/cool state
if heat_cool:
await knx.assert_read("1/2/11")
await knx.receive_response("1/2/11", 0) # cool
# read temperature state
await knx.assert_read("1/2/3")
await knx.receive_response("1/2/3", RAW_FLOAT_20_0)
# read target temperature state
await knx.assert_read("1/2/5")
await knx.receive_response("1/2/5", RAW_FLOAT_22_0)
# read on/off state
await knx.assert_read("1/2/9")
await knx.receive_response("1/2/9", 1)
# turn off
await hass.services.async_call(
"climate",
"turn_off",
{"entity_id": "climate.test"},
blocking=True,
)
await knx.assert_write("1/2/8", 0)
assert hass.states.get("climate.test").state == "off"
# turn on
await hass.services.async_call(
"climate",
"turn_on",
{"entity_id": "climate.test"},
blocking=True,
)
await knx.assert_write("1/2/8", 1)
if heat_cool:
# does not fall back to default hvac mode after turn_on
assert hass.states.get("climate.test").state == "cool"
else:
assert hass.states.get("climate.test").state == "heat"
# set hvac mode to off triggers turn_off if no controller_mode is available
await hass.services.async_call(
"climate",
"set_hvac_mode",
{"entity_id": "climate.test", "hvac_mode": HVACMode.OFF},
blocking=True,
)
await knx.assert_write("1/2/8", 0)
# set hvac mode to heat
await hass.services.async_call(
"climate",
"set_hvac_mode",
{"entity_id": "climate.test", "hvac_mode": HVACMode.HEAT},
blocking=True,
)
if heat_cool:
# only set new hvac_mode without changing on/off - actuator shall handle that
await knx.assert_write("1/2/10", 1)
else:
await knx.assert_write("1/2/8", 1)
async def test_climate_hvac_mode(hass: HomeAssistant, knx: KNXTestKit) -> None:
"""Test KNX climate hvac mode."""
await knx.setup_integration(
@@ -68,7 +158,6 @@ async def test_climate_hvac_mode(hass: HomeAssistant, knx: KNXTestKit) -> None:
}
}
)
async_capture_events(hass, "state_changed")
await hass.async_block_till_done()
# read states state updater
@@ -82,14 +171,14 @@ async def test_climate_hvac_mode(hass: HomeAssistant, knx: KNXTestKit) -> None:
await knx.assert_read("1/2/5")
await knx.receive_response("1/2/5", RAW_FLOAT_22_0)
# turn hvac off
# turn hvac mode to off
await hass.services.async_call(
"climate",
"set_hvac_mode",
{"entity_id": "climate.test", "hvac_mode": HVACMode.OFF},
blocking=True,
)
await knx.assert_write("1/2/8", False)
await knx.assert_write("1/2/6", (0x06,))
# turn hvac on
await hass.services.async_call(
@@ -98,7 +187,6 @@ async def test_climate_hvac_mode(hass: HomeAssistant, knx: KNXTestKit) -> None:
{"entity_id": "climate.test", "hvac_mode": HVACMode.HEAT},
blocking=True,
)
await knx.assert_write("1/2/8", True)
await knx.assert_write("1/2/6", (0x01,))
@@ -182,7 +270,6 @@ async def test_update_entity(hass: HomeAssistant, knx: KNXTestKit) -> None:
)
assert await async_setup_component(hass, "homeassistant", {})
await hass.async_block_till_done()
async_capture_events(hass, "state_changed")
await hass.async_block_till_done()
# read states state updater