Пример #1
0
 def __check_and_clear_schedule(self, topic: List[str],
                                message: MQTTMessage):
     schedule_uuid_or_name: str = topic[-1]
     schedule_type: str = topic[-2]
     if (schedule_type == 'uuid' and ScheduleModel.find_by_uuid(schedule_uuid_or_name) is None) or \
             (schedule_type == 'name' and ScheduleModel.find_by_name(schedule_uuid_or_name) is None) or \
             schedule_type not in ['uuid', 'name']:
         logger.warning(f'No schedule with topic: {message.topic}')
         self.__clear_mqtt_retain_value(message)
         return True
     return False
Пример #2
0
 def patch(self, name):
     data = ScheduleName.parser_patch.parse_args()
     sch = ScheduleModel.find_by_name(name)
     if sch is None:
         abort(404, message="Does not exist {}".format(name))
     try:
         non_none_data = {}
         for key in data.keys():
             if data[key] is not None:
                 non_none_data[key] = data[key]
         return self.update_schedule(sch.uuid, non_none_data)
     except Exception as e:
         abort(500, message=str(e))
Пример #3
0
 def get_schedule(cls, **kwargs) -> ScheduleModel:
     return ScheduleModel.find_by_name(kwargs.get('name'))
Пример #4
0
 def delete(self, name):
     sch = ScheduleModel.find_by_name(name)
     if sch:
         sch.delete_from_db()
     return '', 204
Пример #5
0
 def get(self, name):
     sch = ScheduleModel.find_by_name(name)
     if not sch:
         abort(404, message='Schedule is not found')
     return sch