def DisplayPasskey(self, device, passkey, entered): device = dbus_to_py(device) passkey = dbus_to_py(passkey) entered = dbus_to_py(entered) logger.debug("NINO: DisplayPasskey {}, {} entered {})".format( device, passkey, entered))
def SelectConfiguration(self, capabilities): """Invoked by bluez5 when negotiating transport configuration with us. """ capabilities = dbus_to_py(capabilities) logger.debug("Media endpoint capabilities - {}".format(capabilities)) return self._configuration
def NewConnection(self, device, fd, fd_properties): """Called when a new service-level connection has been established. """ device = dbus_to_py(device) fd_properties = dbus_to_py(fd_properties) logger.debug("New RFCOMM service-level connection - device={}, fd={}, " "fd_properties={}".format(device, fd, fd_properties)) fd = fd.take() logger.debug("OS-level fd = {}".format(fd)) # track new socket for later cleanup fds = self._fds.get(device, []) fds.append(fd) self._fds.update({device: fds}) if self.on_connect: self.on_connect(device=device, socket=socket.socket(fileno=fd), fd_properties=fd_properties)
def ClearConfiguration(self, transport): """Invoked by bluez5 when it is forgetting configuration because the transport was stopped. """ transport = dbus_to_py(transport) logger.debug("Bluez5 has cleared the configuration for transport - {}" "".format(transport)) if self.on_transport_state_changed: self.on_transport_state_changed(transport=self._transport, available=False) self._transport = None
def _player_properties_changed(self, interface, changed, invalidated, path): """Fired by the system bus subscription when a Bluez5 object property changes. """ interface = dbus_to_py(interface) path = dbus_to_py(path) changed = dbus_to_py(changed) invalidated = dbus_to_py(invalidated) # ignore the frequent single "position" updates if len(changed) == 1 and "Position" in changed: return logger.debug("SIGNAL: interface={}, path={}, changed={}, " "invalidated={}".format(interface, path, changed, invalidated)) # get adapter object for access to context adapter_path = "/org/bluez/" + path.split("/")[3] adapter = None for k, v in self._connections.items(): if k.path == adapter_path: adapter = k if adapter is None: logger.debug("Adapter not tracked, ignoring signal.") return # report back track update if "Track" in changed: if self.on_track_changed: self.on_track_changed(track=changed["Track"]) # streaming status update if "Status" in changed: self._update_stream_status(adapter=adapter, status=changed["Status"])
def SetConfiguration(self, transport, properties): """Invoked by bluez5 when the transport configuration has been set. """ transport = dbus_to_py(transport) properties = dbus_to_py(properties) logger.debug("Media endpoint config set - {}".format(properties)) logger.debug("Media transport is available - {}".format(transport)) # build media transport try: self._transport = MediaTransport(system_bus=self._system_bus, dbus_path=transport) except Exception as ex: logger.exception("Error fetching media transport.") if self.on_transport_setup_error: self.on_transport_setup_error(ex) return # hand out if self.on_transport_state_changed: self.on_transport_state_changed(transport=self._transport, available=True)
def _propertieschanged(self, interface, changed, invalidated, path): """Fired by the system bus subscription when a Bluez5 object property changes. """ if not self._started: return interface = dbus_to_py(interface) path = dbus_to_py(path) changed = dbus_to_py(changed) invalidated = dbus_to_py(invalidated) logger.debug("SIGNAL: interface={}, path={}, changed={}, " "invalidated={}".format(interface, path, changed, invalidated)) # is it the adapter we have found suitable? if path == self.path: # alert to property changes if self.on_properties_changed: self.io_loop.add_callback( partial(self.on_properties_changed, adapter=self, props=changed)) # react if adapter was powered off (i.e. disconnected) if "Powered" in changed and not changed["Powered"]: self._adapter_proxy = None self._connected = False self._last_address = self._address self._address = None self._last_path = self._path self._path = None self.io_loop.add_callback(callback=self.on_connected_changed, adapter=self, connected=False) self.io_loop.add_callback(callback=self._find_suitable_adapter)
def RequestDisconnection(self, device): """Called when profile is disconnected from device. """ device = dbus_to_py(device) logger.debug( "Profile connections to device {} are now closed.".format(device)) # need to close each socket to the device for fd in self._fds.pop(device, []): try: os.close(fd) except Exception: logger.exception("Unable to close fd {}.".format(fd)) if self.on_disconnect: self.on_disconnect(device=device)
def RequestAuthorization(self, device): device = dbus_to_py(device) logger.debug("NINO: RequestAuthorization {}".format(device))
def RequestConfirmation(self, device, passkey): device = dbus_to_py(device) passkey = dbus_to_py(passkey) logger.debug("NINO: RequestConfirmation {}, {}".format(device, passkey))
def DisplayPinCode(self, device, pincode): device = dbus_to_py(device) pincode = dbus_to_py(pincode) logger.debug("NINO: DisplayPinCode {}, {}".format(device, pincode))
def RequestPasskey(self, device): device = dbus_to_py(device) logger.debug("NINO: RequestPasskey {}".format(device)) return 0000
def RequestPinCode(self, device): device = dbus_to_py(device) logger.debug("NINO: RequestPinCode {}".format(device)) return "0000"
def AuthorizeService(self, device, uuid): device = dbus_to_py(device) uuid = dbus_to_py(uuid) logger.debug("NINO: AuthorizeService {}, {}".format(device, uuid))