def executeByPayload(self, payload): actuatorId = int(payload[EPGraduallySetLight.ATTR_ACTUATOR_ID]) value = int(payload[EPGraduallySetLight.ATTR_VALUE]) inSeconds = int(payload[EPGraduallySetLight.ATTR_IN_SECONDS]) if actuatorId == self.web_gadget.getLightId(): if value >= 0 and value <= 100: # Stop the running Thread self.web_gadget.gradualThreadController.indicateToStop() while self.web_gadget.gradualThreadController.isRunning(): logging.debug( " Waitiong for thread stops in {0} in executedByPayload() method" .format(__file__)) sleep(self.__class__.TIME_WAIT_FOR_THREAD) actualValue = self.web_gadget.fetchSavedLightValue() newValue = value logging.debug( "WEB request: {0} {1} ('{2}': {3}, '{4}': {5}, '{6}': {7})" .format(EPGraduallySetLight.METHOD, EPGraduallySetLight.URL, EPGraduallySetLight.ATTR_ACTUATOR_ID, actuatorId, EPGraduallySetLight.ATTR_VALUE, value, EPGraduallySetLight.ATTR_IN_SECONDS, inSeconds)) # Save the light value and set the Light # thread = Thread(target = self.web_gadget.setLight, args = (newValue, actualValue['current'], inSeconds)) thread = Thread(target=self.runThread, args=(newValue, actualValue['current'], inSeconds)) thread.daemon = True thread.start() else: raise InvalidAPIUsage( "The value is not valid: {0}".format(value), status_code=404) else: raise InvalidAPIUsage("No such actuator: {0} or value: {1}".format( actuatorId, value), status_code=404) return {'status': 'OK'}
def executeByPayload(self, payload) -> dict: actuatorId = int(payload[EPImmediatelyReverseLight.ATTR_ACTUATOR_ID]) if actuatorId == self.web_gadget.getLightId(): # Stop the running Thread self.web_gadget.gradualThreadController.indicateToStop() while self.web_gadget.gradualThreadController.isRunning(): logging.debug( " Waitiong for thread stops in {0} in executedByPayload() method" .format(__file__)) sleep(self.__class__.TIME_WAIT_FOR_THREAD) logging.debug("WEB request: {0} {1} ('{2}': {3})".format( EPImmediatelyReverseLight.METHOD, EPImmediatelyReverseLight.URL, EPImmediatelyReverseLight.ATTR_ACTUATOR_ID, actuatorId)) # Save the light value and set the Light return self.web_gadget.reverseLight() else: raise InvalidAPIUsage("No such actuator: {0}".format(actuatorId), status_code=404)
def executeByPayload(self, payload): actuatorId = int(payload[EPSignalSend.ATTR_ACTUATOR_ID]) signalId = int(payload[EPSignalSend.ATTR_SIGNAL_ID]) if actuatorId == self.web_gadget.getLightId(): # Stop the running Thread self.web_gadget.gradualThreadController.indicateToStop() while self.web_gadget.gradualThreadController.isRunning(): logging.debug( " Waitiong for thread stops in {0} in executedByPayload() method".format(__file__)) sleep(self.__class__.TIME_WAIT_FOR_THREAD) actualValue = self.web_gadget.fetchSavedLightValue() logging.debug( "{0} {1} ('{2}': {3}, '{4}': {5})".format( EPSignalSend.METHOD, EPSignalSend.URL, EPSignalSend.ATTR_ACTUATOR_ID, actuatorId, EPSignalSend.ATTR_SIGNAL_ID, signalId) ) thread = Thread(target = self.runThread, args = (signalId, actualValue['current'])) thread.daemon = True thread.start() else: raise InvalidAPIUsage("No such actuator: {0} or signal type: {1}}".format(actuatorId, signalId), error_code=404) return {'status': 'OK'}
def executeByPayload(self, payload): actuatorId = int(payload[EPGraduallyScheduleSetLight.ATTR_ACTUATOR_ID]) value = int(payload[EPGraduallyScheduleSetLight.ATTR_VALUE]) inSeconds = int(payload[EPGraduallyScheduleSetLight.ATTR_IN_SECONDS]) atDateTime = datetime.fromisoformat( payload[EPGraduallyScheduleSetLight.ATTR_AT_DATE_TIME]) if actuatorId == self.web_gadget.getLightId(): if value >= 0 and value <= 100: logging.debug( "WEB request: {0} {1} ('{2}': {3}, '{4}': {5}, '{6}': {7}, '{8}': {9})" .format(EPGraduallyScheduleSetLight.METHOD, EPGraduallyScheduleSetLight.URL, EPGraduallyScheduleSetLight.ATTR_ACTUATOR_ID, actuatorId, EPGraduallyScheduleSetLight.ATTR_VALUE, value, EPGraduallyScheduleSetLight.ATTR_IN_SECONDS, inSeconds, EPGraduallyScheduleSetLight.ATTR_AT_DATE_TIME, atDateTime)) # Save the light value and set the Light thread = Thread( target=self.web_gadget.setLightScheduledGradually, args=(value, inSeconds, atDateTime)) thread.daemon = True thread.start() else: raise InvalidAPIUsage( "The value is not valid: {0}".format(value), status_code=404) else: raise InvalidAPIUsage( "No such actuator: {0} or value: {1} or in_seconds: {2} or at: {3}" .format(actuator, value, inSeconds, atDateTime), status_code=404) return {'status': 'OK'}
def executeByPayload(self, payload) -> dict: actuatorId = int(payload[EPImmediatelySetLight.ATTR_ACTUATOR_ID]) value = int(payload[EPImmediatelySetLight.ATTR_VALUE]) if actuatorId == self.web_gadget.getLightId(): if value >= 0 and value <= 100: # Stop the running Thread self.web_gadget.gradualThreadController.indicateToStop() while self.web_gadget.gradualThreadController.isRunning(): logging.debug( " Waitiong for thread stops in {0} in executedByPayload() method".format(__file__)) sleep(self.__class__.TIME_WAIT_FOR_THREAD) actualValue = self.web_gadget.fetchSavedLightValue() logging.debug( "WEB request: {0} {1} ('{2}': {3}, '{4}': {5})".format( EPImmediatelySetLight.METHOD, EPImmediatelySetLight.URL, EPImmediatelySetLight.ATTR_ACTUATOR_ID, actuatorId, EPImmediatelySetLight.ATTR_VALUE, value) ) # if value == 0 and actualValue['current']: # Save the light value and set the Light # return self.web_gadget.setLight(value, actualValue['current']) # else: # Save the light value and set the Light # return self.web_gadget.setLight(value) return self.web_gadget.setLight(value, actualValue['current']) else: raise InvalidAPIUsage("The value is not valid: {0}".format(value), error_code=404) else: raise InvalidAPIUsage("No such actuator: {0} or value: {1}".format(actuatorId, value), error_code=404)
def executeByPayload(self, payload): actuatorId = int(payload[EPGraduallyIncreaseLight.ATTR_ACTUATOR_ID]) stepValue = int(payload[EPGraduallyIncreaseLight.ATTR_STEP_VALUE]) inSeconds = int(payload[EPGraduallyIncreaseLight.ATTR_IN_SECONDS]) if actuatorId == self.web_gadget.getLightId(): # Stop the running Thread self.web_gadget.gradualThreadController.indicateToStop() while self.web_gadget.gradualThreadController.isRunning(): logging.debug( " Waitiong for thread stops in {0} in executedByPayload() method" .format(__file__)) sleep(self.__class__.TIME_WAIT_FOR_THREAD) actualValue = self.web_gadget.fetchSavedLightValue() newValue = actualValue['current'] + stepValue newValue = min(100, newValue) if stepValue > 0 else max( 0, newValue) logging.debug( "{0} {1} ('{2}': {3}, '{4}': {5}, '{6}': {7}) fromValue: {8}, toValue: {9}" .format(EPGraduallyIncreaseLight.METHOD, EPGraduallyIncreaseLight.URL, EPGraduallyIncreaseLight.ATTR_ACTUATOR_ID, actuatorId, EPGraduallyIncreaseLight.ATTR_STEP_VALUE, stepValue, EPGraduallyIncreaseLight.ATTR_IN_SECONDS, inSeconds, actualValue['current'], newValue)) #thread = Thread(target = self.web_gadget.setLight, args = (actuatorId, actualValue['current'], newValue, inSeconds)) #thread = Thread(target = self.web_gadget.setLight, args = (newValue, actualValue['current'], inSeconds)) thread = Thread(target=self.runThread, args=(newValue, actualValue['current'], inSeconds)) thread.daemon = True thread.start() else: raise InvalidAPIUsage( "No such actuator: {0} or step value: {1} or seconds {2}". format(actuatorId, stepValue, inSeconds), error_code=404) return {'status': 'OK'}
def executeByPayload(self, payload) -> dict: actuatorId = int(payload[EPInfoLight.ATTR_ACTUATOR_ID]) if actuatorId == self.web_gadget.getLightId(): actualValue = self.web_gadget.fetchSavedLightValue() logging.debug("WEB request: {0} {1} ('{2}': {3})".format( EPInfoLight.METHOD, EPInfoLight.URL, EPInfoLight.ATTR_ACTUATOR_ID, actuatorId)) return { "value": actualValue, "thread": self.web_gadget.getThreadControllerStatus() } # return {"value": actualValue, "thread": {"inProgress": False, "id":1}} else: raise InvalidAPIUsage("No such actuator: {0} or value: {1}".format( actuatorId, value), error_code=404)
def executeByPayload(self, payload) -> dict: actuatorId = int(payload[EPImmediatelyIncreaseLight.ATTR_ACTUATOR_ID]) stepValue = int(payload[EPImmediatelyIncreaseLight.ATTR_STEP_VALUE]) if actuatorId == self.web_gadget.getLightId(): # Stop the running Thread self.web_gadget.gradualThreadController.indicateToStop() while self.web_gadget.gradualThreadController.isRunning(): logging.debug( " Waitiong for thread stops in {0} in executedByPayload() method" .format(__file__)) sleep(self.__class__.TIME_WAIT_FOR_THREAD) actualValueJson = self.web_gadget.fetchSavedLightValue() actualValue = actualValueJson['current'] newValue = actualValue + stepValue newValue = min(100, newValue) if stepValue > 0 else max( 0, newValue) logging.debug( "WEB request: {0} {1} ('{2}': {3}, '{4}': {5})".format( EPImmediatelyIncreaseLight.METHOD, EPImmediatelyIncreaseLight.URL, EPImmediatelyIncreaseLight.ATTR_ACTUATOR_ID, actuatorId, EPImmediatelyIncreaseLight.ATTR_STEP_VALUE, stepValue)) # Save the light value and set the Light return self.web_gadget.setLight(newValue, actualValue) else: raise InvalidAPIUsage("No such actuator: {0} or value: {1}".format( actuatorId, newValue), status_code=404)