async def list_targets(self) -> List[TargetDescription]: (_, companions) = await asyncio.gather( self._spawn_notifier(), self.direct_companion_manager.get_companions()) 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=self.local_targets_manager.get_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", 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", 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", 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", host="remotehost", port=2, is_local=False), screen_dimensions=None, ), ], )