async def list_targets(self) -> List[TargetDescription]: await self._spawn_notifier() (companions, local_targets) = await asyncio.gather( self._direct_companion_manager.get_companions(), self._local_targets_manager.get_local_targets(), ) connected_targets = [ target for target in (await asyncio.gather( *(self._companion_to_target(companion=companion) for companion in companions))) if target is not None ] return merge_connected_targets(local_targets=local_targets, connected_targets=connected_targets)
async def list_targets( self, only: Optional[OnlyFilter] = None) -> List[TargetDescription]: async def _list_local_targets() -> List[TargetDescription]: companion = self._companion if companion is None: return [] return await companion.list_targets(only=only) (local_targets, connected_targets) = await asyncio.gather( _list_local_targets(), _realize_companions( companion_set=self._companion_set, prune_dead_companion=self._prune_dead_companion, logger=self._logger, ), ) return merge_connected_targets(local_targets=local_targets, connected_targets=connected_targets)
def test_merge_connected_targets(self) -> None: merged_targets = merge_connected_targets( local_targets=[ TargetDescription( udid="a", name="aa", state=None, target_type=None, os_version=None, architecture=None, companion_info=None, screen_dimensions=None, ), TargetDescription( udid="b", name="bb", state=None, target_type=None, os_version=None, architecture=None, companion_info=None, screen_dimensions=None, ), TargetDescription( udid="c", name="cc", state=None, target_type=None, os_version=None, architecture=None, companion_info=None, screen_dimensions=None, ), ], connected_targets=[ TargetDescription( udid="a", name="aa", state=None, target_type=None, os_version=None, architecture=None, companion_info=CompanionInfo( udid="a", address=TCPAddress(host="remotehost", port=1), is_local=False, ), screen_dimensions=None, ), TargetDescription( udid="d", name="dd", state=None, target_type=None, os_version=None, architecture=None, companion_info=CompanionInfo( udid="d", address=TCPAddress(host="remotehost", port=2), is_local=False, ), screen_dimensions=None, ), ], ) self.assertEqual( merged_targets, [ TargetDescription( udid="a", name="aa", state=None, target_type=None, os_version=None, architecture=None, companion_info=CompanionInfo( udid="a", address=TCPAddress(host="remotehost", port=1), is_local=False, ), screen_dimensions=None, ), TargetDescription( udid="b", name="bb", state=None, target_type=None, os_version=None, architecture=None, companion_info=None, screen_dimensions=None, ), TargetDescription( udid="c", name="cc", state=None, target_type=None, os_version=None, architecture=None, companion_info=None, screen_dimensions=None, ), TargetDescription( udid="d", name="dd", state=None, target_type=None, os_version=None, architecture=None, companion_info=CompanionInfo( udid="d", address=TCPAddress(host="remotehost", port=2), is_local=False, ), screen_dimensions=None, ), ], )