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))
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
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))
def get_schedule(cls, **kwargs) -> ScheduleModel: return ScheduleModel.find_by_name(kwargs.get('name'))
def get_schedule(cls, **kwargs) -> ScheduleModel: return ScheduleModel.find_by_uuid(kwargs.get('uuid'))
def get(cls): schedules = ScheduleModel.find_all() return schedules
def delete(self, uuid): sch = ScheduleModel.find_by_uuid(uuid) if sch: sch.delete_from_db() return '', 204
def get(self, uuid): sch = ScheduleModel.find_by_uuid(uuid) if not sch: abort(404, message='Schedule is not found') return sch
def delete(self, name): sch = ScheduleModel.find_by_name(name) if sch: sch.delete_from_db() return '', 204
def get(self, name): sch = ScheduleModel.find_by_name(name) if not sch: abort(404, message='Schedule is not found') return sch
def get(self): return ScheduleModel.get_all()
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
def add_schedule(cls, data): uuid = str(shortuuid.uuid()) schedule = ScheduleModel(uuid=uuid, **data) schedule.save_to_db() return schedule