Use direct service calls in demo climate tests instead of climate common (#40934)

This commit is contained in:
Franck Nijhof 2020-10-01 11:22:30 +02:00 committed by GitHub
parent 1eb086e86d
commit 22ba6e06fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,6 +10,7 @@ from homeassistant.components.climate.const import (
ATTR_FAN_MODE,
ATTR_HUMIDITY,
ATTR_HVAC_ACTION,
ATTR_HVAC_MODE,
ATTR_HVAC_MODES,
ATTR_MAX_HUMIDITY,
ATTR_MAX_TEMP,
@ -26,13 +27,25 @@ from homeassistant.components.climate.const import (
HVAC_MODE_OFF,
PRESET_AWAY,
PRESET_ECO,
SERVICE_SET_AUX_HEAT,
SERVICE_SET_FAN_MODE,
SERVICE_SET_HUMIDITY,
SERVICE_SET_HVAC_MODE,
SERVICE_SET_PRESET_MODE,
SERVICE_SET_SWING_MODE,
SERVICE_SET_TEMPERATURE,
)
from homeassistant.const import (
ATTR_ENTITY_ID,
ATTR_TEMPERATURE,
SERVICE_TURN_OFF,
SERVICE_TURN_ON,
STATE_OFF,
STATE_ON,
)
from homeassistant.const import ATTR_TEMPERATURE, STATE_OFF, STATE_ON
from homeassistant.setup import async_setup_component
from homeassistant.util.unit_system import METRIC_SYSTEM
from tests.components.climate import common
ENTITY_CLIMATE = "climate.hvac"
ENTITY_ECOBEE = "climate.ecobee"
ENTITY_HEATPUMP = "climate.heatpump"
@ -82,9 +95,14 @@ async def test_set_only_target_temp_bad_attr(hass):
assert state.attributes.get(ATTR_TEMPERATURE) == 21
with pytest.raises(vol.Invalid):
await common.async_set_temperature(hass, None, ENTITY_CLIMATE)
await hass.services.async_call(
DOMAIN,
SERVICE_SET_TEMPERATURE,
{ATTR_ENTITY_ID: ENTITY_CLIMATE, ATTR_TEMPERATURE: None},
blocking=True,
)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get(ATTR_TEMPERATURE) == 21
@ -93,8 +111,12 @@ async def test_set_only_target_temp(hass):
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get(ATTR_TEMPERATURE) == 21
await common.async_set_temperature(hass, 30, ENTITY_CLIMATE)
await hass.async_block_till_done()
await hass.services.async_call(
DOMAIN,
SERVICE_SET_TEMPERATURE,
{ATTR_ENTITY_ID: ENTITY_CLIMATE, ATTR_TEMPERATURE: 30},
blocking=True,
)
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get(ATTR_TEMPERATURE) == 30.0
@ -105,8 +127,12 @@ async def test_set_only_target_temp_with_convert(hass):
state = hass.states.get(ENTITY_HEATPUMP)
assert state.attributes.get(ATTR_TEMPERATURE) == 20
await common.async_set_temperature(hass, 21, ENTITY_HEATPUMP)
await hass.async_block_till_done()
await hass.services.async_call(
DOMAIN,
SERVICE_SET_TEMPERATURE,
{ATTR_ENTITY_ID: ENTITY_HEATPUMP, ATTR_TEMPERATURE: 21},
blocking=True,
)
state = hass.states.get(ENTITY_HEATPUMP)
assert state.attributes.get(ATTR_TEMPERATURE) == 21.0
@ -119,10 +145,16 @@ async def test_set_target_temp_range(hass):
assert state.attributes.get(ATTR_TARGET_TEMP_LOW) == 21.0
assert state.attributes.get(ATTR_TARGET_TEMP_HIGH) == 24.0
await common.async_set_temperature(
hass, target_temp_high=25, target_temp_low=20, entity_id=ENTITY_ECOBEE
await hass.services.async_call(
DOMAIN,
SERVICE_SET_TEMPERATURE,
{
ATTR_ENTITY_ID: ENTITY_ECOBEE,
ATTR_TARGET_TEMP_LOW: 20,
ATTR_TARGET_TEMP_HIGH: 25,
},
blocking=True,
)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_ECOBEE)
assert state.attributes.get(ATTR_TEMPERATURE) is None
@ -138,14 +170,16 @@ async def test_set_target_temp_range_bad_attr(hass):
assert state.attributes.get(ATTR_TARGET_TEMP_HIGH) == 24.0
with pytest.raises(vol.Invalid):
await common.async_set_temperature(
hass,
temperature=None,
entity_id=ENTITY_ECOBEE,
target_temp_low=None,
target_temp_high=None,
await hass.services.async_call(
DOMAIN,
SERVICE_SET_TEMPERATURE,
{
ATTR_ENTITY_ID: ENTITY_ECOBEE,
ATTR_TARGET_TEMP_LOW: None,
ATTR_TARGET_TEMP_HIGH: None,
},
blocking=True,
)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_ECOBEE)
assert state.attributes.get(ATTR_TEMPERATURE) is None
@ -159,8 +193,12 @@ async def test_set_target_humidity_bad_attr(hass):
assert state.attributes.get(ATTR_HUMIDITY) == 67
with pytest.raises(vol.Invalid):
await common.async_set_humidity(hass, None, ENTITY_CLIMATE)
await hass.async_block_till_done()
await hass.services.async_call(
DOMAIN,
SERVICE_SET_HUMIDITY,
{ATTR_ENTITY_ID: ENTITY_CLIMATE, ATTR_HUMIDITY: None},
blocking=True,
)
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get(ATTR_HUMIDITY) == 67
@ -171,8 +209,12 @@ async def test_set_target_humidity(hass):
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get(ATTR_HUMIDITY) == 67
await common.async_set_humidity(hass, 64, ENTITY_CLIMATE)
await hass.async_block_till_done()
await hass.services.async_call(
DOMAIN,
SERVICE_SET_HUMIDITY,
{ATTR_ENTITY_ID: ENTITY_CLIMATE, ATTR_HUMIDITY: 64},
blocking=True,
)
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get(ATTR_HUMIDITY) == 64.0
@ -184,8 +226,12 @@ async def test_set_fan_mode_bad_attr(hass):
assert state.attributes.get(ATTR_FAN_MODE) == "On High"
with pytest.raises(vol.Invalid):
await common.async_set_fan_mode(hass, None, ENTITY_CLIMATE)
await hass.async_block_till_done()
await hass.services.async_call(
DOMAIN,
SERVICE_SET_FAN_MODE,
{ATTR_ENTITY_ID: ENTITY_CLIMATE, ATTR_FAN_MODE: None},
blocking=True,
)
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get(ATTR_FAN_MODE) == "On High"
@ -196,8 +242,12 @@ async def test_set_fan_mode(hass):
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get(ATTR_FAN_MODE) == "On High"
await common.async_set_fan_mode(hass, "On Low", ENTITY_CLIMATE)
await hass.async_block_till_done()
await hass.services.async_call(
DOMAIN,
SERVICE_SET_FAN_MODE,
{ATTR_ENTITY_ID: ENTITY_CLIMATE, ATTR_FAN_MODE: "On Low"},
blocking=True,
)
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get(ATTR_FAN_MODE) == "On Low"
@ -209,8 +259,12 @@ async def test_set_swing_mode_bad_attr(hass):
assert state.attributes.get(ATTR_SWING_MODE) == "Off"
with pytest.raises(vol.Invalid):
await common.async_set_swing_mode(hass, None, ENTITY_CLIMATE)
await hass.async_block_till_done()
await hass.services.async_call(
DOMAIN,
SERVICE_SET_SWING_MODE,
{ATTR_ENTITY_ID: ENTITY_CLIMATE, ATTR_SWING_MODE: None},
blocking=True,
)
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get(ATTR_SWING_MODE) == "Off"
@ -221,8 +275,12 @@ async def test_set_swing(hass):
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get(ATTR_SWING_MODE) == "Off"
await common.async_set_swing_mode(hass, "Auto", ENTITY_CLIMATE)
await hass.async_block_till_done()
await hass.services.async_call(
DOMAIN,
SERVICE_SET_SWING_MODE,
{ATTR_ENTITY_ID: ENTITY_CLIMATE, ATTR_SWING_MODE: "Auto"},
blocking=True,
)
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get(ATTR_SWING_MODE) == "Auto"
@ -238,8 +296,12 @@ async def test_set_hvac_bad_attr_and_state(hass):
assert state.state == HVAC_MODE_COOL
with pytest.raises(vol.Invalid):
await common.async_set_hvac_mode(hass, None, ENTITY_CLIMATE)
await hass.async_block_till_done()
await hass.services.async_call(
DOMAIN,
SERVICE_SET_HVAC_MODE,
{ATTR_ENTITY_ID: ENTITY_CLIMATE, ATTR_HVAC_MODE: None},
blocking=True,
)
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get(ATTR_HVAC_ACTION) == CURRENT_HVAC_COOL
@ -251,8 +313,12 @@ async def test_set_hvac(hass):
state = hass.states.get(ENTITY_CLIMATE)
assert state.state == HVAC_MODE_COOL
await common.async_set_hvac_mode(hass, HVAC_MODE_HEAT, ENTITY_CLIMATE)
await hass.async_block_till_done()
await hass.services.async_call(
DOMAIN,
SERVICE_SET_HVAC_MODE,
{ATTR_ENTITY_ID: ENTITY_CLIMATE, ATTR_HVAC_MODE: HVAC_MODE_HEAT},
blocking=True,
)
state = hass.states.get(ENTITY_CLIMATE)
assert state.state == HVAC_MODE_HEAT
@ -260,8 +326,12 @@ async def test_set_hvac(hass):
async def test_set_hold_mode_away(hass):
"""Test setting the hold mode away."""
await common.async_set_preset_mode(hass, PRESET_AWAY, ENTITY_ECOBEE)
await hass.async_block_till_done()
await hass.services.async_call(
DOMAIN,
SERVICE_SET_PRESET_MODE,
{ATTR_ENTITY_ID: ENTITY_ECOBEE, ATTR_PRESET_MODE: PRESET_AWAY},
blocking=True,
)
state = hass.states.get(ENTITY_ECOBEE)
assert state.attributes.get(ATTR_PRESET_MODE) == PRESET_AWAY
@ -269,8 +339,12 @@ async def test_set_hold_mode_away(hass):
async def test_set_hold_mode_eco(hass):
"""Test setting the hold mode eco."""
await common.async_set_preset_mode(hass, PRESET_ECO, ENTITY_ECOBEE)
await hass.async_block_till_done()
await hass.services.async_call(
DOMAIN,
SERVICE_SET_PRESET_MODE,
{ATTR_ENTITY_ID: ENTITY_ECOBEE, ATTR_PRESET_MODE: PRESET_ECO},
blocking=True,
)
state = hass.states.get(ENTITY_ECOBEE)
assert state.attributes.get(ATTR_PRESET_MODE) == PRESET_ECO
@ -282,16 +356,25 @@ async def test_set_aux_heat_bad_attr(hass):
assert state.attributes.get(ATTR_AUX_HEAT) == STATE_OFF
with pytest.raises(vol.Invalid):
await common.async_set_aux_heat(hass, None, ENTITY_CLIMATE)
await hass.async_block_till_done()
await hass.services.async_call(
DOMAIN,
SERVICE_SET_AUX_HEAT,
{ATTR_ENTITY_ID: ENTITY_CLIMATE, ATTR_AUX_HEAT: None},
blocking=True,
)
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get(ATTR_AUX_HEAT) == STATE_OFF
async def test_set_aux_heat_on(hass):
"""Test setting the axillary heater on/true."""
await common.async_set_aux_heat(hass, True, ENTITY_CLIMATE)
await hass.async_block_till_done()
await hass.services.async_call(
DOMAIN,
SERVICE_SET_AUX_HEAT,
{ATTR_ENTITY_ID: ENTITY_CLIMATE, ATTR_AUX_HEAT: True},
blocking=True,
)
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get(ATTR_AUX_HEAT) == STATE_ON
@ -299,8 +382,12 @@ async def test_set_aux_heat_on(hass):
async def test_set_aux_heat_off(hass):
"""Test setting the auxiliary heater off/false."""
await common.async_set_aux_heat(hass, False, ENTITY_CLIMATE)
await hass.async_block_till_done()
await hass.services.async_call(
DOMAIN,
SERVICE_SET_AUX_HEAT,
{ATTR_ENTITY_ID: ENTITY_CLIMATE, ATTR_AUX_HEAT: False},
blocking=True,
)
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get(ATTR_AUX_HEAT) == STATE_OFF
@ -308,21 +395,37 @@ async def test_set_aux_heat_off(hass):
async def test_turn_on(hass):
"""Test turn on device."""
await common.async_set_hvac_mode(hass, HVAC_MODE_OFF, ENTITY_CLIMATE)
await hass.services.async_call(
DOMAIN,
SERVICE_SET_HVAC_MODE,
{ATTR_ENTITY_ID: ENTITY_CLIMATE, ATTR_HVAC_MODE: HVAC_MODE_OFF},
blocking=True,
)
state = hass.states.get(ENTITY_CLIMATE)
assert state.state == HVAC_MODE_OFF
await common.async_turn_on(hass, ENTITY_CLIMATE)
await hass.services.async_call(
DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: ENTITY_CLIMATE}, blocking=True
)
state = hass.states.get(ENTITY_CLIMATE)
assert state.state == HVAC_MODE_HEAT
async def test_turn_off(hass):
"""Test turn on device."""
await common.async_set_hvac_mode(hass, HVAC_MODE_HEAT, ENTITY_CLIMATE)
await hass.services.async_call(
DOMAIN,
SERVICE_SET_HVAC_MODE,
{ATTR_ENTITY_ID: ENTITY_CLIMATE, ATTR_HVAC_MODE: HVAC_MODE_HEAT},
blocking=True,
)
state = hass.states.get(ENTITY_CLIMATE)
assert state.state == HVAC_MODE_HEAT
await common.async_turn_off(hass, ENTITY_CLIMATE)
await hass.services.async_call(
DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: ENTITY_CLIMATE}, blocking=True
)
state = hass.states.get(ENTITY_CLIMATE)
assert state.state == HVAC_MODE_OFF