def execute(self, command, params, challenge): """Execute a command. https://developers.google.com/actions/smarthome/create-app#actiondevicesexecute """ executed = False for trt in self.traits(): if trt.can_execute(command, params): acknowledge = self.state.ack # ack is now stored in state pincode = False if configuration['Domoticz']['switchProtectionPass']: protect = self.state.protected else: protect = False if protect or self.state.domain == domains['security']: pincode = configuration['Domoticz']['switchProtectionPass'] if self.state.domain == domains['security']: pincode = self.state.seccode acknowledge = False if challenge is None: raise SmartHomeErrorNoChallenge(ERR_CHALLENGE_NEEDED, 'pinNeeded', 'Unable to execute {} for {} - challenge needed '.format( command, self.state.entity_id)) elif not challenge.get('pin', False): raise SmartHomeErrorNoChallenge(ERR_CHALLENGE_NEEDED, 'userCancelled', 'Unable to execute {} for {} - challenge needed '.format( command, self.state.entity_id)) elif True == protect and pincode != challenge.get('pin'): raise SmartHomeErrorNoChallenge(ERR_CHALLENGE_NEEDED, 'challengeFailedPinNeeded', 'Unable to execute {} for {} - challenge needed '.format( command, self.state.entity_id)) elif self.state.domain == domains['security'] and pincode != hashlib.md5( str.encode(challenge.get('pin'))).hexdigest(): raise SmartHomeErrorNoChallenge(ERR_CHALLENGE_NEEDED, 'challengeFailedPinNeeded', 'Unable to execute {} for {} - challenge needed '.format( command, self.state.entity_id)) if acknowledge: if challenge is None: raise SmartHomeErrorNoChallenge(ERR_CHALLENGE_NEEDED, 'ackNeeded', 'Unable to execute {} for {} - challenge needed '.format( command, self.state.entity_id)) elif not challenge.get('ack', False): raise SmartHomeErrorNoChallenge(ERR_CHALLENGE_NEEDED, 'userCancelled', 'Unable to execute {} for {} - challenge needed '.format( command, self.state.entity_id)) trt.execute(command, params) executed = True break if not executed: raise SmartHomeError(ERR_FUNCTION_NOT_SUPPORTED, 'Unable to execute {} for {}'.format(command, self.state.entity_id))
def execute(self, command, params, challenge): """Execute a command. https://developers.google.com/actions/smarthome/create-app#actiondevicesexecute """ executed = False for trt in self.traits(): if trt.can_execute(command, params): ack = False pin = False desc = getDesc(self.state) if desc != None: ack = desc.get('ack', False) if DOMOTICZ_SWITCH_PROTECTION_PASSWD != False: protect = self.state.protected else: protect = False if protect or self.state.domain == securityDOMAIN: pin = DOMOTICZ_SWITCH_PROTECTION_PASSWD if self.state.domain == securityDOMAIN: pin = self.state.seccode ack = False if challenge == None: raise SmartHomeErrorNoChallenge(ERR_CHALLENGE_NEEDED, 'pinNeeded', 'Unable to execute {} for {} - challenge needed '.format(command, self.state.entity_id)) elif False == challenge.get('pin', False): raise SmartHomeErrorNoChallenge(ERR_CHALLENGE_NEEDED, 'userCancelled', 'Unable to execute {} for {} - challenge needed '.format(command, self.state.entity_id)) elif True == protect and pin != challenge.get('pin'): raise SmartHomeErrorNoChallenge(ERR_CHALLENGE_NEEDED, 'challengeFailedPinNeeded', 'Unable to execute {} for {} - challenge needed '.format(command, self.state.entity_id)) elif self.state.domain == securityDOMAIN and pin != hashlib.md5(str.encode(challenge.get('pin'))).hexdigest(): raise SmartHomeErrorNoChallenge(ERR_CHALLENGE_NEEDED, 'challengeFailedPinNeeded', 'Unable to execute {} for {} - challenge needed '.format(command, self.state.entity_id)) if ack: print(challenge) if challenge == None: raise SmartHomeErrorNoChallenge(ERR_CHALLENGE_NEEDED, 'ackNeeded', 'Unable to execute {} for {} - challenge needed '.format(command, self.state.entity_id)) elif False == challenge.get('ack', False): raise SmartHomeErrorNoChallenge(ERR_CHALLENGE_NEEDED, 'userCancelled', 'Unable to execute {} for {} - challenge needed '.format(command, self.state.entity_id)) trt.execute(command, params) executed = True break if not executed: raise SmartHomeError(ERR_FUNCTION_NOT_SUPPORTED, 'Unable to execute {} for {}'.format(command, self.state.entity_id))