예제 #1
0
    def process_event(self,event):
        self.debug("process event %s" % self)
        for var_name, var_value  in event.items():
            if var_name == 'LastChange':
                self.debug("we have a LastChange event %s", var_value)
                self.get_state_variable(var_name, 0).update(var_value)
                tree = utils.parse_xml(var_value, 'utf-8').getroot()
                namespace_uri, tag = tree.tag[1:].split( "}", 1)
                for instance in tree.findall('{%s}InstanceID' % namespace_uri):
                    instance_id = instance.attrib['val']
                    self.debug("instance_id %r %r" % (instance,instance_id))
                    for var in instance.getchildren():
                        self.debug("var %r" % var)
                        namespace_uri, tag = var.tag[1:].split("}", 1)
                        if len(var.attrib) > 1:
                            self.debug("Extended StateVariable %s - %s", var.tag, var.attrib)

                        if var.attrib.has_key('channel') and var.attrib['channel'] != 'Master':
                            # TODO handle attributes that them selves have multiple instances
                            self.info("Skiiping update to %s its not for master channel %s", var.tag, var.attrib)
                            pass
                        else:
                            if self.get_state_variables(instance_id) is None:
                                # TODO Create instance ?
                                self.info("%r Create new service instance %r", self, instance_id)
                                self.create_new_instance(instance_id)

                            if not self.get_state_variables(instance_id).has_key(tag):
                                # SONOS stuff, it returns attributes that are not listed in the 
                                # state description. The soap reply propogates the changes as state updates.
                                nv = variable.StateVariable(self, tag,
                                                               'n/a',
                                                               instance_id, True,
                                                               "string", [])
                                self.get_state_variables(instance_id)[tag] = nv
                                self.info("%r Create new variable %r", self, tag)

                            val = None
                            if var.attrib.has_key('val'):
                                val = var.attrib['val']
                            self.get_state_variable(tag, instance_id).update(val)
                        self.info("updated var %r" % var)
            else:
                # what if not exist
                self.info("updated var %s - %s ", var_name, var_value)
                self.get_state_variable(var_name, 0).update(var_value)

        self.debug("process event complete %s" % self)
        if self.last_time_updated == None:
            self.last_time_updated = time.time()    # needs to be set before louie call.
            louie.send('Coherence.UPnP.DeviceClient.Service.notified', sender=self.device, service=self)
            self.info("send signal Coherence.UPnP.DeviceClient.Service.notified for %r" % self)
        self.last_time_updated = time.time()
예제 #2
0
 def process_event(self,event):
     self.info("process event %r %r" % (self,event))
     for var_name, var_value  in event.items():
         if var_name == 'LastChange':
             self.info("we have a LastChange event")
             self.get_state_variable(var_name, 0).update(var_value)
             if len(var_value) == 0:
                 continue
             tree = utils.parse_xml(var_value, 'utf-8').getroot()
             namespace_uri, tag = tree.tag[1:].split( "}", 1)
             for instance in tree.findall('{%s}InstanceID' % namespace_uri):
                 instance_id = instance.attrib['val']
                 self.info("instance_id %r %r" % (instance,instance_id))
                 for var in instance.getchildren():
                     self.info("var %r" % var)
                     namespace_uri, tag = var.tag[1:].split("}", 1)
                     self.info("%r %r %r" % (namespace_uri, tag,var.attrib['val']))
                     self.get_state_variable(tag, instance_id).update(var.attrib['val'])
                     self.info("updated var %r" % var)
                     if len(var.attrib) > 1:
                         self.info("Extended StateVariable %s - %r", var.tag, var.attrib)
                         if var.attrib.has_key('channel') and var.attrib['channel'] != 'Master':
                             # TODO handle attributes that them selves have multiple instances
                             self.info("Skipping update to %s its not for master channel %s", var.tag, var.attrib)
                             pass
                         else:
                             if not self.get_state_variables(instance_id):
                                 # TODO Create instance ?
                                 self.error("%r update failed (not self.get_state_variables(instance_id)) %r", self, instance_id)
                             elif not self.get_state_variables(instance_id).has_key(tag):
                                 # TODO Create instance StateVariable?
                                 # SONOS stuff
                                 self.error("%r update failed (not self.get_state_variables(instance_id).has_key(tag)) %r", self, tag)
                             else:
                                 val = None
                                 if var.attrib.has_key('val'):
                                     val = var.attrib['val']
                                 #self.debug("%r update %r %r %r", self,namespace_uri, tag, var.attrib['val'])
                                 self.get_state_variable(tag, instance_id).update(var.attrib['val'])
                                 self.debug("updated 'attributed' var %r", var)
             louie.send('Coherence.UPnP.DeviceClient.Service.Event.processed',None,self,(var_name,var_value,event.raw))
         else:
             self.get_state_variable(var_name, 0).update(var_value)
             louie.send('Coherence.UPnP.DeviceClient.Service.Event.processed',None,self,(var_name,var_value,event.raw))
     if self.last_time_updated == None:
         # The clients (e.g. media_server_client) check for last time to detect whether service detection is complete
         # so we need to set it here and now to avoid a potential race condition
         self.last_time_updated = time.time()
         louie.send('Coherence.UPnP.DeviceClient.Service.notified', sender=self.device, service=self)
         self.info("send signal Coherence.UPnP.DeviceClient.Service.notified for %r" % self)
     self.last_time_updated = time.time()
예제 #3
0
    def process_event(self,event):
        self.info("process event %r" % self)
        for var_name, var_value  in event.items():
            if var_name == 'LastChange':
                self.info("we have a LastChange event")
                self.get_state_variable(var_name, 0).update(var_value)
                tree = utils.parse_xml(var_value, 'utf-8').getroot()
                namespace_uri, tag = tree.tag[1:].split( "}", 1)
                for instance in tree.findall('{%s}InstanceID' % namespace_uri):
                    instance_id = instance.attrib['val']
                    self.info("instance_id %r %r" % (instance,instance_id))
                    for var in instance.getchildren():
                        self.info("var %r" % var)
                        namespace_uri, tag = var.tag[1:].split("}", 1)
                        if len(var.attrib) > 1:
                            self.info("Extended StateVariable %s - %s", var.tag, var.attrib)

                        if var.attrib.has_key('channel') and var.attrib['channel'] != 'Master':
                            # TODO handle attributes that them selves have multiple instances
                            self.info("Skiiping update to %s its not for master channel %s", var.tag, var.attrib)
                            pass
                        else:
                            if not self.get_state_variables(instance_id) :
                                # TODO Create instance ?
                                self.error("%r update failed (not self.get_state_variables(instance_id)) %r", self, instance_id)
                            elif not self.get_state_variables(instance_id).has_key(tag):
                                # TODO Create instance StateVariable?
                                # SONOS stuff
                                self.error("%r update failed (not self.get_state_variables(instance_id).has_key(tag)) %r", self, tag)
                            else:
                                val = None
                                if var.attrib.has_key('val'):
                                    val = var.attrib['val']
                                #self.debug("%r update %r %r %r", self,namespace_uri, tag, var.attrib['val'])
                                self.get_state_variable(tag, instance_id).update(var.attrib['val'])
                            self.debug("updated var %r", var)
            else:
                self.get_state_variable(var_name, 0).update(var_value)
        if self.last_time_updated == None:
            louie.send('Coherence.UPnP.DeviceClient.Service.notified', sender=self.device, service=self)
            self.info("send signal Coherence.UPnP.DeviceClient.Service.notified for %r" % self)
        self.last_time_updated = time.time()
예제 #4
0
 def process_event(self, event):
     self.info("process event %r %r" % (self, event))
     for var_name, var_value in event.items():
         if var_name == 'LastChange':
             self.info("we have a LastChange event")
             self.get_state_variable(var_name, 0).update(var_value)
             if len(var_value) == 0:
                 continue
             tree = utils.parse_xml(var_value, 'utf-8').getroot()
             namespace_uri, tag = tree.tag[1:].split("}", 1)
             for instance in tree.findall('{%s}InstanceID' % namespace_uri):
                 instance_id = instance.attrib['val']
                 self.info("instance_id %r %r" % (instance, instance_id))
                 for var in instance.getchildren():
                     self.info("var %r" % var)
                     namespace_uri, tag = var.tag[1:].split("}", 1)
                     self.info("%r %r %r" %
                               (namespace_uri, tag, var.attrib['val']))
                     self.get_state_variable(tag, instance_id).update(
                         var.attrib['val'])
                     self.info("updated var %r" % var)
                     if len(var.attrib) > 1:
                         self.info("Extended StateVariable %s - %r",
                                   var.tag, var.attrib)
                         if var.attrib.has_key('channel') and var.attrib[
                                 'channel'] != 'Master':
                             # TODO handle attributes that them selves have multiple instances
                             self.info(
                                 "Skipping update to %s its not for master channel %s",
                                 var.tag, var.attrib)
                             pass
                         else:
                             if not self.get_state_variables(instance_id):
                                 # TODO Create instance ?
                                 self.error(
                                     "%r update failed (not self.get_state_variables(instance_id)) %r",
                                     self, instance_id)
                             elif not self.get_state_variables(
                                     instance_id).has_key(tag):
                                 # TODO Create instance StateVariable?
                                 # SONOS stuff
                                 self.error(
                                     "%r update failed (not self.get_state_variables(instance_id).has_key(tag)) %r",
                                     self, tag)
                             else:
                                 val = None
                                 if var.attrib.has_key('val'):
                                     val = var.attrib['val']
                                 #self.debug("%r update %r %r %r", self,namespace_uri, tag, var.attrib['val'])
                                 self.get_state_variable(
                                     tag,
                                     instance_id).update(var.attrib['val'])
                                 self.debug("updated 'attributed' var %r",
                                            var)
             louie.send(
                 'Coherence.UPnP.DeviceClient.Service.Event.processed',
                 None, self, (var_name, var_value, event.raw))
         else:
             self.get_state_variable(var_name, 0).update(var_value)
             louie.send(
                 'Coherence.UPnP.DeviceClient.Service.Event.processed',
                 None, self, (var_name, var_value, event.raw))
     if self.last_time_updated == None:
         # The clients (e.g. media_server_client) check for last time to detect whether service detection is complete
         # so we need to set it here and now to avoid a potential race condition
         self.last_time_updated = time.time()
         louie.send('Coherence.UPnP.DeviceClient.Service.notified',
                    sender=self.device,
                    service=self)
         self.info(
             "send signal Coherence.UPnP.DeviceClient.Service.notified for %r"
             % self)
     self.last_time_updated = time.time()