Do async_setup_platform in background (#36244)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Paulus Schoutsen 2020-05-31 22:18:30 -07:00 committed by GitHub
parent d488c779fc
commit 276f3afb00
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
161 changed files with 1184 additions and 305 deletions

View file

@ -72,6 +72,7 @@ DEFAULT_CONFIG = {
async def test_setup_params(hass, mqtt_mock):
"""Test the initial parameters."""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("temperature") == 21
@ -85,6 +86,7 @@ async def test_setup_params(hass, mqtt_mock):
async def test_supported_features(hass, mqtt_mock):
"""Test the supported_features."""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
support = (
@ -102,6 +104,7 @@ async def test_supported_features(hass, mqtt_mock):
async def test_get_hvac_modes(hass, mqtt_mock):
"""Test that the operation list returns the correct modes."""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
modes = state.attributes.get("hvac_modes")
@ -121,6 +124,7 @@ async def test_set_operation_bad_attr_and_state(hass, mqtt_mock, caplog):
Also check the state.
"""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.state == "off"
@ -136,6 +140,7 @@ async def test_set_operation_bad_attr_and_state(hass, mqtt_mock, caplog):
async def test_set_operation(hass, mqtt_mock):
"""Test setting of new operation mode."""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.state == "off"
@ -151,6 +156,7 @@ async def test_set_operation_pessimistic(hass, mqtt_mock):
config = copy.deepcopy(DEFAULT_CONFIG)
config["climate"]["mode_state_topic"] = "mode-state"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.state == "unknown"
@ -173,6 +179,7 @@ async def test_set_operation_with_power_command(hass, mqtt_mock):
config = copy.deepcopy(DEFAULT_CONFIG)
config["climate"]["power_command_topic"] = "power-command"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.state == "off"
@ -196,6 +203,7 @@ async def test_set_operation_with_power_command(hass, mqtt_mock):
async def test_set_fan_mode_bad_attr(hass, mqtt_mock, caplog):
"""Test setting fan mode without required attribute."""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("fan_mode") == "low"
@ -213,6 +221,7 @@ async def test_set_fan_mode_pessimistic(hass, mqtt_mock):
config = copy.deepcopy(DEFAULT_CONFIG)
config["climate"]["fan_mode_state_topic"] = "fan-state"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("fan_mode") is None
@ -233,6 +242,7 @@ async def test_set_fan_mode_pessimistic(hass, mqtt_mock):
async def test_set_fan_mode(hass, mqtt_mock):
"""Test setting of new fan mode."""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("fan_mode") == "low"
@ -245,6 +255,7 @@ async def test_set_fan_mode(hass, mqtt_mock):
async def test_set_swing_mode_bad_attr(hass, mqtt_mock, caplog):
"""Test setting swing mode without required attribute."""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("swing_mode") == "off"
@ -262,6 +273,7 @@ async def test_set_swing_pessimistic(hass, mqtt_mock):
config = copy.deepcopy(DEFAULT_CONFIG)
config["climate"]["swing_mode_state_topic"] = "swing-state"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("swing_mode") is None
@ -282,6 +294,7 @@ async def test_set_swing_pessimistic(hass, mqtt_mock):
async def test_set_swing(hass, mqtt_mock):
"""Test setting of new swing mode."""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("swing_mode") == "off"
@ -294,6 +307,7 @@ async def test_set_swing(hass, mqtt_mock):
async def test_set_target_temperature(hass, mqtt_mock):
"""Test setting the target temperature."""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("temperature") == 21
@ -326,6 +340,7 @@ async def test_set_target_temperature_pessimistic(hass, mqtt_mock):
config = copy.deepcopy(DEFAULT_CONFIG)
config["climate"]["temperature_state_topic"] = "temperature-state"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("temperature") is None
@ -346,6 +361,7 @@ async def test_set_target_temperature_pessimistic(hass, mqtt_mock):
async def test_set_target_temperature_low_high(hass, mqtt_mock):
"""Test setting the low/high target temperature."""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
await common.async_set_temperature(
hass, target_temp_low=20, target_temp_high=23, entity_id=ENTITY_CLIMATE
@ -363,6 +379,7 @@ async def test_set_target_temperature_low_highpessimistic(hass, mqtt_mock):
config["climate"]["temperature_low_state_topic"] = "temperature-low-state"
config["climate"]["temperature_high_state_topic"] = "temperature-high-state"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("target_temp_low") is None
@ -398,6 +415,7 @@ async def test_receive_mqtt_temperature(hass, mqtt_mock):
config = copy.deepcopy(DEFAULT_CONFIG)
config["climate"]["current_temperature_topic"] = "current_temperature"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
async_fire_mqtt_message(hass, "current_temperature", "47")
state = hass.states.get(ENTITY_CLIMATE)
@ -409,6 +427,7 @@ async def test_set_away_mode_pessimistic(hass, mqtt_mock):
config = copy.deepcopy(DEFAULT_CONFIG)
config["climate"]["away_mode_state_topic"] = "away-state"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("preset_mode") is None
@ -437,6 +456,7 @@ async def test_set_away_mode(hass, mqtt_mock):
config["climate"]["payload_off"] = "AUS"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("preset_mode") is None
@ -467,6 +487,7 @@ async def test_set_hvac_action(hass, mqtt_mock):
config = copy.deepcopy(DEFAULT_CONFIG)
config["climate"]["action_topic"] = "action"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("hvac_action") is None
@ -481,6 +502,7 @@ async def test_set_hold_pessimistic(hass, mqtt_mock):
config = copy.deepcopy(DEFAULT_CONFIG)
config["climate"]["hold_state_topic"] = "hold-state"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("hold_mode") is None
@ -501,6 +523,7 @@ async def test_set_hold_pessimistic(hass, mqtt_mock):
async def test_set_hold(hass, mqtt_mock):
"""Test setting the hold mode."""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("preset_mode") is None
@ -525,6 +548,7 @@ async def test_set_hold(hass, mqtt_mock):
async def test_set_preset_mode_twice(hass, mqtt_mock):
"""Test setting of the same mode twice only publishes once."""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("preset_mode") is None
@ -543,6 +567,7 @@ async def test_set_aux_pessimistic(hass, mqtt_mock):
config = copy.deepcopy(DEFAULT_CONFIG)
config["climate"]["aux_state_topic"] = "aux-state"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("aux_heat") == "off"
@ -567,6 +592,7 @@ async def test_set_aux_pessimistic(hass, mqtt_mock):
async def test_set_aux(hass, mqtt_mock):
"""Test setting of the aux heating."""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("aux_heat") == "off"
@ -612,6 +638,7 @@ async def test_set_target_temperature_low_high_with_templates(hass, mqtt_mock, c
config["climate"]["temperature_high_state_template"] = "{{ value_json.temp_high }}"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
@ -658,6 +685,7 @@ async def test_set_with_templates(hass, mqtt_mock, caplog):
config["climate"]["current_temperature_topic"] = "current-temperature"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
# Operation Mode
state = hass.states.get(ENTITY_CLIMATE)
@ -745,6 +773,7 @@ async def test_min_temp_custom(hass, mqtt_mock):
config["climate"]["min_temp"] = 26
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
min_temp = state.attributes.get("min_temp")
@ -759,6 +788,7 @@ async def test_max_temp_custom(hass, mqtt_mock):
config["climate"]["max_temp"] = 60
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
max_temp = state.attributes.get("max_temp")
@ -773,6 +803,7 @@ async def test_temp_step_custom(hass, mqtt_mock):
config["climate"]["temp_step"] = 0.01
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
temp_step = state.attributes.get("target_temp_step")
@ -788,6 +819,7 @@ async def test_temperature_unit(hass, mqtt_mock):
config["climate"]["current_temperature_topic"] = "current_temperature"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
async_fire_mqtt_message(hass, "current_temperature", "77")
@ -945,6 +977,7 @@ async def test_entity_debug_info_message(hass, mqtt_mock):
async def test_precision_default(hass, mqtt_mock):
"""Test that setting precision to tenths works as intended."""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
await common.async_set_temperature(
hass, temperature=23.67, entity_id=ENTITY_CLIMATE
@ -959,6 +992,7 @@ async def test_precision_halves(hass, mqtt_mock):
config = copy.deepcopy(DEFAULT_CONFIG)
config["climate"]["precision"] = 0.5
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
await common.async_set_temperature(
hass, temperature=23.67, entity_id=ENTITY_CLIMATE
@ -973,6 +1007,7 @@ async def test_precision_whole(hass, mqtt_mock):
config = copy.deepcopy(DEFAULT_CONFIG)
config["climate"]["precision"] = 1.0
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
await common.async_set_temperature(
hass, temperature=23.67, entity_id=ENTITY_CLIMATE