Increase test coverage for KNX Climate (#117903)
* Increase test coverage fro KNX Climate * fix test type annotationpull/119096/head
parent
581fb2f9f4
commit
de3a0841d8
|
@ -54,11 +54,12 @@ async def test_climate_basic_temperature_set(
|
|||
assert len(events) == 1
|
||||
|
||||
|
||||
@pytest.mark.parametrize("heat_cool", [False, True])
|
||||
@pytest.mark.parametrize("heat_cool_ga", [None, "4/4/4"])
|
||||
async def test_climate_on_off(
|
||||
hass: HomeAssistant, knx: KNXTestKit, heat_cool: bool
|
||||
hass: HomeAssistant, knx: KNXTestKit, heat_cool_ga: str | None
|
||||
) -> None:
|
||||
"""Test KNX climate on/off."""
|
||||
on_off_ga = "3/3/3"
|
||||
await knx.setup_integration(
|
||||
{
|
||||
ClimateSchema.PLATFORM: {
|
||||
|
@ -66,15 +67,15 @@ async def test_climate_on_off(
|
|||
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_ADDRESS: on_off_ga,
|
||||
ClimateSchema.CONF_ON_OFF_STATE_ADDRESS: "1/2/9",
|
||||
}
|
||||
| (
|
||||
{
|
||||
ClimateSchema.CONF_HEAT_COOL_ADDRESS: "1/2/10",
|
||||
ClimateSchema.CONF_HEAT_COOL_ADDRESS: heat_cool_ga,
|
||||
ClimateSchema.CONF_HEAT_COOL_STATE_ADDRESS: "1/2/11",
|
||||
}
|
||||
if heat_cool
|
||||
if heat_cool_ga
|
||||
else {}
|
||||
)
|
||||
}
|
||||
|
@ -82,7 +83,7 @@ async def test_climate_on_off(
|
|||
|
||||
await hass.async_block_till_done()
|
||||
# read heat/cool state
|
||||
if heat_cool:
|
||||
if heat_cool_ga:
|
||||
await knx.assert_read("1/2/11")
|
||||
await knx.receive_response("1/2/11", 0) # cool
|
||||
# read temperature state
|
||||
|
@ -102,7 +103,7 @@ async def test_climate_on_off(
|
|||
{"entity_id": "climate.test"},
|
||||
blocking=True,
|
||||
)
|
||||
await knx.assert_write("1/2/8", 0)
|
||||
await knx.assert_write(on_off_ga, 0)
|
||||
assert hass.states.get("climate.test").state == "off"
|
||||
|
||||
# turn on
|
||||
|
@ -112,8 +113,8 @@ async def test_climate_on_off(
|
|||
{"entity_id": "climate.test"},
|
||||
blocking=True,
|
||||
)
|
||||
await knx.assert_write("1/2/8", 1)
|
||||
if heat_cool:
|
||||
await knx.assert_write(on_off_ga, 1)
|
||||
if heat_cool_ga:
|
||||
# does not fall back to default hvac mode after turn_on
|
||||
assert hass.states.get("climate.test").state == "cool"
|
||||
else:
|
||||
|
@ -126,7 +127,7 @@ async def test_climate_on_off(
|
|||
{"entity_id": "climate.test", "hvac_mode": HVACMode.OFF},
|
||||
blocking=True,
|
||||
)
|
||||
await knx.assert_write("1/2/8", 0)
|
||||
await knx.assert_write(on_off_ga, 0)
|
||||
|
||||
# set hvac mode to heat
|
||||
await hass.services.async_call(
|
||||
|
@ -135,15 +136,19 @@ async def test_climate_on_off(
|
|||
{"entity_id": "climate.test", "hvac_mode": HVACMode.HEAT},
|
||||
blocking=True,
|
||||
)
|
||||
if heat_cool:
|
||||
if heat_cool_ga:
|
||||
# only set new hvac_mode without changing on/off - actuator shall handle that
|
||||
await knx.assert_write("1/2/10", 1)
|
||||
await knx.assert_write(heat_cool_ga, 1)
|
||||
else:
|
||||
await knx.assert_write("1/2/8", 1)
|
||||
await knx.assert_write(on_off_ga, 1)
|
||||
|
||||
|
||||
async def test_climate_hvac_mode(hass: HomeAssistant, knx: KNXTestKit) -> None:
|
||||
@pytest.mark.parametrize("on_off_ga", [None, "4/4/4"])
|
||||
async def test_climate_hvac_mode(
|
||||
hass: HomeAssistant, knx: KNXTestKit, on_off_ga: str | None
|
||||
) -> None:
|
||||
"""Test KNX climate hvac mode."""
|
||||
controller_mode_ga = "3/3/3"
|
||||
await knx.setup_integration(
|
||||
{
|
||||
ClimateSchema.PLATFORM: {
|
||||
|
@ -151,11 +156,17 @@ async def test_climate_hvac_mode(hass: HomeAssistant, knx: KNXTestKit) -> None:
|
|||
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_CONTROLLER_MODE_ADDRESS: "1/2/6",
|
||||
ClimateSchema.CONF_CONTROLLER_MODE_ADDRESS: controller_mode_ga,
|
||||
ClimateSchema.CONF_CONTROLLER_MODE_STATE_ADDRESS: "1/2/7",
|
||||
ClimateSchema.CONF_ON_OFF_ADDRESS: "1/2/8",
|
||||
ClimateSchema.CONF_OPERATION_MODES: ["Auto"],
|
||||
}
|
||||
| (
|
||||
{
|
||||
ClimateSchema.CONF_ON_OFF_ADDRESS: on_off_ga,
|
||||
}
|
||||
if on_off_ga
|
||||
else {}
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -171,23 +182,50 @@ 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 mode to off
|
||||
# turn hvac mode to off - set_hvac_mode() doesn't send to on_off if dedicated hvac 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/6", (0x06,))
|
||||
await knx.assert_write(controller_mode_ga, (0x06,))
|
||||
|
||||
# turn hvac on
|
||||
# set hvac to non default mode
|
||||
await hass.services.async_call(
|
||||
"climate",
|
||||
"set_hvac_mode",
|
||||
{"entity_id": "climate.test", "hvac_mode": HVACMode.HEAT},
|
||||
{"entity_id": "climate.test", "hvac_mode": HVACMode.COOL},
|
||||
blocking=True,
|
||||
)
|
||||
await knx.assert_write("1/2/6", (0x01,))
|
||||
await knx.assert_write(controller_mode_ga, (0x03,))
|
||||
|
||||
# turn off
|
||||
await hass.services.async_call(
|
||||
"climate",
|
||||
"turn_off",
|
||||
{"entity_id": "climate.test"},
|
||||
blocking=True,
|
||||
)
|
||||
if on_off_ga:
|
||||
await knx.assert_write(on_off_ga, 0)
|
||||
else:
|
||||
await knx.assert_write(controller_mode_ga, (0x06,))
|
||||
assert hass.states.get("climate.test").state == "off"
|
||||
|
||||
# turn on
|
||||
await hass.services.async_call(
|
||||
"climate",
|
||||
"turn_on",
|
||||
{"entity_id": "climate.test"},
|
||||
blocking=True,
|
||||
)
|
||||
if on_off_ga:
|
||||
await knx.assert_write(on_off_ga, 1)
|
||||
else:
|
||||
# restore last hvac mode
|
||||
await knx.assert_write(controller_mode_ga, (0x03,))
|
||||
assert hass.states.get("climate.test").state == "cool"
|
||||
|
||||
|
||||
async def test_climate_preset_mode(
|
||||
|
|
Loading…
Reference in New Issue