def GET(self, index): qdict = web.input() try: index = int(index) delete = get_input(qdict, 'delete', False, lambda x: True) runnow = get_input(qdict, 'runnow', False, lambda x: True) enable = get_input(qdict, 'enable', None, lambda x: x == '1') if delete: programs.remove_program(index) Timer(0.1, programs.calculate_balances).start() raise web.seeother('/programs') elif runnow: programs.run_now(index) Timer(0.1, programs.calculate_balances).start() raise web.seeother('/programs') elif enable is not None: programs[index].enabled = enable Timer(0.1, programs.calculate_balances).start() raise web.seeother('/programs') except ValueError: pass if isinstance(index, int): program = programs.get(index) else: program = programs.create_program() program.set_days_simple(6*60, 30, 30, 0, []) return self.core_render.program(program)
def POST(self, program_id): logger.debug('POST /programs/{}'.format(program_id if program_id else '')) if program_id: action = web.input().get('do', '').lower() program_id = int(program_id) if action == 'runnow': logger.debug('Starting program {id} ("{name}")'.format(id=program_id, name=programs[program_id].name)) programs.run_now(program_id) elif action == 'stop': pass # TODO else: logger.error('Unknown program action: "%s"', action) raise badrequest() return self._program_to_dict(programs[program_id]) else: program_data = json.loads(web.data()) p = programs.create_program() p.type = program_data.get('type', ProgramType.DAYS_SIMPLE) if p.type == ProgramType.DAYS_SIMPLE: p.set_days_simple(0, 30, 0, 0, []) # some sane defaults self._dict_to_program(p, program_data) # some sane defaults # p.enabled = False programs.add_program(p) return self._program_to_dict(programs.get(p.index))
def POST(self, program_id): logger.debug( 'POST /programs/{}'.format(program_id if program_id else '')) if program_id: action = web.input().get('do', '').lower() program_id = int(program_id) if action == 'runnow': logger.debug('Starting program {id} ("{name}")'.format( id=program_id, name=programs[program_id].name)) programs.run_now(program_id) elif action == 'stop': pass # TODO else: logger.error('Unknown program action: "%s"', action) raise badrequest() return self._program_to_dict(programs[program_id]) else: program_data = json.loads(web.data()) p = programs.create_program() p.type = program_data.get('type', ProgramType.DAYS_SIMPLE) if p.type == ProgramType.DAYS_SIMPLE: p.set_days_simple(0, 30, 0, 0, []) # some sane defaults self._dict_to_program(p, program_data) # some sane defaults # p.enabled = False programs.add_program(p) return self._program_to_dict(programs.get(p.index))
def POST(self, index): qdict = web.input() try: index = int(index) program = programs.get(index) except ValueError: program = programs.create_program() qdict['schedule_type'] = int(qdict['schedule_type']) program.name = qdict['name'] program.stations = json.loads(qdict['stations']) program.enabled = True if qdict.get('enabled', 'off') == 'on' else False if qdict['schedule_type'] == ProgramType.WEEKLY_WEATHER: program.cut_off = 0 program.fixed = True else: program.cut_off = int(qdict['cut_off']) program.fixed = True if qdict.get('fixed', 'off') == 'on' else False simple = [int(qdict['simple_hour']) * 60 + int(qdict['simple_minute']), int(qdict['simple_duration']), int(qdict['simple_pause']), int(qdict['simple_rcount']) if qdict.get('simple_repeat', 'off') == 'on' else 0] repeat_start_date = datetime.datetime.combine(datetime.date.today(), datetime.time.min) + \ datetime.timedelta(days=int(qdict['interval_delay'])) if qdict['schedule_type'] == ProgramType.DAYS_SIMPLE: program.set_days_simple(*(simple + [ json.loads(qdict['days'])])) elif qdict['schedule_type'] == ProgramType.DAYS_ADVANCED: program.set_days_advanced(json.loads(qdict['advanced_schedule_data']), json.loads(qdict['days'])) elif qdict['schedule_type'] == ProgramType.REPEAT_SIMPLE: program.set_repeat_simple(*(simple + [ int(qdict['interval']), repeat_start_date])) elif qdict['schedule_type'] == ProgramType.REPEAT_ADVANCED: program.set_repeat_advanced(json.loads(qdict['advanced_schedule_data']), int(qdict['interval']), repeat_start_date) elif qdict['schedule_type'] == ProgramType.WEEKLY_ADVANCED: program.set_weekly_advanced(json.loads(qdict['weekly_schedule_data'])) elif qdict['schedule_type'] == ProgramType.WEEKLY_WEATHER: program.set_weekly_weather(int(qdict['weather_irrigation_min']), int(qdict['weather_irrigation_max']), int(qdict['weather_run_max']), int(qdict['weather_pause_ratio'])/100.0, json.loads(qdict['weather_pems_data']), ) elif qdict['schedule_type'] == ProgramType.CUSTOM: program.modulo = int(qdict['interval'])*1440 program.manual = False program.start = repeat_start_date program.schedule = json.loads(qdict['custom_schedule_data']) if program.index < 0: programs.add_program(program) Timer(0.1, programs.calculate_balances).start() raise web.seeother('/programs')