Cloud: Make sure on_connect forwards platform only once (#24582)
* Make sure on_connect forwards platform only once * Make sure right handlerpull/24609/head
parent
ca70b96005
commit
f382be4c15
|
@ -191,8 +191,16 @@ async def async_setup(hass, config):
|
|||
hass.helpers.service.async_register_admin_service(
|
||||
DOMAIN, SERVICE_REMOTE_DISCONNECT, _service_handler)
|
||||
|
||||
loaded_binary_sensor = False
|
||||
|
||||
async def _on_connect():
|
||||
"""Discover RemoteUI binary sensor."""
|
||||
nonlocal loaded_binary_sensor
|
||||
|
||||
if loaded_binary_sensor:
|
||||
return
|
||||
|
||||
loaded_binary_sensor = True
|
||||
hass.async_create_task(hass.helpers.discovery.async_load_platform(
|
||||
'binary_sensor', DOMAIN, {}, config))
|
||||
|
||||
|
|
|
@ -154,3 +154,25 @@ async def test_setup_setup_cloud_user(hass, hass_storage):
|
|||
|
||||
assert cloud_user
|
||||
assert cloud_user.groups[0].id == GROUP_ID_ADMIN
|
||||
|
||||
|
||||
async def test_on_connect(hass, mock_cloud_fixture):
|
||||
"""Test cloud on connect triggers."""
|
||||
cl = hass.data['cloud']
|
||||
|
||||
assert len(cl.iot._on_connect) == 4
|
||||
|
||||
assert len(hass.states.async_entity_ids('binary_sensor')) == 0
|
||||
|
||||
assert 'async_setup' in str(cl.iot._on_connect[-1])
|
||||
await cl.iot._on_connect[-1]()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(hass.states.async_entity_ids('binary_sensor')) == 1
|
||||
|
||||
with patch('homeassistant.helpers.discovery.async_load_platform',
|
||||
side_effect=mock_coro) as mock_load:
|
||||
await cl.iot._on_connect[-1]()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(mock_load.mock_calls) == 0
|
||||
|
|
Loading…
Reference in New Issue