def activate(self, connection, device=None, specific_object=None): if not isinstance(connection, dbus_helpers(INTERFACES[18])): raise TypeError connection_path = connection.object_path device_path = dbus.ObjectPath('/') specific_object_path = dbus.ObjectPath('/') settings = connection.settings if connection.type in ('802-3-ethernet', '802-11-wireless'): LOGGER.debug('Finding device for %s', connection_path) devices = [device for device in self.devices if device.managed and device.raw_type == connection.device_type] device = devices[0] if device: LOGGER.debug('%s using %s', connection_path, device_path) device_path = device.object_path else: LOGGER.error('No device found for %s', connection_path) return self.ActivateConnection(connection_path, device_path, specific_object_path, dbus_interface=INTERFACES[0])
def activate(self, connection, device=None, specific_object=None): if not isinstance(connection, dbus_helpers(INTERFACES[11])): raise TypeError service_name = connection.requested_bus_name connection_path = connection.object_path settings = connection.settings device_path = dbus.ObjectPath('/') if connection.type in ('802-3-ethernet', '802-11-wireless'): LOGGER.debug('Finding device for %s', connection_path) device = [device for device in self.devices if device.managed and device.type == connection.device_type][0] if device: LOGGER.debug('%s using %s', connection_path, device_path) device_path = device.object_path else: LOGGER.error('No device found for %s', connection_path) specific_object_path = dbus.ObjectPath('/') if connection.type == '802-11-wireless': LOGGER.debug('Finding AP for %s', device_path) ssid = settings[connection.type]['ssid'] aps = [ap for ap in device.access_points if ap['Ssid'] == ssid] if aps: specific_object = max(aps, key=lambda ap: ap['Strength']) if specific_object: LOGGER.debug('%s using %s', device_path, specific_object_path) specific_object_path = specific_object.object_path else: LOGGER.error('No AP found for %s', device_path) return self.ActivateConnection(service_name, connection_path, device_path, specific_object_path, dbus_interface=INTERFACES[0])