Source code for coherence.upnp.devices.wan_device_client

# -*- coding: utf-8 -*-

# Licensed under the MIT license
# http://opensource.org/licenses/mit-license.php

# Copyright 2010 Frank Scholz <dev@coherence-project.org>

'''
:class:`WANDeviceClient`
------------------------

A class representing an embbeded device with a WAN client.

'''

from eventdispatcher import (
    EventDispatcher, Property, StringProperty)

from coherence import log
from coherence.upnp.devices.wan_connection_device_client import \
    WANConnectionDeviceClient
from coherence.upnp.services.clients.wan_common_interface_config_client import\
    WANCommonInterfaceConfigClient


[docs]class WANDeviceClient(EventDispatcher, log.LogAble): ''' .. versionchanged:: 0.9.0 * Introduced inheritance from EventDispatcher * The emitted events changed: - Coherence.UPnP.DeviceClient.detection_completed => embedded_device_client_detection_completed * Changed `device_type`, `embedded_device_detection_completed` and `service_detection_completed` to use EventDispatcher's properties ''' logCategory = 'wan_device_client' device_type = StringProperty('') embedded_device_detection_completed = Property(False) service_detection_completed = Property(False) def __init__(self, device): log.LogAble.__init__(self) EventDispatcher.__init__(self) self.register_event( # 'Coherence.UPnP.DeviceClient.detection_completed', 'embedded_device_client_detection_completed', ) self.device = device # 'Coherence.UPnP.DeviceClient.Service.notified' self.device.bind( embedded_device_client_detection_completed=self.embedded_device_notified, # noqa service_notified=self.service_notified ) self.device_type = self.device.get_friendly_device_type() self.version = int(self.device.get_device_type_version()) self.icons = device.icons self.wan_connection_device = None self.wan_common_interface_connection = None try: wan_connection_device = \ self.device.get_embedded_device_by_type( 'WANConnectionDevice')[0] self.wan_connection_device = WANConnectionDeviceClient( wan_connection_device) except Exception as er: self.warning( "Embedded WANConnectionDevice device not available, " "device not implemented properly according to " "the UPnP specification [ERROR: {}]".format(er)) raise # 'Coherence.UPnP.DeviceClient.Service.notified' for service in self.device.get_services(): if service.get_type() in [ "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1"]: self.wan_common_interface_connection = \ WANCommonInterfaceConfigClient(service) self.info("WANDevice %s", self.device.get_friendly_name())
[docs] def remove(self): self.info("removal of WANDeviceClient started") if self.wan_common_interface_connection is not None: self.wan_common_interface_connection.remove() if self.wan_connection_device is not None: self.wan_connection_device.remove()
[docs] def embedded_device_notified(self, device): self.info("EmbeddedDevice %r sent notification", device) if self.embedded_device_detection_completed: return self.embedded_device_detection_completed = True if self.embedded_device_detection_completed is True and \ self.service_detection_completed is True: # 'Coherence.UPnP.EmbeddedDeviceClient.detection_completed' self.dispatch_event( 'embedded_device_client_detection_completed', self)
[docs] def service_notified(self, service): self.info("Service %r sent notification", service) if self.service_detection_completed: return if self.wan_common_interface_connection is not None: if not hasattr(self.wan_common_interface_connection.service, 'last_time_updated'): return if self.wan_common_interface_connection.\ service.last_time_updated is None: return self.service_detection_completed = True if self.embedded_device_detection_completed is True and \ self.service_detection_completed is True: # 'Coherence.UPnP.EmbeddedDeviceClient.detection_completed' self.dispatch_event( 'embedded_device_client_detection_completed', self)