Add events on cloud connect and disconnect (#65215)
* Add events on cloud connect and disconnect Signed-off-by: cgtobi <cgtobi@gmail.com> * Use event capture helper Signed-off-by: cgtobi <cgtobi@gmail.com> * Provide listener method instead of public event Signed-off-by: cgtobi <cgtobi@gmail.com> * Add test for disconnect notification Signed-off-by: cgtobi <cgtobi@gmail.com> * Apply suggestions from code review Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Use Enum Signed-off-by: cgtobi <cgtobi@gmail.com> * Add module level api Signed-off-by: cgtobi <cgtobi@gmail.com> * Apply suggestions from code review Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Clean up dead code Signed-off-by: cgtobi <cgtobi@gmail.com> * Flake8 Signed-off-by: cgtobi <cgtobi@gmail.com> * Clean up Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
fda0fbd115
commit
81ad56b8ad
2 changed files with 53 additions and 0 deletions
|
@ -137,6 +137,14 @@ async def test_on_connect(hass, mock_cloud_fixture):
|
|||
|
||||
assert len(hass.states.async_entity_ids("binary_sensor")) == 0
|
||||
|
||||
cloud_states = []
|
||||
|
||||
def handle_state(cloud_state):
|
||||
nonlocal cloud_states
|
||||
cloud_states.append(cloud_state)
|
||||
|
||||
cloud.async_listen_connection_change(hass, handle_state)
|
||||
|
||||
assert "async_setup" in str(cl.iot._on_connect[-1])
|
||||
await cl.iot._on_connect[-1]()
|
||||
await hass.async_block_till_done()
|
||||
|
@ -149,6 +157,17 @@ async def test_on_connect(hass, mock_cloud_fixture):
|
|||
|
||||
assert len(mock_load.mock_calls) == 0
|
||||
|
||||
assert len(cloud_states) == 1
|
||||
assert cloud_states[-1] == cloud.CloudConnectionState.CLOUD_CONNECTED
|
||||
|
||||
assert len(cl.iot._on_disconnect) == 2
|
||||
assert "async_setup" in str(cl.iot._on_disconnect[-1])
|
||||
await cl.iot._on_disconnect[-1]()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(cloud_states) == 2
|
||||
assert cloud_states[-1] == cloud.CloudConnectionState.CLOUD_DISCONNECTED
|
||||
|
||||
|
||||
async def test_remote_ui_url(hass, mock_cloud_fixture):
|
||||
"""Test getting remote ui url."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue