Intelligent timeout handler for setup/bootstrap (#38329)

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
authored and GitHub committed 2020-08-05 14:58:19 +02:00
1 parent caca762088
commit c291d4aa7d
21 files changed
+901 -89

No files matched your search

@@ -133,6 +133,7 @@ async def test_get_action_capabilities(hass, device_reg, entity_reg):
device_id=device_entry.id,
)
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
await hass.async_block_till_done()
expected_capabilities = {
"arm_away": {"extra_fields": []},
@@ -170,6 +171,7 @@ async def test_get_action_capabilities_arm_code(hass, device_reg, entity_reg):
device_id=device_entry.id,
)
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
await hass.async_block_till_done()
expected_capabilities = {
"arm_away": {
@@ -267,6 +269,8 @@ async def test_action(hass):
},
)
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
await hass.async_block_till_done()
assert (
hass.states.get("alarm_control_panel.alarm_no_arm_code").state == STATE_UNKNOWN
)
@@ -60,6 +60,7 @@ async def test_get_conditions(hass, device_reg, entity_reg):
)
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
await hass.async_block_till_done()
expected_conditions = [
{
@@ -60,6 +60,7 @@ async def test_get_triggers(hass, device_reg, entity_reg):
)
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
await hass.async_block_till_done()
expected_triggers = [
{
@@ -46,6 +46,7 @@ async def test_get_actions(hass, device_reg, entity_reg):
DOMAIN, "test", ent.unique_id, device_id=device_entry.id
)
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
await hass.async_block_till_done()
expected_actions = [
{
@@ -87,6 +88,7 @@ async def test_get_actions_tilt(hass, device_reg, entity_reg):
DOMAIN, "test", ent.unique_id, device_id=device_entry.id
)
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
await hass.async_block_till_done()
expected_actions = [
{
@@ -140,6 +142,7 @@ async def test_get_actions_set_pos(hass, device_reg, entity_reg):
DOMAIN, "test", ent.unique_id, device_id=device_entry.id
)
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
await hass.async_block_till_done()
expected_actions = [
{
@@ -169,6 +172,7 @@ async def test_get_actions_set_tilt_pos(hass, device_reg, entity_reg):
DOMAIN, "test", ent.unique_id, device_id=device_entry.id
)
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
await hass.async_block_till_done()
expected_actions = [
{
@@ -217,6 +221,7 @@ async def test_get_action_capabilities(hass, device_reg, entity_reg):
)
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
await hass.async_block_till_done()
actions = await async_get_device_automations(hass, "action", device_entry.id)
assert len(actions) == 3 # open, close, stop
@@ -244,6 +249,7 @@ async def test_get_action_capabilities_set_pos(hass, device_reg, entity_reg):
)
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
await hass.async_block_till_done()
expected_capabilities = {
"extra_fields": [
@@ -286,6 +292,7 @@ async def test_get_action_capabilities_set_tilt_pos(hass, device_reg, entity_reg
)
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
await hass.async_block_till_done()
expected_capabilities = {
"extra_fields": [
@@ -352,6 +359,7 @@ async def test_action(hass):
]
},
)
await hass.async_block_till_done()
open_calls = async_mock_service(hass, "cover", "open_cover")
close_calls = async_mock_service(hass, "cover", "close_cover")
@@ -408,6 +416,7 @@ async def test_action_tilt(hass):
]
},
)
await hass.async_block_till_done()
open_calls = async_mock_service(hass, "cover", "open_cover_tilt")
close_calls = async_mock_service(hass, "cover", "close_cover_tilt")
@@ -468,6 +477,7 @@ async def test_action_set_position(hass):
]
},
)
await hass.async_block_till_done()
cover_pos_calls = async_mock_service(hass, "cover", "set_cover_position")
tilt_pos_calls = async_mock_service(hass, "cover", "set_cover_tilt_position")
+1
View File
@@ -366,6 +366,7 @@ async def test_reconnect(hass, monkeypatch, mock_connection_factory):
protocol.wait_closed = wait_closed
await async_setup_component(hass, "sensor", {"sensor": config})
await hass.async_block_till_done()
assert connection_factory.call_count == 1
+20
View File
@@ -104,6 +104,7 @@ async def test_valid_config_with_info(hass):
}
},
)
await hass.async_block_till_done()
async def test_valid_config_no_name(hass):
@@ -114,6 +115,7 @@ async def test_valid_config_no_name(hass):
"switch",
{"switch": {"platform": "flux", "lights": ["light.desk", "light.lamp"]}},
)
await hass.async_block_till_done()
async def test_invalid_config_no_lights(hass):
@@ -122,6 +124,7 @@ async def test_invalid_config_no_lights(hass):
assert await async_setup_component(
hass, "switch", {"switch": {"platform": "flux", "name": "flux"}}
)
await hass.async_block_till_done()
async def test_flux_when_switch_is_off(hass, legacy_patchable_time):
@@ -168,6 +171,7 @@ async def test_flux_when_switch_is_off(hass, legacy_patchable_time):
}
},
)
await hass.async_block_till_done()
async_fire_time_changed(hass, test_time)
await hass.async_block_till_done()
@@ -218,6 +222,7 @@ async def test_flux_before_sunrise(hass, legacy_patchable_time):
}
},
)
await hass.async_block_till_done()
turn_on_calls = async_mock_service(hass, light.DOMAIN, SERVICE_TURN_ON)
await common.async_turn_on(hass, "switch.flux")
await hass.async_block_till_done()
@@ -271,6 +276,7 @@ async def test_flux_before_sunrise_known_location(hass, legacy_patchable_time):
}
},
)
await hass.async_block_till_done()
turn_on_calls = async_mock_service(hass, light.DOMAIN, SERVICE_TURN_ON)
await common.async_turn_on(hass, "switch.flux")
await hass.async_block_till_done()
@@ -325,6 +331,7 @@ async def test_flux_after_sunrise_before_sunset(hass, legacy_patchable_time):
}
},
)
await hass.async_block_till_done()
turn_on_calls = async_mock_service(hass, light.DOMAIN, SERVICE_TURN_ON)
await common.async_turn_on(hass, "switch.flux")
await hass.async_block_till_done()
@@ -380,6 +387,7 @@ async def test_flux_after_sunset_before_stop(hass, legacy_patchable_time):
}
},
)
await hass.async_block_till_done()
turn_on_calls = async_mock_service(hass, light.DOMAIN, SERVICE_TURN_ON)
common.turn_on(hass, "switch.flux")
await hass.async_block_till_done()
@@ -434,6 +442,7 @@ async def test_flux_after_stop_before_sunrise(hass, legacy_patchable_time):
}
},
)
await hass.async_block_till_done()
turn_on_calls = async_mock_service(hass, light.DOMAIN, SERVICE_TURN_ON)
common.turn_on(hass, "switch.flux")
await hass.async_block_till_done()
@@ -490,6 +499,7 @@ async def test_flux_with_custom_start_stop_times(hass, legacy_patchable_time):
}
},
)
await hass.async_block_till_done()
turn_on_calls = async_mock_service(hass, light.DOMAIN, SERVICE_TURN_ON)
common.turn_on(hass, "switch.flux")
await hass.async_block_till_done()
@@ -547,6 +557,7 @@ async def test_flux_before_sunrise_stop_next_day(hass, legacy_patchable_time):
}
},
)
await hass.async_block_till_done()
turn_on_calls = async_mock_service(hass, light.DOMAIN, SERVICE_TURN_ON)
common.turn_on(hass, "switch.flux")
await hass.async_block_till_done()
@@ -608,6 +619,7 @@ async def test_flux_after_sunrise_before_sunset_stop_next_day(
}
},
)
await hass.async_block_till_done()
turn_on_calls = async_mock_service(hass, light.DOMAIN, SERVICE_TURN_ON)
common.turn_on(hass, "switch.flux")
await hass.async_block_till_done()
@@ -669,6 +681,7 @@ async def test_flux_after_sunset_before_midnight_stop_next_day(
}
},
)
await hass.async_block_till_done()
turn_on_calls = async_mock_service(hass, light.DOMAIN, SERVICE_TURN_ON)
common.turn_on(hass, "switch.flux")
await hass.async_block_till_done()
@@ -729,6 +742,7 @@ async def test_flux_after_sunset_after_midnight_stop_next_day(
}
},
)
await hass.async_block_till_done()
turn_on_calls = async_mock_service(hass, light.DOMAIN, SERVICE_TURN_ON)
common.turn_on(hass, "switch.flux")
await hass.async_block_till_done()
@@ -789,6 +803,7 @@ async def test_flux_after_stop_before_sunrise_stop_next_day(
}
},
)
await hass.async_block_till_done()
turn_on_calls = async_mock_service(hass, light.DOMAIN, SERVICE_TURN_ON)
common.turn_on(hass, "switch.flux")
await hass.async_block_till_done()
@@ -846,6 +861,7 @@ async def test_flux_with_custom_colortemps(hass, legacy_patchable_time):
}
},
)
await hass.async_block_till_done()
turn_on_calls = async_mock_service(hass, light.DOMAIN, SERVICE_TURN_ON)
common.turn_on(hass, "switch.flux")
await hass.async_block_till_done()
@@ -902,6 +918,7 @@ async def test_flux_with_custom_brightness(hass, legacy_patchable_time):
}
},
)
await hass.async_block_till_done()
turn_on_calls = async_mock_service(hass, light.DOMAIN, SERVICE_TURN_ON)
common.turn_on(hass, "switch.flux")
await hass.async_block_till_done()
@@ -974,6 +991,7 @@ async def test_flux_with_multiple_lights(hass, legacy_patchable_time):
}
},
)
await hass.async_block_till_done()
turn_on_calls = async_mock_service(hass, light.DOMAIN, SERVICE_TURN_ON)
common.turn_on(hass, "switch.flux")
await hass.async_block_till_done()
@@ -1033,6 +1051,7 @@ async def test_flux_with_mired(hass, legacy_patchable_time):
}
},
)
await hass.async_block_till_done()
turn_on_calls = async_mock_service(hass, light.DOMAIN, SERVICE_TURN_ON)
common.turn_on(hass, "switch.flux")
await hass.async_block_till_done()
@@ -1085,6 +1104,7 @@ async def test_flux_with_rgb(hass, legacy_patchable_time):
}
},
)
await hass.async_block_till_done()
turn_on_calls = async_mock_service(hass, light.DOMAIN, SERVICE_TURN_ON)
await common.async_turn_on(hass, "switch.flux")
await hass.async_block_till_done()
@@ -34,6 +34,7 @@ async def test_get_actions_support_open(hass, device_reg, entity_reg):
platform = getattr(hass.components, f"test.{DOMAIN}")
platform.init()
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
await hass.async_block_till_done()
config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass)
@@ -77,6 +78,7 @@ async def test_get_actions_not_support_open(hass, device_reg, entity_reg):
platform = getattr(hass.components, f"test.{DOMAIN}")
platform.init()
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
await hass.async_block_till_done()
config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass)
@@ -146,6 +148,7 @@ async def test_action(hass):
]
},
)
await hass.async_block_till_done()
lock_calls = async_mock_service(hass, "lock", "lock")
unlock_calls = async_mock_service(hass, "lock", "unlock")