Allow platform unloading (#13784)

* Allow platform unloading

* Add tests

* Add last test
This commit is contained in:
Paulus Schoutsen 2018-04-12 08:28:54 -04:00 committed by Pascal Vizeli
parent dd7e6edf61
commit f47572d3c0
12 changed files with 218 additions and 14 deletions

View file

@ -555,3 +555,29 @@ async def test_setup_entry_platform_not_ready(hass, caplog):
assert len(async_setup_entry.mock_calls) == 1
assert 'Platform test not ready yet' in caplog.text
assert len(mock_call_later.mock_calls) == 1
async def test_reset_cancels_retry_setup(hass):
"""Test that resetting a platform will cancel scheduled a setup retry."""
async_setup_entry = Mock(side_effect=PlatformNotReady)
platform = MockPlatform(
async_setup_entry=async_setup_entry
)
config_entry = MockConfigEntry()
ent_platform = MockEntityPlatform(
hass,
platform_name=config_entry.domain,
platform=platform
)
with patch.object(entity_platform, 'async_call_later') as mock_call_later:
assert not await ent_platform.async_setup_entry(config_entry)
assert len(mock_call_later.mock_calls) == 1
assert len(mock_call_later.return_value.mock_calls) == 0
assert ent_platform._async_cancel_retry_setup is not None
await ent_platform.async_reset()
assert len(mock_call_later.return_value.mock_calls) == 1
assert ent_platform._async_cancel_retry_setup is None