def new_subscriber(self, subscriber): notify = [] for vdict in self._variables.values(): notify += [v for v in vdict.values() if v.send_events == True] self.info("new_subscriber", subscriber, notify) if len(notify) <= 0: return root = ET.Element('e:propertyset') root.attrib['xmlns:e']='urn:schemas-upnp-org:event-1-0' evented_variables = 0 for n in notify: e = ET.SubElement( root, 'e:property') if n.name == 'LastChange': if subscriber['seq'] == 0: text = self.build_last_change_event(n.instance, force=True) else: text = self.build_last_change_event(n.instance) if text is not None: ET.SubElement( e, n.name).text = text evented_variables += 1 else: ET.SubElement( e, n.name).text = str(n.value) evented_variables += 1 if evented_variables > 0: xml = ET.tostring( root, encoding='utf-8') event.send_notification(subscriber, xml) self._subscribers[subscriber['sid']] = subscriber
def propagate_notification(self, notify): #print "propagate_notification", notify if len(self._subscribers) <= 0: return if len(notify) <= 0: return root = ET.Element('e:propertyset') root.attrib['xmlns:e']='urn:schemas-upnp-org:event-1-0' if isinstance( notify, variable.StateVariable): notify = [notify,] evented_variables = 0 for n in notify: e = ET.SubElement( root, 'e:property') if n.name == 'LastChange': text = self.build_last_change_event(instance=n.instance) if text is not None: ET.SubElement( e, n.name).text = text evented_variables += 1 else: s = ET.SubElement( e, n.name).text = str(n.value) evented_variables += 1 if n.dependant_variable != None: dependants = n.dependant_variable.get_allowed_values() if dependants != None and len(dependants) > 0: s.attrib['channel']=dependants[0] if evented_variables == 0: return xml = ET.tostring( root, encoding='utf-8') #print "propagate_notification", xml for s in self._subscribers.values(): event.send_notification(s, xml)
def process_value(result): variable.update(result) if default == True: variable.default_value = variable.value if(variable.send_events == True and variable.moderated == False and len(self._subscribers) > 0): xml = self.build_single_notification(instance, variable_name, variable.value) for s in self._subscribers.values(): event.send_notification(s, xml)
def new_subscriber(self, subscriber): notify = [] for vdict in self._variables.values(): notify += [v for v in vdict.values() if v.send_events == True] self.info("new_subscriber", subscriber, notify) if len(notify) <= 0: return root = ET.Element('e:propertyset') root.attrib['xmlns:e'] = 'urn:schemas-upnp-org:event-1-0' evented_variables = 0 for n in notify: e = ET.SubElement(root, 'e:property') if n.name == 'LastChange': if subscriber['seq'] == 0: text = self.build_last_change_event(n.instance, force=True) else: text = self.build_last_change_event(n.instance) if text is not None: ET.SubElement(e, n.name).text = text evented_variables += 1 else: ET.SubElement(e, n.name).text = str(n.value) evented_variables += 1 if evented_variables > 0: xml = ET.tostring(root, encoding='utf-8') d, p = event.send_notification(subscriber, xml) self._pending_notifications[d] = p d.addBoth(self.rm_notification, d) self._subscribers[subscriber['sid']] = subscriber
def new_subscriber(self, subscriber): notify = [] for vdict in list(self._variables.values()): notify += [ v for v in list(vdict.values()) if v.send_events == True ] self.info("new_subscriber %s %s", subscriber, notify) if len(notify) <= 0: return root = etree.Element('{%s}propertyset' % NS_UPNP_ORG_EVENT_1_0, nsmap={'e': NS_UPNP_ORG_EVENT_1_0}) evented_variables = 0 for n in notify: e = etree.SubElement(root, '{%s}property' % NS_UPNP_ORG_EVENT_1_0) if n.name == 'LastChange': if subscriber['seq'] == 0: text = self.build_last_change_event(n.instance, force=True) else: text = self.build_last_change_event(n.instance) if text is not None: etree.SubElement(e, n.name).text = text evented_variables += 1 else: etree.SubElement(e, n.name).text = str(n.value) evented_variables += 1 if evented_variables > 0: xml = etree.tostring(root, encoding='utf-8', pretty_print=True) d, p = event.send_notification(subscriber, xml) self._pending_notifications[d] = p d.addBoth(self.rm_notification, d) self._subscribers[subscriber['sid']] = subscriber
def propagate_notification(self, notify): if len(self._subscribers) <= 0: return if len(notify) <= 0: return root = etree.Element('{%s}propertyset' % NS_UPNP_ORG_EVENT_1_0, nsmap={'e': NS_UPNP_ORG_EVENT_1_0}) if isinstance(notify, variable.StateVariable): notify = [notify, ] evented_variables = 0 for n in notify: e = etree.SubElement(root, '{%s}property' % NS_UPNP_ORG_EVENT_1_0) if n.name == 'LastChange': text = self.build_last_change_event(instance=n.instance) if text is not None: etree.SubElement(e, n.name).text = text evented_variables += 1 else: s = etree.SubElement(e, n.name).text = str(n.value) evented_variables += 1 if n.dependant_variable is not None: dependants = n.dependant_variable.get_allowed_values() if dependants is not None and len(dependants) > 0: s.attrib['channel'] = dependants[0] if evented_variables == 0: return xml = etree.tostring(root, encoding='utf-8', pretty_print=True) for s in self._subscribers.values(): d, p = event.send_notification(s, xml) self._pending_notifications[d] = p d.addBoth(self.rm_notification, d)
def new_subscriber(self, subscriber): notify = [] for vdict in self._variables.values(): notify += [v for v in vdict.values() if v.send_events == True] self.info("new_subscriber %s %s", subscriber, notify) if len(notify) <= 0: return root = etree.Element('{%s}propertyset' % NS_UPNP_ORG_EVENT_1_0, nsmap={'e': NS_UPNP_ORG_EVENT_1_0}) evented_variables = 0 for n in notify: e = etree.SubElement(root, '{%s}property' % NS_UPNP_ORG_EVENT_1_0) if n.name == 'LastChange': if subscriber['seq'] == 0: text = self.build_last_change_event(n.instance, force=True) else: text = self.build_last_change_event(n.instance) if text is not None: etree.SubElement(e, n.name).text = text evented_variables += 1 else: etree.SubElement(e, n.name).text = str(n.value) evented_variables += 1 if evented_variables > 0: xml = etree.tostring(root, encoding='utf-8', pretty_print=True) d, p = event.send_notification(subscriber, xml) self._pending_notifications[d] = p d.addBoth(self.rm_notification, d) self._subscribers[subscriber['sid']] = subscriber
def process_value(result): variable.update(result) if default: variable.default_value = variable.value if variable.send_events and not variable.moderated and len(self._subscribers) > 0: xml = self.build_single_notification(instance, variable_name, variable.value) for s in self._subscribers.values(): d, p = event.send_notification(s, xml) self._pending_notifications[d] = p d.addBoth(self.rm_notification, d)
def process_value(result): variable.update(result) if default == True: variable.default_value = variable.value if (variable.send_events == True and variable.moderated == False and len(self._subscribers) > 0): xml = self.build_single_notification(instance, variable_name, variable.value) for s in self._subscribers.values(): d, p = event.send_notification(s, xml) self._pending_notifications[d] = p d.addBoth(self.rm_notification, d)
def process_value(result): variable.update(result) if default: variable.default_value = variable.value if variable.send_events and not variable.moderated and len( self._subscribers) > 0: xml = self.build_single_notification(instance, variable_name, variable.value) for s in list(self._subscribers.values()): d, p = event.send_notification(s, xml) self._pending_notifications[d] = p d.addBoth(self.rm_notification, d)
def propagate_notification(self, notify): #print "propagate_notification", notify if len(self._subscribers) <= 0: return if len(notify) <= 0: return root = ET.Element('e:propertyset') root.attrib['xmlns:e'] = 'urn:schemas-upnp-org:event-1-0' if isinstance(notify, variable.StateVariable): notify = [ notify, ] evented_variables = 0 for n in notify: e = ET.SubElement(root, 'e:property') if n.name == 'LastChange': text = self.build_last_change_event(instance=n.instance) if text is not None: ET.SubElement(e, n.name).text = text evented_variables += 1 else: s = ET.SubElement(e, n.name).text = str(n.value) evented_variables += 1 if n.dependant_variable != None: dependants = n.dependant_variable.get_allowed_values() if dependants != None and len(dependants) > 0: s.attrib['channel'] = dependants[0] if evented_variables == 0: return xml = ET.tostring(root, encoding='utf-8') #print "propagate_notification", xml for s in self._subscribers.values(): d, p = event.send_notification(s, xml) self._pending_notifications[d] = p d.addBoth(self.rm_notification, d)
def propagate_notification(self, notify): if len(self._subscribers) <= 0: return if len(notify) <= 0: return root = etree.Element('{%s}propertyset' % NS_UPNP_ORG_EVENT_1_0, nsmap={'e': NS_UPNP_ORG_EVENT_1_0}) if isinstance(notify, variable.StateVariable): notify = [ notify, ] evented_variables = 0 for n in notify: e = etree.SubElement(root, '{%s}property' % NS_UPNP_ORG_EVENT_1_0) if n.name == 'LastChange': text = self.build_last_change_event(instance=n.instance) if text is not None: etree.SubElement(e, n.name).text = text evented_variables += 1 else: s = etree.SubElement(e, n.name).text = str(n.value) evented_variables += 1 if n.dependant_variable is not None: dependants = n.dependant_variable.get_allowed_values() if dependants is not None and len(dependants) > 0: s.attrib['channel'] = dependants[0] if evented_variables == 0: return xml = etree.tostring(root, encoding='utf-8', pretty_print=True) for s in list(self._subscribers.values()): d, p = event.send_notification(s, xml) self._pending_notifications[d] = p d.addBoth(self.rm_notification, d)