def setState(self, state): if self.type == 'GPIO': new_state = 1 - self.active - state GPIO.output(self.pin, new_state) if GPIO.input(self.pin) is self.active: return 1 else: return 0
def executeAction(self): if self.type == 'GPIO': original_state = GPIO.input(self.pin) new_state = 1 - original_state GPIO.output(self.pin, new_state) if 'Duration' in self.attributes: time.sleep(self.attributes['Duration']) GPIO.output(self.pin, original_state) if self.type == 'Script' and self.action: if self.getState(): subprocess.call([self.off_cmd], shell=True) else: subprocess.call([self.on_cmd], shell=True)
def getState(self): if self.type == 'GPIO': if GPIO.input(self.pin) is self.active: return 1 else: return 0 else: #get the state of other Appliances in other rooms #not properly implemented yet returnCode = subprocess.call([self.status_cmd], shell=True) if returnCode == 0: return 1 return 0