@@ -433,7 +433,9 @@ async def async_update_data() -> Optional[AlexaEntityData]:
433433 ].values ()
434434 auth_info = hass .data [DATA_ALEXAMEDIA ]["accounts" ][email ].get ("auth_info" )
435435 new_devices = hass .data [DATA_ALEXAMEDIA ]["accounts" ][email ]["new_devices" ]
436- should_get_network = False # get_network_details is deprecated
436+ should_get_network = hass .data [DATA_ALEXAMEDIA ]["accounts" ][email ][
437+ "should_get_network"
438+ ]
437439 extended_entity_discovery = hass .data [DATA_ALEXAMEDIA ]["accounts" ][email ][
438440 "options"
439441 ].get (CONF_EXTENDED_ENTITY_DISCOVERY )
@@ -484,6 +486,9 @@ async def async_update_data() -> Optional[AlexaEntityData]:
484486 if entities_to_monitor :
485487 tasks .append (get_entity_data (login_obj , list (entities_to_monitor )))
486488
489+ if should_get_network :
490+ tasks .append (AlexaAPI .get_network_details (login_obj ))
491+
487492 try :
488493 # Note: asyncio.TimeoutError and aiohttp.ClientError are already
489494 # handled by the data update coordinator.
@@ -496,7 +501,34 @@ async def async_update_data() -> Optional[AlexaEntityData]:
496501 * optional_task_results ,
497502 ) = await asyncio .gather (* tasks )
498503
499- if entities_to_monitor :
504+ if should_get_network :
505+ _LOGGER .debug (
506+ "Alexa entities have been loaded. Prepared for discovery."
507+ )
508+ api_devices = optional_task_results .pop ()
509+ if not api_devices :
510+ _LOGGER .warning (
511+ "%s: Alexa API returned an unexpected response while getting connected devices." ,
512+ hide_email (email ),
513+ )
514+ alexa_entities = parse_alexa_entities (api_devices )
515+ hass .data [DATA_ALEXAMEDIA ]["accounts" ][email ]["devices" ].update (
516+ alexa_entities
517+ )
518+ hass .data [DATA_ALEXAMEDIA ]["accounts" ][email ][
519+ "should_get_network"
520+ ] = False
521+
522+ # First run is a special case. Get the state of all entities(including disabled)
523+ # This ensures all entities have state during startup without needing to request coordinator refresh
524+ for type_of_entity , entities in alexa_entities .items ():
525+ if type_of_entity == "guard" or extended_entity_discovery :
526+ for entity in entities :
527+ entities_to_monitor .add (entity .get ("id" ))
528+ entity_state = await get_entity_data (
529+ login_obj , list (entities_to_monitor )
530+ )
531+ elif entities_to_monitor :
500532 entity_state = optional_task_results .pop ()
501533
502534 if new_devices :
0 commit comments