def _option_cb(self, key, old, new): # Clear if manual mode changed: if key == 'manual_mode': programs.run_now_program = None run_once.clear() log.finish_run(None) stations.clear() # Stop relay if not used anymore: if key == 'master_relay' and not new and outputs.relay_output: outputs.relay_output = False
def _botCmd_stop(self, bot, update): # msg for stop all station and disable scheduler chat_id = update.message.chat.id if chat_id in list(self._currentChats): txt = _(u'{} System - scheduler OFF. All stations OFF.').format(options.name) programs.run_now_program = None run_once.clear() log.finish_run(None) stations.clear() else: txt = _(u'Sorry I can not do that.') if is_python2(): bot.sendMessage(chat_id, text=txt.encode('utf-8')) else: bot.sendMessage(chat_id, text=txt)
def GET(self): from ospy import server qdict = web.input() stop_all = get_input(qdict, 'stop_all', False, lambda x: True) scheduler_enabled = get_input(qdict, 'scheduler_enabled', None, lambda x: x == '1') manual_mode = get_input(qdict, 'manual_mode', None, lambda x: x == '1') rain_block = get_input(qdict, 'rain_block', None, float) level_adjustment = get_input(qdict, 'level_adjustment', None, float) toggle_temp = get_input(qdict, 'toggle_temp', False, lambda x: True) if stop_all: if not options.manual_mode: options.scheduler_enabled = False programs.run_now_program = None run_once.clear() log.finish_run(None) stations.clear() if scheduler_enabled is not None: options.scheduler_enabled = scheduler_enabled if manual_mode is not None: options.manual_mode = manual_mode if rain_block is not None: options.rain_block = datetime.datetime.now() + datetime.timedelta(hours=rain_block) if level_adjustment is not None: options.level_adjustment = level_adjustment / 100 if toggle_temp: options.temp_unit = "F" if options.temp_unit == "C" else "C" set_to = get_input(qdict, 'set_to', None, int) sid = get_input(qdict, 'sid', 0, int) - 1 set_time = get_input(qdict, 'set_time', 0, int) if set_to is not None and 0 <= sid < stations.count() and options.manual_mode: if set_to: # if status is on start = datetime.datetime.now() new_schedule = { 'active': True, 'program': -1, 'station': sid, 'program_name': "Manual", 'fixed': True, 'cut_off': 0, 'manual': True, 'blocked': False, 'start': start, 'original_start': start, 'end': start + datetime.timedelta(days=3650), 'uid': '%s-%s-%d' % (str(start), "Manual", sid), 'usage': stations.get(sid).usage } if set_time > 0: # if an optional duration time is given new_schedule['end'] = datetime.datetime.now() + datetime.timedelta(seconds=set_time) log.start_run(new_schedule) stations.activate(new_schedule['station']) else: # If status is off stations.deactivate(sid) active = log.active_runs() for interval in active: if interval['station'] == sid: log.finish_run(interval) self._redirect_back()
def FTP_download(self): try: # read command file and save to ramdisk self.ftp.retrbinary("RETR " + plugin_options['loc'] + "data.txt", open("/home/pi/ramdisk/data.txt", 'wb').write) fs = file("/home/pi/ramdisk/data.txt", 'r') obsahaut = fs.readline() fs.close() log.debug( NAME, _(u'FTP received data from file data.txt') + ': ' + str(obsahaut)) change = False if (obsahaut == "AU"): # scheduller options.manual_mode = False log.info(NAME, _(u'Scheduler mode is activated.')) change = True if (obsahaut == "MA"): # manual options.manual_mode = True log.info(NAME, _(u'Manual mode is activated.')) change = True for num_output in range(0, options.output_count): s = 'Z' + str(num_output) if (obsahaut == s): # stations xx ON options.manual_mode = True log.info(NAME, _(u'Manual mode is activated.')) stations.activate(num_output) log.info(NAME, _(u'Activated stations') + ': ' + str(num_output + 1)) change = True s = 'V' + str(num_output) if (obsahaut == s): # stations xx OFF options.manual_mode = True log.info(NAME, _(u'Manual mode is activated.')) stations.deactivate(num_output) log.info( NAME, _(u'Deactivated stations') + ': ' + str(num_output + 1)) change = True for program in programs.get(): s = 'P' + str(program.index + 1) if (obsahaut == s): # Run-now program xx options.manual_mode = False log.info(NAME, _(u'Scheduler mode is activated.')) programs.run_now(program.index) log.info(NAME, _(u'Activated program') + ': ' + str(program.name)) self._sleep(2) change = True program.index + 1 if (obsahaut == "STOP"): # stop all stations and disable scheduler options.scheduler_enabled = False programs.run_now_program = None run_once.clear() log.finish_run(None) stations.clear() log.info(NAME, _(u'Stop all stations and disable system.')) change = True if (obsahaut == "START"): # enable scheduler options.scheduler_enabled = True log.info(NAME, _(u'Enable system.')) change = True if (change): # delete data.txt command now is OK fs = open('/home/pi/ramdisk/data.txt', 'w') fs.write('OK') fs.close() FTP_upload(self) # send to server actual data # TODO save_to_options except Exception: log.clear(NAME) log.info( NAME, _(u'Remote FTP control settings') + ':\n' + traceback.format_exc()) pass