From 5988c06b1045a2e1193043b490602534e3f3009f Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Tue, 21 Jul 2009 23:45:20 +0200 Subject: [PATCH] use the new methods and remove any device.get_device_type().split(':')[3:5] as it is stupid, can be cached and leads to stupid errors if something is missing. --- .../extern/telepathy/mirabeau_tube_publisher.py | 7 +++---- coherence/tube_service.py | 4 ++-- coherence/upnp/devices/binary_light_client.py | 3 ++- coherence/upnp/devices/control_point.py | 8 +++----- coherence/upnp/devices/dimmable_light_client.py | 3 ++- coherence/upnp/devices/media_renderer_client.py | 3 ++- coherence/upnp/devices/media_server_client.py | 3 ++- mirabeau_client.py | 7 +------ tw_mirabeau_test.py | 9 ++------- 9 files changed, 19 insertions(+), 28 deletions(-) diff --git a/coherence/extern/telepathy/mirabeau_tube_publisher.py b/coherence/extern/telepathy/mirabeau_tube_publisher.py index 4833765..772ae5b 100644 --- a/coherence/extern/telepathy/mirabeau_tube_publisher.py +++ b/coherence/extern/telepathy/mirabeau_tube_publisher.py @@ -33,13 +33,12 @@ class MirabeauTubePublisherMixin(tube.TubePublisherMixin): return def _register_device(self, device): - name = '%s (%s)' % (device.get_friendly_name(), - ':'.join(device.get_device_type().split(':')[3:5])) - if self.allowed_devices != None and device.uuid not in self.allowed_devices: + if self.allowed_devices is not None and device.uuid not in self.allowed_devices: self.info("device not allowed: %r", device.uuid) return device.add_to_connection(self.device_tube, device.path()) - self.info("adding device %s to connection: %s", name, self.device_tube) + self.info("adding device %s to connection: %s", + device.get_markup_name(), self.device_tube) for service in device.services: service.add_to_connection(self.service_tube, service.path) diff --git a/coherence/tube_service.py b/coherence/tube_service.py index 012077f..c6ebc92 100644 --- a/coherence/tube_service.py +++ b/coherence/tube_service.py @@ -226,8 +226,8 @@ class TubeDeviceProxy(log.Loggable): self.uuid[1] = 'tube' self.uuid = '-'.join(self.uuid) self.friendly_name = self.device.get_friendly_name() - _,_,_,self.device_type,self.version = self.device.get_device_type().split(':') - self.version = int(self.version) + self.device_type = self.device.get_friendly_device_type() + self.version = int(self.device.get_device_type_version()) self._services = [] self._devices = [] diff --git a/coherence/upnp/devices/binary_light_client.py b/coherence/upnp/devices/binary_light_client.py index 49f471d..c0da2ff 100644 --- a/coherence/upnp/devices/binary_light_client.py +++ b/coherence/upnp/devices/binary_light_client.py @@ -14,7 +14,8 @@ class BinaryLightClient(log.Loggable): def __init__(self, device): self.device = device - self.device_type,self.version = device.get_device_type().split(':')[3:5] + self.device_type = self.device.get_friendly_device_type() + self.version = int(self.device.get_device_type_version()) self.icons = device.icons self.switch_power = None diff --git a/coherence/upnp/devices/control_point.py b/coherence/upnp/devices/control_point.py index f9be536..0f736b9 100644 --- a/coherence/upnp/devices/control_point.py +++ b/coherence/upnp/devices/control_point.py @@ -118,12 +118,10 @@ class ControlPoint(log.Loggable): self.info("found device %s of type %s - %r" %(device.get_friendly_name(), device.get_device_type(), device.client)) if device.client == None: - stuff = device.get_device_type().split(':') - short_type = None - if len(stuff) > 3: - short_type = stuff[3] + short_type = device.get_friendly_device_type() if short_type in self.auto_client and short_type is not None: - self.info("identified %s %r" % (short_type,device.get_friendly_name())) + self.info("identified %s %r", + (short_type, device.get_friendly_name())) if short_type == 'MediaServer': client = MediaServerClient(device) diff --git a/coherence/upnp/devices/dimmable_light_client.py b/coherence/upnp/devices/dimmable_light_client.py index 3d75e3c..da8b878 100644 --- a/coherence/upnp/devices/dimmable_light_client.py +++ b/coherence/upnp/devices/dimmable_light_client.py @@ -15,7 +15,8 @@ class DimmableLightClient(log.Loggable): def __init__(self, device): self.device = device - self.device_type,self.version = device.get_device_type().split(':')[3:5] + self.device_type = self.device.get_friendly_device_type() + self.version = int(self.device.get_device_type_version()) self.icons = device.icons self.switch_power = None self.dimming = None diff --git a/coherence/upnp/devices/media_renderer_client.py b/coherence/upnp/devices/media_renderer_client.py index 5270b79..d04f185 100644 --- a/coherence/upnp/devices/media_renderer_client.py +++ b/coherence/upnp/devices/media_renderer_client.py @@ -16,7 +16,8 @@ class MediaRendererClient(log.Loggable): def __init__(self, device): self.device = device - self.device_type,self.version = device.get_device_type().split(':')[3:5] + self.device_type = self.device.get_friendly_device_type() + self.version = int(self.device.get_device_type_version()) self.icons = device.icons self.rendering_control = None self.connection_manager = None diff --git a/coherence/upnp/devices/media_server_client.py b/coherence/upnp/devices/media_server_client.py index deef461..720a068 100644 --- a/coherence/upnp/devices/media_server_client.py +++ b/coherence/upnp/devices/media_server_client.py @@ -16,7 +16,8 @@ class MediaServerClient(log.Loggable): def __init__(self, device): self.device = device - self.device_type,self.version = device.get_device_type().split(':')[3:5] + self.device_type = self.device.get_friendly_device_type() + self.version = int(self.device.get_device_type_version()) self.icons = device.icons self.scheduled_recording = None self.content_directory = None diff --git a/mirabeau_client.py b/mirabeau_client.py index 6868c12..aaaf12d 100644 --- a/mirabeau_client.py +++ b/mirabeau_client.py @@ -27,12 +27,7 @@ def run(args=None): def got_devices(devices): print "got %d devices" % len(devices) for device in devices: - try: - name = '%s (%s)' % (device.get_friendly_name(), - ':'.join(device.get_device_type().split(':')[3:5])) - except: - continue - print "got_devices", name, device.get_id() + print "got_devices", device.get_markup_name(), device.get_id() # #print " >", if device.get_id() == "uuid:d5a96478-ba4b-4bf8-813b-250755d8edde": diff --git a/tw_mirabeau_test.py b/tw_mirabeau_test.py index 971d4a5..761dbb0 100644 --- a/tw_mirabeau_test.py +++ b/tw_mirabeau_test.py @@ -40,12 +40,7 @@ class TubeProxy(object): def got_devices(self,devices): for device in devices: - try: - name = '%s (%s)' % (device.get_friendly_name(), - ':'.join(device.get_device_type().split(':')[3:5])) - except: - continue - print "got_devices", name, device.get_id() + print "got_devices", device.get_markup_name(), device.get_id() # #print " >", if device.get_id() == "uuid:d5a96478-ba4b-4bf8-813b-250755d8edde": @@ -65,4 +60,4 @@ if __name__ == "__main__": from twisted.internet import reactor reactor.callWhenRunning(run) - reactor.run() \ No newline at end of file + reactor.run() -- 1.6.0.4