Coverage for coherence/upnp/devices/control_point.py : 39%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# Licensed under the MIT license # http://opensource.org/licenses/mit-license.php
# Copyright 2006-2010 Frank Scholz <dev@coherence-project.org>
InternetGatewayDeviceClient
elif isinstance(self.callback, str): louie.send(self.callback, None, device=device)
device.host == self.pattern): self.fire(device) device.friendly_name == self.pattern): self.fire(device) device.get_uuid() == self.pattern):
self.info('ControlPoint [check device]: {}'.format(device)) self.check_device(device)
'Coherence.UPnP.Device.detection_completed', louie.Any) 'Coherence.UPnP.Device.remove_client', louie.Any) 'Coherence.UPnP.DeviceClient.detection_completed', louie.Any)
'Coherence.UPnP.Device.detection_completed', louie.Any) 'Coherence.UPnP.Device.remove_client', louie.Any) 'Coherence.UPnP.DeviceClient.detection_completed', louie.Any)
if device_type in self.auto_client: return self.auto_client.append(device_type) for device in self.get_devices(): self.check_device(device)
self.info('ControlPoint.browse: {}'.format(device)) device = self.coherence.get_device_with_usn(device.get_usn()) if not device: return self.check_device(device)
query.check(device) query.callback(None) else:
sender=louie.sender.Any, weak=True): """ wrapper method around louie.connect """ louie.connect(receiver, signal=signal, sender=sender, weak=weak)
sender=louie.sender.Any, weak=True): """ wrapper method around louie.disconnect """ louie.disconnect(receiver, signal=signal, sender=sender, weak=weak)
return self.coherence.get_device_with_id(id)
return self.coherence.get_device_by_host(host)
device.get_friendly_name(), device.get_device_type(), device.client) device.get_friendly_name())
client = MediaRendererClient(device) client = InternetGatewayDeviceClient(device)
client.device_type, udn) 'Coherence.UPnP.ControlPoint.%s.detected' % client.device_type, None, client=client, udn=udn)
louie.send( 'Coherence.UPnP.ControlPoint.%s.removed' % client.device_type, None, udn=udn) self.info("removed %s %s", client.device_type, client.device.get_friendly_name()) client.remove()
self.info('propagate: %r', event) if event.get_sid() in service.subscribers: try: service.subscribers[event.get_sid()].process_event(event) except Exception as msg: self.debug(msg) self.debug(traceback.format_exc()) pass
def got_result(result): print(result)
def got_error(result): print("error", result)
try: f = open(path) data = f.read() f.close() headers = { b"Content-Type": b"application/octet-stream", b"Content-Length": bytes(str(len(data)), encoding='utf-8') } df = client.getPage( url, method=b"POST", headers=headers, postdata=data) df.addCallback(got_result) df.addErrback(got_error) return df except IOError: pass
print("list_devices") r = [] for device in self.control_point.get_devices(): # print(device.get_friendly_name(), device.get_service_type(), # device.get_location(), device.get_id()) d = {'friendly_name': device.get_friendly_name(), 'device_type': device.get_device_type(), 'location': str(device.get_location()), 'id': str(device.get_id())} r.append(d) return r
print("mute") device = self.control_point.get_device_with_id(device_id) if device is not None: client = device.get_client() client.rendering_control.set_mute(desired_mute=1) return "Ok" return "Error"
print("unmute", device_id) device = self.control_point.get_device_with_id(device_id) if device is not None: client = device.get_client() client.rendering_control.set_mute(desired_mute=0) return "Ok" return "Error"
print("set volume") device = self.control_point.get_device_with_id(device_id) if device is not None: client = device.get_client() client.rendering_control.set_volume(desired_volume=volume) return "Ok" return "Error"
print("play") device = self.control_point.get_device_with_id(device_id) if device is not None: client = device.get_client() client.av_transport.play() return "Ok" return "Error"
print("pause") device = self.control_point.get_device_with_id(device_id) if device is not None: client = device.get_client() client.av_transport.pause() return "Ok" return "Error"
print("stop") device = self.control_point.get_device_with_id(device_id) if device is not None: client = device.get_client() client.av_transport.stop() return "Ok" return "Error"
print("next") device = self.control_point.get_device_with_id(device_id) if device is not None: client = device.get_client() next(client.av_transport) return "Ok" return "Error"
print("previous") device = self.control_point.get_device_with_id(device_id) if device is not None: client = device.get_client() client.av_transport.previous() return "Ok" return "Error"
print("set_av_transport_uri") device = self.control_point.get_device_with_id(device_id) if device is not None: client = device.get_client() client.av_transport.set_av_transport_uri(current_uri=uri) return "Ok" return "Error"
print("create_object", arguments) device = self.control_point.get_device_with_id(device_id) if device is not None: client = device.get_client() client.content_directory.create_object(container_id, arguments) return "Ok" return "Error"
print("import_resource", source_uri, destination_uri) device = self.control_point.get_device_with_id(device_id) if device is not None: client = device.get_client() client.content_directory.import_resource(source_uri, destination_uri) return "Ok" return "Error"
print("put_resource", url, path) self.control_point.put_resource(url, path) return "Ok"
print("ping") return "Ok"
from twisted.web import server r = XMLRPC(control_point) print("XMLRPC-API on port %d ready" % port) reactor.listenTCP(port, server.Site(r))
config = {} config['logmode'] = 'warning' config['serverport'] = 30020 from coherence.base import Coherence
ctrl = ControlPoint(Coherence(config), auto_client=[])
def show_devices(): print("show_devices") for d in ctrl.get_devices(): print(d, d.get_id())
def the_result(r): print("result", r, r.get_id())
def query_devices(): print("query_devices") ctrl.add_query(DeviceQuery('host', '192.168.0.1', the_result))
def query_devices2(): print("query_devices with timeout") ctrl.add_query( DeviceQuery('host', '192.168.0.1', the_result, timeout=10, oneshot=False))
def stop_reactor(*args): reactor.stop() print("Stoped reactor successfully")
reactor.callLater(2, show_devices) reactor.callLater(3, query_devices) reactor.callLater(4, query_devices2) reactor.callLater(5, ctrl.add_query, DeviceQuery( 'friendly_name', 'Coherence Test Content', the_result, timeout=10, oneshot=False)) reactor.callLater(6, stop_reactor)
reactor.run() |