Exemple #1
0
 def add_schedule(self, uuid, data):
     try:
         sch = ScheduleModel(uuid=uuid, **data)
         sch.save_to_db()
         return sch
     except Exception as e:
         abort(500, message=str(e))
Exemple #2
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
Exemple #3
0
 def patch(self, uuid):
     data = ScheduleSingular.parser_patch.parse_args()
     sch = ScheduleModel.find_by_uuid(uuid)
     if sch is None:
         abort(404, message="Does not exist {}".format(uuid))
     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(uuid, non_none_data)
     except Exception as e:
         abort(500, message=str(e))
Exemple #4
0
 def get_schedule(cls, **kwargs) -> ScheduleModel:
     return ScheduleModel.find_by_name(kwargs.get('name'))
Exemple #5
0
 def get_schedule(cls, **kwargs) -> ScheduleModel:
     return ScheduleModel.find_by_uuid(kwargs.get('uuid'))
Exemple #6
0
 def get(cls):
     schedules = ScheduleModel.find_all()
     return schedules
Exemple #7
0
 def delete(self, uuid):
     sch = ScheduleModel.find_by_uuid(uuid)
     if sch:
         sch.delete_from_db()
     return '', 204
Exemple #8
0
 def get(self, uuid):
     sch = ScheduleModel.find_by_uuid(uuid)
     if not sch:
         abort(404, message='Schedule is not found')
     return sch
Exemple #9
0
 def delete(self, name):
     sch = ScheduleModel.find_by_name(name)
     if sch:
         sch.delete_from_db()
     return '', 204
Exemple #10
0
 def get(self, name):
     sch = ScheduleModel.find_by_name(name)
     if not sch:
         abort(404, message='Schedule is not found')
     return sch
Exemple #11
0
 def get(self):
     return ScheduleModel.get_all()
Exemple #12
0
 def update_schedule(self, uuid, data):
     ScheduleModel.filter_by_uuid(uuid).update(data)
     db.session.commit()
     sch_return = ScheduleModel.find_by_uuid(uuid)
     return sch_return
Exemple #13
0
 def add_schedule(cls, data):
     uuid = str(shortuuid.uuid())
     schedule = ScheduleModel(uuid=uuid, **data)
     schedule.save_to_db()
     return schedule