Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
Arquivo: api.py Projeto: Rimco/OSPy
    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))
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
    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))
Exemplo n.º 5
0
 def _botCmd_runOnce(self, bot, update, args):             # run-now program xx
     chat_id = update.message.chat.id
     if chat_id in list(self._currentChats):
         txt = _(u'{} RunOnce: program {}.').format(options.name, args)
         for program in programs.get():
             if (program.index == int(args-1)):   
                 options.manual_mode = False   
                 log.finish_run(None)
                 stations.clear()    
                 programs.run_now(program.index)
                 break       
             program.index+1
     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)
Exemplo n.º 6
0
    def run(self):       
        log.clear(NAME)  
        while not self._stop.is_set():
            try:
                if plugin_options['use_button']:  # if button plugin is enabled
                    actual_buttons = read_buttons()
                    
                    #led_outputs(actual_buttons)

                    for i in range(8):
                       tb = "button" + str(i)    
                       if actual_buttons == i and plugin_options[tb]== "reboot":
                          log.info(NAME, datetime_string() + ': ' + _('System reboot')) 
                          stations.clear()
                          reboot()
                          self._sleep(2)
                       
                       if actual_buttons == i and plugin_options[tb]== "pwrOff":
                          log.info(NAME, datetime_string() + ': ' + _('System shutdown')) 
                          stations.clear()
                          poweroff()
                          self._sleep(2)
                         
                       if actual_buttons == i and plugin_options[tb]== "stopAll":
                          log.info(NAME, datetime_string() + ': ' + _('All stations now stopped')) 
                          log.finish_run(None)       # save log
                          stations.clear()           # set all station to off 
                          self._sleep(2)

                       if actual_buttons == i and plugin_options[tb]== "schedEn":
                          log.info(NAME, datetime_string() + ': ' + _('Scheduler is now enabled')) 
                          options.scheduler_enabled = True
                          self._sleep(2)

                       if actual_buttons == i and plugin_options[tb]== "schedDis":
                          log.info(NAME, datetime_string() + ': ' + _('Scheduler is now disabled')) 
                          options.scheduler_enabled = False
                          self._sleep(2)

                       if actual_buttons == i and plugin_options[tb]== "RunP1":
                          log.info(NAME, datetime_string() + ': ' + _('Run now program 1')) 
                          for program in programs.get():
                             if (program.index == 0):   # Run-now program 1
                                options.manual_mode = False   
                                log.finish_run(None)
                                stations.clear()    
                                programs.run_now(program.index)       
                             program.index+1
                          self._sleep(2)

                       if actual_buttons == i and plugin_options[tb]== "RunP2":
                          log.info(NAME, datetime_string() + ': ' + _('Run now program 2')) 
                          for program in programs.get():
                             if (program.index == 1):   # Run-now program 2  
                                options.manual_mode = False     
                                log.finish_run(None)
                                stations.clear()   
                                programs.run_now(program.index)
                             program.index+1
                          self._sleep(2)

                       if actual_buttons == i and plugin_options[tb]== "RunP3":
                          log.info(NAME, datetime_string() + ': ' + _('Run now program 3')) 
                          for program in programs.get():
                             if (program.index == 2):   # Run-now program 3  
                                options.manual_mode = False     
                                log.finish_run(None)  
                                stations.clear() 
                                programs.run_now(program.index)
                             program.index+1
                          self._sleep(2)
                            
                       if actual_buttons == i and plugin_options[tb]== "RunP4":
                          log.info(NAME, datetime_string() + ': ' + _('Run now program 4')) 
                          for program in programs.get():
                             if (program.index == 3):   # Run-now program 4  
                                options.manual_mode = False   
                                log.finish_run(None)
                                stations.clear()     
                                programs.run_now(program.index)
                             program.index+1
                          self._sleep(2)        
 
                       if actual_buttons == i and plugin_options[tb]== "RunP5":
                          log.info(NAME, datetime_string() + ': ' + _('Run now program 5'))
                          for program in programs.get():
                             if (program.index == 4):   # Run-now program 5
                                options.manual_mode = False
                                log.finish_run(None)
                                stations.clear() 
                                programs.run_now(program.index)
                             program.index+1
                          self._sleep(2)

                       if actual_buttons == i and plugin_options[tb]== "RunP6":
                          log.info(NAME, datetime_string() + ': ' + _('Run now program 6'))
                          for program in programs.get():
                             if (program.index == 5):   # Run-now program 6
                                options.manual_mode = False
                                log.finish_run(None)
                                stations.clear() 
                                programs.run_now(program.index)
                             program.index+1
                          self._sleep(2)

                       if actual_buttons == i and plugin_options[tb]== "RunP7":
                          log.info(NAME, datetime_string() + ': ' + _('Run now program 7'))
                          for program in programs.get():
                             if (program.index == 6):   # Run-now program 7
                                options.manual_mode = False
                                log.finish_run(None)
                                stations.clear() 
                                programs.run_now(program.index)
                             program.index+1
                          self._sleep(2)

                       if actual_buttons == i and plugin_options[tb]== "RunP8":
                          log.info(NAME, datetime_string() + ': ' + _('Run now program 8'))
                          for program in programs.get():
                             if (program.index == 7):   # Run-now program 8
                                options.manual_mode = False
                                log.finish_run(None)
                                stations.clear() 
                                programs.run_now(program.index)
                             program.index+1
                          self._sleep(2)

                    self._sleep(1)

            except Exception:
                log.clear(NAME)
                log.error(NAME, _('Button plug-in') + ':\n' + traceback.format_exc())
                self._sleep(60)
                pass
Exemplo n.º 7
0
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
Exemplo n.º 8
0
def sms_check(self):
    """Control and processing SMS"""
    try:
        import gammu
    except Exception:
        log.error(NAME,
                  _('SMS Modem plug-in') + ':\n' + traceback.format_exc())

    tel1 = sms_options['tel1']
    tel2 = sms_options['tel2']
    comm1 = sms_options['txt1']
    comm2 = sms_options['txt2']
    comm3 = sms_options['txt3']
    comm4 = sms_options['txt4']
    comm5 = sms_options['txt5']
    comm6 = sms_options['txt6']
    comm7 = sms_options['txt7']
    comm8 = sms_options['txt8']
    comm9 = sms_options['txt9']

    sm = gammu.StateMachine()
    sm.ReadConfig()
    try:
        sm.Init()
        log.debug(NAME, datetime_string() + ': ' + _('Checking SMS...'))
    except:
        log.error(NAME,
                  _('SMS Modem plug-in') + ':\n' + traceback.format_exc())
        self._sleep(60)

    if sms_options[
            "use_strength"]:  # print strength signal in status Window every check SMS
        signal = sm.GetSignalQuality(
        )  # list: SignalPercent, SignalStrength, BitErrorRate
        log.info(
            NAME,
            datetime_string() + ': ' + _('Signal') + ': ' +
            str(signal['SignalPercent']) + '% ' +
            str(signal['SignalStrength']) + 'dB')

    status = sm.GetSMSStatus()
    remain = status['SIMUsed'] + status['PhoneUsed'] + status['TemplatesUsed']
    sms = []
    start = True
    while remain > 0:
        if start:
            cursms = sm.GetNextSMS(Start=True, Folder=0)
            start = False
        else:
            cursms = sm.GetNextSMS(Location=cursms[0]['Location'], Folder=0)
        remain = remain - len(cursms)
        sms.append(cursms)
    data = gammu.LinkSMS(sms)
    for x in data:
        v = gammu.DecodeSMS(x)
        m = x[0]
        print '%-15s: %s' % ('Sender', m['Number'])
        print '%-15s: %s' % ('Date', str(m['DateTime']))
        print '%-15s: %s' % ('State', m['State'])
        print '%-15s: %s' % ('SMS command', m['Text'])
        if (m['Number']
                == tel1) or (m['Number']
                             == tel2):  # If telephone is admin 1 or admin 2
            log.info(NAME, datetime_string() + ': ' + _('SMS from admin'))
            if m['State'] == "UnRead":  # If SMS is unread
                log.clear(NAME)
                if m['Text'] == comm1:  # If command = comm1 (info - send SMS to admin phone1 and phone2)
                    log.info(
                        NAME,
                        _('Command') + ' ' + comm1 + ' ' + _('is processed'))
                    # send 1/2 SMS with text 1
                    up = helpers.uptime()
                    temp = helpers.get_cpu_temp(
                        options.temp_unit) + ' ' + options.temp_unit
                    ip = str(helpers.get_ip())
                    ver = version.ver_date
                    datastr = ('SMS 1/2. ' + datetime_string() + ', TEMP: ' +
                               temp + ', IP: ' + ip + ', SW: ' + ver +
                               ', UP: ' + up)
                    message = {
                        'Text': datastr,
                        'SMSC': {
                            'Location': 1
                        },
                        'Number': m['Number'],
                    }
                    sm.SendSMS(message)  # send sms 1/2
                    log.info(NAME, datastr)
                    # send 2/2 SMS with text 2
                    if inputs.rain_sensed():
                        rain = "Active"
                    else:
                        rain = "Inactive"
                    try:
                        from plugins import pressure_monitor
                        state_press = pressure_monitor.get_check_pressure()

                        if state_press:
                            press = "High"
                        else:
                            press = "Low"
                    except Exception:
                        press = "N/A"
                    finished = [
                        run for run in log.finished_runs()
                        if not run['blocked']
                    ]
                    if finished:
                        last_prog = finished[-1]['start'].strftime(
                            '%H:%M: ') + finished[-1]['program_name']
                    else:
                        last_prog = 'None'
                    datastr = ('SMS 2/2. ' + 'RAIN: ' + rain + ', PRESS: ' +
                               press + ', LAST: ' + last_prog)
                    message = {
                        'Text': datastr,
                        'SMSC': {
                            'Location': 1
                        },
                        'Number': m['Number'],
                    }
                    sm.SendSMS(message)  # send sms 2/2
                    log.info(NAME, datastr)

                    log.info(
                        NAME,
                        _('Command') + ': ' + comm1 + ' ' +
                        _('was processed and confirmation was sent as SMS to')
                        + ': ' + m['Number'])
                    sm.DeleteSMS(m['Folder'], m['Location'])  # SMS deleted
                    log.info(NAME, _('Received SMS was deleted'))

                elif m['Text'] == comm2:  # If command = comm2 (stop - scheduler)
                    log.info(
                        NAME,
                        _('Command') + ' ' + comm2 + ' ' + _('is processed'))
                    options.scheduler_enabled = False
                    log.finish_run(None)
                    stations.clear()

                    message = {
                        'Text': 'Command: ' + comm2 + ' was processed',
                        'SMSC': {
                            'Location': 1
                        },
                        'Number': m['Number'],
                    }
                    sm.SendSMS(message)
                    log.info(
                        NAME,
                        _('Command') + ': ' + comm2 + ' ' +
                        _('was processed and confirmation was sent as SMS to')
                        + ': ' + m['Number'])
                    sm.DeleteSMS(m['Folder'], m['Location'])
                    log.info(NAME, _('Received SMS was deleted'))

                elif m['Text'] == comm3:  # If command = comm3 (start - scheduler)
                    log.info(
                        NAME,
                        _('Command') + ' ' + comm3 + ' ' + _('is processed'))
                    options.scheduler_enabled = True
                    message = {
                        'Text': 'Command: ' + comm3 + ' was processed',
                        'SMSC': {
                            'Location': 1
                        },
                        'Number': m['Number'],
                    }
                    sm.SendSMS(message)
                    log.info(
                        NAME,
                        _('Command') + ': ' + comm3 + ' ' +
                        _('was processed and confirmation was sent as SMS to')
                        + ': ' + m['Number'])
                    sm.DeleteSMS(m['Folder'], m['Location'])
                    log.info(NAME, _('Received SMS was deleted'))

                elif m['Text'] == comm4:  # If command = comm4 (reboot system)
                    log.info(
                        NAME,
                        _('Command') + ' ' + comm4 + ' ' + _('is processed'))
                    message = {
                        'Text': 'Command: ' + comm4 + ' was processed',
                        'SMSC': {
                            'Location': 1
                        },
                        'Number': m['Number'],
                    }
                    sm.SendSMS(message)
                    log.info(
                        NAME,
                        _('Command') + ': ' + comm4 + ' ' +
                        _('was processed and confirmation was sent as SMS to')
                        + ': ' + m['Number'])
                    sm.DeleteSMS(m['Folder'], m['Location'])
                    log.info(
                        NAME,
                        _('Received SMS was deleted and system is now reboot'))
                    reboot()  # restart linux system

                elif m['Text'] == comm5:  # If command = comm5 (poweroff system)
                    log.info(
                        NAME,
                        _('Command') + ' ' + comm5 + ' ' + _('is processed'))
                    message = {
                        'Text': 'Command: ' + comm5 + ' was processed',
                        'SMSC': {
                            'Location': 1
                        },
                        'Number': m['Number'],
                    }
                    sm.SendSMS(message)
                    log.info(
                        NAME,
                        _('Command') + ': ' + comm5 + ' ' +
                        _('was processed and confirmation was sent as SMS to')
                        + ': ' + m['Number'])
                    sm.DeleteSMS(m['Folder'], m['Location'])
                    log.info(
                        NAME,
                        _('Received SMS was deleted and system is now poweroff'
                          ))
                    poweroff()  # poweroff linux system

                elif m['Text'] == comm6:  # If command = comm6 (update ospi system)
                    log.info(
                        NAME,
                        _('Command') + ' ' + comm6 + ' ' + _('is processed'))
                    message = {
                        'Text': 'Command: ' + comm6 + ' was processed',
                        'SMSC': {
                            'Location': 1
                        },
                        'Number': m['Number'],
                    }
                    sm.SendSMS(message)
                    log.info(
                        NAME,
                        _('Command') + ': ' + comm6 + ' ' +
                        _('was processed and confirmation was sent as SMS to')
                        + ': ' + m['Number'])
                    try:
                        from plugins.system_update import perform_update

                        perform_update()
                        log.info(
                            NAME,
                            _('Received SMS was deleted, update was performed and program will restart'
                              ))
                    except ImportError:
                        log.info(
                            NAME,
                            _('Received SMS was deleted, but could not perform update'
                              ))

                    sm.DeleteSMS(m['Folder'], m['Location'])

                elif m['Text'] == comm7:  # If command = comm7 (send email with foto from webcam)
                    log.info(
                        NAME,
                        _('Command') + ' ' + comm7 + ' ' + _('is processed'))
                    message = {
                        'Text': 'Command: ' + comm7 + ' was processed',
                        'SMSC': {
                            'Location': 1
                        },
                        'Number': m['Number'],
                    }
                    sm.SendSMS(message)
                    log.info(
                        NAME,
                        _('Command') + ': ' + comm7 + ' ' +
                        _('was processed and confirmation was sent as SMS to')
                        + ': ' + m['Number'])
                    try:
                        from plugins.webcam import get_run_cam, get_image_location

                        get_run_cam()  # process save foto to ./data/image.jpg
                        msg = _('SMS plug-in send image file from webcam.')

                        send_email(msg, attach=get_image_location())

                    except ImportError:
                        log.info(
                            NAME,
                            _('Received SMS was deleted, but could not send email with photo from webcam'
                              ))
                        message = {
                            'Text': 'Error: not send foto from webcam',
                            'SMSC': {
                                'Location': 1
                            },
                            'Number': m['Number'],
                        }
                        sm.SendSMS(message)
                    sm.DeleteSMS(m['Folder'], m['Location'])

                elif m['Text'] == comm8:  # If command = comm8 (send SMS with available commands)
                    log.info(
                        NAME,
                        _('Command') + ' ' + comm8 + ' ' + _('is processed'))
                    message = {
                        'Text':
                        'Available commands: ' + comm1 + ',' + comm2 + ',' +
                        comm3 + ',' + comm4 + ',' + comm5 + ',' + comm6 + ',' +
                        comm7 + ',' + comm8 + ',' + comm9 + 'xx',
                        'SMSC': {
                            'Location': 1
                        },
                        'Number':
                        m['Number'],
                    }
                    sm.SendSMS(message)
                    log.info(
                        NAME,
                        _('Command') + ': ' + comm8 + ' ' +
                        _('was processed and confirmation was sent as SMS to')
                        + ': ' + m['Number'])
                    sm.DeleteSMS(m['Folder'], m['Location'])
                    log.info(NAME, _('Received SMS was deleted'))

                elif m['Text'][0:len(
                        comm9
                )] == comm9:  # If command = lenght char comm9 (run now program xx)
                    num = m['Text'][len(
                        comm9
                    ):]  # number from sms text example: run36 -> num=36
                    log.info(
                        NAME,
                        _('Command') + ' ' + comm9 + ' ' + _('is processed'))
                    index = int(num)
                    if index <= programs.count(
                    ):  # if program number from sms text exists in program db
                        log.finish_run(None)
                        stations.clear()
                        prog = int(index - 1)
                        programs.run_now(prog)
                        log.info(
                            NAME,
                            _('Program') + ': ' + str(index) + ' ' +
                            _('now run'))
                        message = {
                            'Text': 'Program: ' + str(index) + ' now run',
                            'SMSC': {
                                'Location': 1
                            },
                            'Number': m['Number'],
                        }
                    else:
                        message = {
                            'Text': 'Program: ' + str(index) + ' no exists!',
                            'SMSC': {
                                'Location': 1
                            },
                            'Number': m['Number'],
                        }

                    sm.SendSMS(message)
                    log.info(
                        NAME,
                        _('Command') + ': ' + str(m['Text']) + ' ' +
                        _('was processed and confirmation was sent as SMS to')
                        + ': ' + m['Number'])
                    sm.DeleteSMS(m['Folder'], m['Location'])
                    log.info(NAME, _('Received SMS was deleted'))

                else:  # If SMS command is not defined
                    sm.DeleteSMS(m['Folder'], m['Location'])
                    log.info(
                        NAME,
                        _('Received command') + ' ' + m['Text'] + ' ' +
                        _('is not defined!'))

            else:  # If SMS was read
                sm.DeleteSMS(m['Folder'], m['Location'])
                log.info(NAME, _('Received SMS was deleted - SMS was read'))
        else:  # If telephone number is not admin 1 or admin 2 phone number
            sm.DeleteSMS(m['Folder'], m['Location'])
            log.info(NAME,
                     _('Received SMS was deleted - SMS was not from admin'))
Exemplo n.º 9
0
    def run(self):
        log.clear(NAME)
        disable_text = True

        while not self._stop_event.is_set():
            try:
                if plugin_options['use_button']:  # if button plugin is enabled
                    disable_text = True
                    actual_buttons = read_buttons()

                    # led_outputs(actual_buttons) # for test

                    for i in range(8):
                        tb = "button" + str(i)
                        if actual_buttons == i and plugin_options[
                                tb] == "reboot":
                            log.info(
                                NAME,
                                datetime_string() + ': ' + _(u'System reboot'))
                            stations.clear()
                            report_rebooted()
                            reboot(block=True)  # Linux HW software
                            self._sleep(1)

                        if actual_buttons == i and plugin_options[
                                tb] == "pwrOff":
                            log.info(
                                NAME,
                                datetime_string() + ': ' +
                                _(u'System shutdown'))
                            stations.clear()
                            report_poweroff()
                            poweroff(wait=10, block=True)  # shutdown HW system
                            self._sleep(1)

                        if actual_buttons == i and plugin_options[
                                tb] == "stopAll":
                            log.info(
                                NAME,
                                datetime_string() + ': ' +
                                _(u'Selected stations now stopped'))
                            set_stations_in_scheduler_off()
                            self._sleep(1)

                        if actual_buttons == i and plugin_options[
                                tb] == "schedEn":
                            log.info(
                                NAME,
                                datetime_string() + ': ' +
                                _(u'Scheduler is now enabled'))
                            options.scheduler_enabled = True
                            self._sleep(1)

                        if actual_buttons == i and plugin_options[
                                tb] == "schedDis":
                            log.info(
                                NAME,
                                datetime_string() + ': ' +
                                _(u'Scheduler is now disabled'))
                            options.scheduler_enabled = False
                            self._sleep(1)

                        if actual_buttons == i and plugin_options[
                                tb] == "RunP1":
                            log.info(
                                NAME,
                                datetime_string() + ': ' +
                                _(u'Run now program 1'))
                            for program in programs.get():
                                if (program.index == 0):  # Run-now program 1
                                    options.manual_mode = False
                                    if plugin_options['first_stop']:
                                        log.finish_run(None)
                                        stations.clear()
                                    programs.run_now(program.index)
                                program.index + 1
                            self._sleep(1)

                        if actual_buttons == i and plugin_options[
                                tb] == "RunP2":
                            log.info(
                                NAME,
                                datetime_string() + ': ' +
                                _(u'Run now program 2'))
                            for program in programs.get():
                                if (program.index == 1):  # Run-now program 2
                                    options.manual_mode = False
                                    if plugin_options['first_stop']:
                                        log.finish_run(None)
                                        stations.clear()
                                    programs.run_now(program.index)
                                program.index + 1
                            self._sleep(1)

                        if actual_buttons == i and plugin_options[
                                tb] == "RunP3":
                            log.info(
                                NAME,
                                datetime_string() + ': ' +
                                _(u'Run now program 3'))
                            for program in programs.get():
                                if (program.index == 2):  # Run-now program 3
                                    options.manual_mode = False
                                    if plugin_options['first_stop']:
                                        log.finish_run(None)
                                        stations.clear()
                                    programs.run_now(program.index)
                                program.index + 1
                            self._sleep(1)

                        if actual_buttons == i and plugin_options[
                                tb] == "RunP4":
                            log.info(
                                NAME,
                                datetime_string() + ': ' +
                                _(u'Run now program 4'))
                            for program in programs.get():
                                if (program.index == 3):  # Run-now program 4
                                    options.manual_mode = False
                                    if plugin_options['first_stop']:
                                        log.finish_run(None)
                                        stations.clear()
                                    programs.run_now(program.index)
                                program.index + 1
                            self._sleep(1)

                        if actual_buttons == i and plugin_options[
                                tb] == "RunP5":
                            log.info(
                                NAME,
                                datetime_string() + ': ' +
                                _('Run now program 5'))
                            for program in programs.get():
                                if (program.index == 4):  # Run-now program 5
                                    options.manual_mode = False
                                    if plugin_options['first_stop']:
                                        log.finish_run(None)
                                        stations.clear()
                                    programs.run_now(program.index)
                                program.index + 1
                            self._sleep(1)

                        if actual_buttons == i and plugin_options[
                                tb] == "RunP6":
                            log.info(
                                NAME,
                                datetime_string() + ': ' +
                                _(u'Run now program 6'))
                            for program in programs.get():
                                if (program.index == 5):  # Run-now program 6
                                    options.manual_mode = False
                                    if plugin_options['first_stop']:
                                        log.finish_run(None)
                                        stations.clear()
                                    programs.run_now(program.index)
                                program.index + 1
                            self._sleep(1)

                        if actual_buttons == i and plugin_options[
                                tb] == "RunP7":
                            log.info(
                                NAME,
                                datetime_string() + ': ' +
                                _(u'Run now program 7'))
                            for program in programs.get():
                                if (program.index == 6):  # Run-now program 7
                                    options.manual_mode = False
                                    if plugin_options['first_stop']:
                                        log.finish_run(None)
                                        stations.clear()
                                    programs.run_now(program.index)
                                program.index + 1
                            self._sleep(1)

                        if actual_buttons == i and plugin_options[
                                tb] == "RunP8":
                            log.info(
                                NAME,
                                datetime_string() + ': ' +
                                _(u'Run now program 8'))
                            for program in programs.get():
                                if (program.index == 7):  # Run-now program 8
                                    options.manual_mode = False
                                    if plugin_options['first_stop']:
                                        log.finish_run(None)
                                        stations.clear()
                                    programs.run_now(program.index)
                                program.index + 1
                            self._sleep(1)

                    self._sleep(1)

                else:
                    # text on the web if plugin is disabled
                    if disable_text:
                        log.clear(NAME)
                        log.info(NAME, _(u'Button plug-in is disabled.'))
                        disable_text = False
                    self._sleep(1)

            except Exception:
                log.clear(NAME)
                log.error(
                    NAME,
                    _(u'Button plug-in') + ':\n' + traceback.format_exc())
                self._sleep(60)
                pass