Do async_setup_platform in background (#36244)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Paulus SchoutsenandJ. Nick Koston authored and GitHub committed 2020-05-31 22:18:30 -07:00
1 parent d488c779fc
commit 276f3afb00
161 files changed
+1184 -305

No files matched your search

@@ -76,12 +76,11 @@ async def test_valid_conf(hass):
@pytest.fixture
def setup_comp_1(hass):
async def setup_comp_1(hass):
"""Initialize components."""
hass.config.units = METRIC_SYSTEM
assert hass.loop.run_until_complete(
async_setup_component(hass, "homeassistant", {})
)
assert await async_setup_component(hass, "homeassistant", {})
await hass.async_block_till_done()
async def test_heater_input_boolean(hass, setup_comp_1):
@@ -104,6 +103,7 @@ async def test_heater_input_boolean(hass, setup_comp_1):
}
},
)
await hass.async_block_till_done()
assert STATE_OFF == hass.states.get(heater_switch).state
@@ -122,6 +122,7 @@ async def test_heater_switch(hass, setup_comp_1):
assert await async_setup_component(
hass, switch.DOMAIN, {"switch": {"platform": "test"}}
)
await hass.async_block_till_done()
heater_switch = switch_1.entity_id
assert await async_setup_component(
@@ -154,27 +155,26 @@ def _setup_sensor(hass, temp):
@pytest.fixture
def setup_comp_2(hass):
async def setup_comp_2(hass):
"""Initialize components."""
hass.config.units = METRIC_SYSTEM
assert hass.loop.run_until_complete(
async_setup_component(
hass,
DOMAIN,
{
"climate": {
"platform": "generic_thermostat",
"name": "test",
"cold_tolerance": 2,
"hot_tolerance": 4,
"heater": ENT_SWITCH,
"target_sensor": ENT_SENSOR,
"away_temp": 16,
"initial_hvac_mode": HVAC_MODE_HEAT,
}
},
)
assert await async_setup_component(
hass,
DOMAIN,
{
"climate": {
"platform": "generic_thermostat",
"name": "test",
"cold_tolerance": 2,
"hot_tolerance": 4,
"heater": ENT_SWITCH,
"target_sensor": ENT_SENSOR,
"away_temp": 16,
"initial_hvac_mode": HVAC_MODE_HEAT,
}
},
)
await hass.async_block_till_done()
async def test_setup_defaults_to_unknown(hass):
@@ -195,6 +195,7 @@ async def test_setup_defaults_to_unknown(hass):
}
},
)
await hass.async_block_till_done()
assert HVAC_MODE_OFF == hass.states.get(ENTITY).state
@@ -288,6 +289,7 @@ async def test_sensor_unknown(hass):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("climate.unknown")
assert state.attributes.get("current_temperature") is None
@@ -307,6 +309,7 @@ async def test_sensor_unavailable(hass):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("climate.unavailable")
assert state.attributes.get("current_temperature") is None
@@ -438,28 +441,27 @@ def _setup_switch(hass, is_on):
@pytest.fixture
def setup_comp_3(hass):
async def setup_comp_3(hass):
"""Initialize components."""
hass.config.temperature_unit = TEMP_CELSIUS
assert hass.loop.run_until_complete(
async_setup_component(
hass,
DOMAIN,
{
"climate": {
"platform": "generic_thermostat",
"name": "test",
"cold_tolerance": 2,
"hot_tolerance": 4,
"away_temp": 30,
"heater": ENT_SWITCH,
"target_sensor": ENT_SENSOR,
"ac_mode": True,
"initial_hvac_mode": HVAC_MODE_COOL,
}
},
)
assert await async_setup_component(
hass,
DOMAIN,
{
"climate": {
"platform": "generic_thermostat",
"name": "test",
"cold_tolerance": 2,
"hot_tolerance": 4,
"away_temp": 30,
"heater": ENT_SWITCH,
"target_sensor": ENT_SENSOR,
"ac_mode": True,
"initial_hvac_mode": HVAC_MODE_COOL,
}
},
)
await hass.async_block_till_done()
async def test_set_target_temp_ac_off(hass, setup_comp_3):
@@ -584,28 +586,27 @@ async def test_no_state_change_when_operation_mode_off_2(hass, setup_comp_3):
@pytest.fixture
def setup_comp_4(hass):
async def setup_comp_4(hass):
"""Initialize components."""
hass.config.temperature_unit = TEMP_CELSIUS
assert hass.loop.run_until_complete(
async_setup_component(
hass,
DOMAIN,
{
"climate": {
"platform": "generic_thermostat",
"name": "test",
"cold_tolerance": 0.3,
"hot_tolerance": 0.3,
"heater": ENT_SWITCH,
"target_sensor": ENT_SENSOR,
"ac_mode": True,
"min_cycle_duration": datetime.timedelta(minutes=10),
"initial_hvac_mode": HVAC_MODE_COOL,
}
},
)
assert await async_setup_component(
hass,
DOMAIN,
{
"climate": {
"platform": "generic_thermostat",
"name": "test",
"cold_tolerance": 0.3,
"hot_tolerance": 0.3,
"heater": ENT_SWITCH,
"target_sensor": ENT_SENSOR,
"ac_mode": True,
"min_cycle_duration": datetime.timedelta(minutes=10),
"initial_hvac_mode": HVAC_MODE_COOL,
}
},
)
await hass.async_block_till_done()
async def test_temp_change_ac_trigger_on_not_long_enough(hass, setup_comp_4):
@@ -695,28 +696,27 @@ async def test_mode_change_ac_trigger_on_not_long_enough(hass, setup_comp_4):
@pytest.fixture
def setup_comp_5(hass):
async def setup_comp_5(hass):
"""Initialize components."""
hass.config.temperature_unit = TEMP_CELSIUS
assert hass.loop.run_until_complete(
async_setup_component(
hass,
DOMAIN,
{
"climate": {
"platform": "generic_thermostat",
"name": "test",
"cold_tolerance": 0.3,
"hot_tolerance": 0.3,
"heater": ENT_SWITCH,
"target_sensor": ENT_SENSOR,
"ac_mode": True,
"min_cycle_duration": datetime.timedelta(minutes=10),
"initial_hvac_mode": HVAC_MODE_COOL,
}
},
)
assert await async_setup_component(
hass,
DOMAIN,
{
"climate": {
"platform": "generic_thermostat",
"name": "test",
"cold_tolerance": 0.3,
"hot_tolerance": 0.3,
"heater": ENT_SWITCH,
"target_sensor": ENT_SENSOR,
"ac_mode": True,
"min_cycle_duration": datetime.timedelta(minutes=10),
"initial_hvac_mode": HVAC_MODE_COOL,
}
},
)
await hass.async_block_till_done()
async def test_temp_change_ac_trigger_on_not_long_enough_2(hass, setup_comp_5):
@@ -806,27 +806,26 @@ async def test_mode_change_ac_trigger_on_not_long_enough_2(hass, setup_comp_5):
@pytest.fixture
def setup_comp_6(hass):
async def setup_comp_6(hass):
"""Initialize components."""
hass.config.temperature_unit = TEMP_CELSIUS
assert hass.loop.run_until_complete(
async_setup_component(
hass,
DOMAIN,
{
"climate": {
"platform": "generic_thermostat",
"name": "test",
"cold_tolerance": 0.3,
"hot_tolerance": 0.3,
"heater": ENT_SWITCH,
"target_sensor": ENT_SENSOR,
"min_cycle_duration": datetime.timedelta(minutes=10),
"initial_hvac_mode": HVAC_MODE_HEAT,
}
},
)
assert await async_setup_component(
hass,
DOMAIN,
{
"climate": {
"platform": "generic_thermostat",
"name": "test",
"cold_tolerance": 0.3,
"hot_tolerance": 0.3,
"heater": ENT_SWITCH,
"target_sensor": ENT_SENSOR,
"min_cycle_duration": datetime.timedelta(minutes=10),
"initial_hvac_mode": HVAC_MODE_HEAT,
}
},
)
await hass.async_block_till_done()
async def test_temp_change_heater_trigger_off_not_long_enough(hass, setup_comp_6):
@@ -916,31 +915,31 @@ async def test_mode_change_heater_trigger_on_not_long_enough(hass, setup_comp_6)
@pytest.fixture
def setup_comp_7(hass):
async def setup_comp_7(hass):
"""Initialize components."""
hass.config.temperature_unit = TEMP_CELSIUS
assert hass.loop.run_until_complete(
async_setup_component(
hass,
DOMAIN,
{
"climate": {
"platform": "generic_thermostat",
"name": "test",
"cold_tolerance": 0.3,
"hot_tolerance": 0.3,
"heater": ENT_SWITCH,
"target_temp": 25,
"target_sensor": ENT_SENSOR,
"ac_mode": True,
"min_cycle_duration": datetime.timedelta(minutes=15),
"keep_alive": datetime.timedelta(minutes=10),
"initial_hvac_mode": HVAC_MODE_COOL,
}
},
)
assert await async_setup_component(
hass,
DOMAIN,
{
"climate": {
"platform": "generic_thermostat",
"name": "test",
"cold_tolerance": 0.3,
"hot_tolerance": 0.3,
"heater": ENT_SWITCH,
"target_temp": 25,
"target_sensor": ENT_SENSOR,
"ac_mode": True,
"min_cycle_duration": datetime.timedelta(minutes=15),
"keep_alive": datetime.timedelta(minutes=10),
"initial_hvac_mode": HVAC_MODE_COOL,
}
},
)
await hass.async_block_till_done()
async def test_temp_change_ac_trigger_on_long_enough_3(hass, setup_comp_7):
"""Test if turn on signal is sent at keep-alive intervals."""
@@ -994,29 +993,28 @@ def _send_time_changed(hass, now):
@pytest.fixture
def setup_comp_8(hass):
async def setup_comp_8(hass):
"""Initialize components."""
hass.config.temperature_unit = TEMP_CELSIUS
assert hass.loop.run_until_complete(
async_setup_component(
hass,
DOMAIN,
{
"climate": {
"platform": "generic_thermostat",
"name": "test",
"cold_tolerance": 0.3,
"hot_tolerance": 0.3,
"target_temp": 25,
"heater": ENT_SWITCH,
"target_sensor": ENT_SENSOR,
"min_cycle_duration": datetime.timedelta(minutes=15),
"keep_alive": datetime.timedelta(minutes=10),
"initial_hvac_mode": HVAC_MODE_HEAT,
}
},
)
assert await async_setup_component(
hass,
DOMAIN,
{
"climate": {
"platform": "generic_thermostat",
"name": "test",
"cold_tolerance": 0.3,
"hot_tolerance": 0.3,
"target_temp": 25,
"heater": ENT_SWITCH,
"target_sensor": ENT_SENSOR,
"min_cycle_duration": datetime.timedelta(minutes=15),
"keep_alive": datetime.timedelta(minutes=10),
"initial_hvac_mode": HVAC_MODE_HEAT,
}
},
)
await hass.async_block_till_done()
async def test_temp_change_heater_trigger_on_long_enough_2(hass, setup_comp_8):
@@ -1066,29 +1064,28 @@ async def test_temp_change_heater_trigger_off_long_enough_2(hass, setup_comp_8):
@pytest.fixture
def setup_comp_9(hass):
async def setup_comp_9(hass):
"""Initialize components."""
hass.config.temperature_unit = TEMP_FAHRENHEIT
assert hass.loop.run_until_complete(
async_setup_component(
hass,
DOMAIN,
{
"climate": {
"platform": "generic_thermostat",
"name": "test",
"cold_tolerance": 0.3,
"hot_tolerance": 0.3,
"target_temp": 25,
"heater": ENT_SWITCH,
"target_sensor": ENT_SENSOR,
"min_cycle_duration": datetime.timedelta(minutes=15),
"keep_alive": datetime.timedelta(minutes=10),
"precision": 0.1,
}
},
)
assert await async_setup_component(
hass,
DOMAIN,
{
"climate": {
"platform": "generic_thermostat",
"name": "test",
"cold_tolerance": 0.3,
"hot_tolerance": 0.3,
"target_temp": 25,
"heater": ENT_SWITCH,
"target_sensor": ENT_SENSOR,
"min_cycle_duration": datetime.timedelta(minutes=15),
"keep_alive": datetime.timedelta(minutes=10),
"precision": 0.1,
}
},
)
await hass.async_block_till_done()
async def test_precision(hass, setup_comp_9):
@@ -1116,6 +1113,7 @@ async def test_custom_setup_params(hass):
},
)
assert result
await hass.async_block_till_done()
state = hass.states.get(ENTITY)
assert state.attributes.get("min_temp") == MIN_TEMP
assert state.attributes.get("max_temp") == MAX_TEMP
@@ -1150,7 +1148,7 @@ async def test_restore_state(hass):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("climate.test_thermostat")
assert state.attributes[ATTR_TEMPERATURE] == 20
assert state.attributes[ATTR_PRESET_MODE] == PRESET_AWAY
@@ -1188,7 +1186,7 @@ async def test_no_restore_state(hass):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("climate.test_thermostat")
assert state.attributes[ATTR_TEMPERATURE] == 22
assert state.state == HVAC_MODE_OFF