Fix cloud connected signal only firing once (#92009)

pull/92019/head
Erik Montnemery 2023-04-25 18:15:27 +02:00 committed by GitHub
parent dae05a0c93
commit 933761d425
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View File

@ -272,8 +272,8 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
if subscription_info := await async_subscription_info(cloud): if subscription_info := await async_subscription_info(cloud):
async_manage_legacy_subscription_issue(hass, subscription_info) async_manage_legacy_subscription_issue(hass, subscription_info)
async def _on_connect(): async def _discover_platforms():
"""Discover RemoteUI binary sensor.""" """Discover platforms."""
nonlocal loaded nonlocal loaded
# Prevent multiple discovery # Prevent multiple discovery
@ -285,6 +285,10 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
await async_load_platform(hass, Platform.STT, DOMAIN, {}, config) await async_load_platform(hass, Platform.STT, DOMAIN, {}, config)
await async_load_platform(hass, Platform.TTS, DOMAIN, {}, config) await async_load_platform(hass, Platform.TTS, DOMAIN, {}, config)
async def _on_connect():
"""Handle cloud connect."""
await _discover_platforms()
async_dispatcher_send( async_dispatcher_send(
hass, SIGNAL_CLOUD_CONNECTION_STATE, CloudConnectionState.CLOUD_CONNECTED hass, SIGNAL_CLOUD_CONNECTION_STATE, CloudConnectionState.CLOUD_CONNECTED
) )

View File

@ -160,7 +160,7 @@ async def test_on_connect(hass: HomeAssistant, mock_cloud_fixture) -> None:
assert len(mock_load.mock_calls) == 0 assert len(mock_load.mock_calls) == 0
assert len(cloud_states) == 1 assert len(cloud_states) == 2
assert cloud_states[-1] == cloud.CloudConnectionState.CLOUD_CONNECTED assert cloud_states[-1] == cloud.CloudConnectionState.CLOUD_CONNECTED
assert len(cl.iot._on_disconnect) == 2 assert len(cl.iot._on_disconnect) == 2
@ -168,7 +168,7 @@ async def test_on_connect(hass: HomeAssistant, mock_cloud_fixture) -> None:
await cl.iot._on_disconnect[-1]() await cl.iot._on_disconnect[-1]()
await hass.async_block_till_done() await hass.async_block_till_done()
assert len(cloud_states) == 2 assert len(cloud_states) == 3
assert cloud_states[-1] == cloud.CloudConnectionState.CLOUD_DISCONNECTED assert cloud_states[-1] == cloud.CloudConnectionState.CLOUD_DISCONNECTED