def upnp_SetTarget(self,**kwargs): self.info('upnp_SetTarget %r', kwargs) self.state = int(generalise_boolean(kwargs['NewTargetValue'])) if self.server: self.server.switch_power_server.set_variable(0, 'Target', self.state) self.server.switch_power_server.set_variable(0, 'Status', self.state) print "we have been switched to state", self.state return {}
def upnp_SetTarget(self, **kwargs): self.info('upnp_SetTarget %r', kwargs) self.state = int(generalise_boolean(kwargs['NewTargetValue'])) if self.server: self.server.switch_power_server.set_variable( 0, 'Target', self.state) self.server.switch_power_server.set_variable( 0, 'Status', self.state) print "we have been switched to state", self.state return {}
def update(self, value): if not isinstance(self.service, service.Service): if self.name == 'ContainerUpdateIDs': old_value = self.value if self.updated: if isinstance(value, tuple): v = old_value.split(',') i = 0 while i < len(v): if v[i] == str(value[0]): del v[i:i + 2] old_value = ','.join(v) break i += 2 if len(old_value): new_value = old_value + ',' + str( value[0]) + ',' + str(value[1]) else: new_value = str(value[0]) + ',' + str(value[1]) else: if len(old_value): new_value = str(old_value) + ',' + str(value) else: new_value = str(value) else: if isinstance(value, tuple): new_value = str(value[0]) + ',' + str(value[1]) else: new_value = value else: if self.data_type == 'string': if isinstance(value, str): value = value.split(',') if (isinstance(value, tuple) or isinstance(value, set)): value = list(value) if not isinstance(value, list): value = [value] new_value = [] for v in value: if type(v) == str: v = v # .encode('utf-8') else: v = str(v) if len(self.allowed_values): if self.has_vendor_values: new_value.append(v) elif v.upper() in [x.upper() for x in self.allowed_values]: new_value.append(v) else: self.warning( f'Variable {self.name} update, ' f'{self.has_vendor_values} value {v} ' f'doesn\'t fit in {self.allowed_values}') new_value = 'Coherence_Value_Error' else: new_value.append(v) new_value = ','.join(new_value) elif self.data_type == 'boolean': new_value = utils.generalise_boolean(value) elif self.data_type == 'bin.base64': new_value = value else: new_value = int(value) else: if self.data_type == 'string': if type(value) != str: value = str(value) if len(self.allowed_values): if self.has_vendor_values: new_value = value elif value.upper() in [v.upper() for v in self.allowed_values]: new_value = value else: self.warning(f'Variable {self.name} NOT updated, ' f'value {value} doesn\'t fit') new_value = 'Coherence_Value_Error' else: new_value = value elif self.data_type == 'boolean': new_value = utils.generalise_boolean(value) elif self.data_type == 'bin.base64': new_value = value else: try: new_value = int(value) except ValueError: new_value = 'Coherence_Value_Error' if new_value == 'Coherence_Value_Error': return if new_value == self.value: self.info(f'variable NOT updated, no value change' f' {self.name} {self.value}') return self.old_value = self.value self.value = new_value self.last_time_touched = time.time() # print(f'UPDATED {self.name} {self.service} ' # f'{isinstance(self.service, service.Service)} ' # f'{self.instance} {self.value} {self._callbacks}') self.notify() if isinstance(self.service, service.Service): # self.notify() pass else: self.updated = True if self.service.last_change is not None: self.service.last_change.updated = True
def update(self, value): self.info("variable check for update %s %s %s", self.name, value, self.service) if not isinstance(self.service, service.Service): if self.name == 'ContainerUpdateIDs': old_value = self.value if self.updated == True: if isinstance(value, tuple): v = old_value.split(',') i = 0 while i < len(v): if v[i] == str(value[0]): del v[i:i + 2] old_value = ','.join(v) break i += 2 if len(old_value): new_value = old_value + ',' + str( value[0]) + ',' + str(value[1]) else: new_value = str(value[0]) + ',' + str(value[1]) else: if len(old_value): new_value = str(old_value) + ',' + str(value) else: new_value = str(value) else: if isinstance(value, tuple): new_value = str(value[0]) + ',' + str(value[1]) else: new_value = value else: if self.data_type == 'string': if isinstance(value, str): value = value.split(',') if (isinstance(value, tuple) or isinstance(value, Set)): value = list(value) if not isinstance(value, list): value = [value] new_value = [] for v in value: if type(v) == str: v = v.encode('utf-8') else: v = str(v) if len(self.allowed_values): if self.has_vendor_values == True: new_value.append(v) elif v.upper() in [ x.upper() for x in self.allowed_values ]: new_value.append(v) else: self.warning( "Variable %s update, %r value %s doesn't fit in %r", self.name, self.has_vendor_values, v, self.allowed_values) new_value = 'Coherence_Value_Error' else: new_value.append(v) new_value = ','.join(new_value) elif self.data_type == 'boolean': new_value = utils.generalise_boolean(value) elif self.data_type == 'bin.base64': new_value = value else: new_value = int(value) else: if self.data_type == 'string': if type(value) == str: value = value.encode('utf-8') else: value = str(value) if len(self.allowed_values): if self.has_vendor_values == True: new_value = value elif value.upper() in [ v.upper() for v in self.allowed_values ]: new_value = value else: self.warning( "Variable %s NOT updated, value %s doesn't fit", self.name, value) new_value = 'Coherence_Value_Error' else: new_value = value elif self.data_type == 'boolean': new_value = utils.generalise_boolean(value) elif self.data_type == 'bin.base64': new_value = value else: try: new_value = int(value) except ValueError: new_value = 'Coherence_Value_Error' if new_value == 'Coherence_Value_Error': return if new_value == self.value: self.info("variable NOT updated, no value change %s %s", self.name, self.value) return self.old_value = self.value self.value = new_value self.last_time_touched = time.time() #print "UPDATED %s %r %r %r %r %r" % (self.name,self.service,isinstance( self.service, service.Service),self.instance,self.value,self._callbacks) self.notify() if isinstance(self.service, service.Service): #self.notify() pass else: self.updated = True if self.service.last_change != None: self.service.last_change.updated = True self.info("variable updated %s %s", self.name, self.value)
def update(self, value): self.info("variable check for update", self.name, value, self.service) if not isinstance( self.service, service.Service): if self.name == 'ContainerUpdateIDs': old_value = self.value if self.updated == True: if isinstance( value, tuple): v = old_value.split(',') i = 0 while i < len(v): if v[i] == str(value[0]): del v[i:i+2] old_value = ','.join(v) break; i += 2 if len(old_value): new_value = old_value + ',' + str(value[0]) + ',' + str(value[1]) else: new_value = str(value[0]) + ',' + str(value[1]) else: if len(old_value): new_value = str(old_value) + ',' + str(value) else: new_value = str(value) else: if isinstance( value, tuple): new_value = str(value[0]) + ',' + str(value[1]) else: new_value = value else: if self.data_type == 'string': if isinstance(value,basestring): value = value.split(',') if(isinstance(value,tuple) or isinstance(value,Set)): value = list(value) if not isinstance(value,list): value = [value] new_value = [] for v in value: if type(v) == unicode: v = v.encode('utf-8') else: v = str(v) if len(self.allowed_values): if self.has_vendor_values == True: new_value.append(v) elif v.upper() in [x.upper() for x in self.allowed_values]: new_value.append(v) else: self.warning("Variable %s update, %r value %s doesn't fit in %r" % (self.name, self.has_vendor_values, v, self.allowed_values)) new_value = 'Coherence_Value_Error' else: new_value.append(v) new_value = ','.join(new_value) elif self.data_type == 'boolean': new_value = utils.generalise_boolean(value) elif self.data_type == 'bin.base64': new_value = value else: new_value = int(value) else: if self.data_type == 'string': if type(value) == unicode: value = value.encode('utf-8') else: value = str(value) if len(self.allowed_values): if self.has_vendor_values == True: new_value = value elif value.upper() in [v.upper() for v in self.allowed_values]: new_value = value else: self.warning("Variable %s NOT updated, value %s doesn't fit" % (self.name, value)) new_value = 'Coherence_Value_Error' else: new_value = value elif self.data_type == 'boolean': new_value = utils.generalise_boolean(value) elif self.data_type == 'bin.base64': new_value = value else: try: new_value = int(value) except ValueError: new_value = 'Coherence_Value_Error' if new_value == 'Coherence_Value_Error': return if new_value == self.value: self.info("variable NOT updated, no value change", self.name, self.value) return self.old_value = self.value self.value = new_value self.last_time_touched = time.time() #print "UPDATED %s %r %r %r %r %r" % (self.name,self.service,isinstance( self.service, service.Service),self.instance,self.value,self._callbacks) self.notify() if isinstance( self.service, service.Service): #self.notify() pass else: self.updated = True if self.service.last_change != None: self.service.last_change.updated = True self.info("variable updated", self.name, self.value)