Exemplo n.º 1
0
def try_mail(text, logtext, attachment=None, subject=None):
    ### Try send e-mail ###   
    log.clear(NAME)
    try:
        email(text, subject, attachment)  # send email with attachment from
        log.info(NAME, _(u'E-mail was sent') + ':\n' + logtext)
        if not options.run_logEM:
            log.info(NAME, _(u'E-mail logging is disabled in options...'))
        else:    
            logEM.save_email_log(subject or email_options['emlsubject'], logtext, _(u'Sent'))

    except Exception:
        log.error(NAME, _(u'E-mail was not sent! Connection to Internet not ready.'))
        logEM.save_email_log(subject or email_options['emlsubject'], logtext, _(u'E-mail was not sent! Connection to Internet not ready.'))
        if not options.run_logEM:
            log.info(NAME, _(u'E-mail logging is disabled in options...'))
            
        if email_options["emlrepeater"]: # saving e-mails is enabled  
            data = {}
            data['date'] = str(datetime.now().strftime('%d.%m.%Y'))
            data['time'] = str(datetime.now().strftime('%H:%M:%S'))   
            data['text'] = u'%s' % text
            data['logtext'] = u'%s' % logtext
            data['subject'] = u'%s' % email_options['emlsubject']
            data['attachment'] = u'%s' % attachment

            update_saved_emails(data)    # saving e-mail data to file: saved_emails.json
Exemplo n.º 2
0
def notify_station_off(name, **kw):
    if plugin_options['enabled']:
        current_time = datetime.datetime.now()
        try:
            if int(current_time.hour) >= int(
                    plugin_options['start_hour']) and int(
                        current_time.hour) <= int(plugin_options['stop_hour']):
                st_nr = int(kw[u"txt"])
                log.clear(NAME)
                log.info(
                    NAME,
                    datetime_string() + u': ' +
                    _(u'Stations {} OFF').format(str(st_nr + 1)))
                data = {}
                if len(plugin_options['sounds']) > 0:
                    data['song'] = plugin_options['sounds'][int(
                        plugin_options['off'][st_nr])]
                    path = os.path.join(plugin_data_dir(), data['song'])
                    if os.path.isfile(path):
                        update_song_queue(data)  # save song name to song queue
                    else:
                        log.info(
                            NAME,
                            datetime_string() + u': ' + _(u'File not exists!'))
        except Exception:
            log.error(
                NAME,
                _(u'Voice Station plug-in') + ':\n' + traceback.format_exc())
Exemplo n.º 3
0
    def GET(self):
        global must_stop
        qdict = web.input()

        if checker is not None:
            stop = helpers.get_input(qdict, 'stop', False, lambda x: True)
            clear = helpers.get_input(qdict, 'clear', False, lambda x: True)

            if 'test' in qdict:
                command = -1
                data = {}
                if 'state' in qdict and int(qdict['state']) == 1:
                    command = plugin_options['on'][int(qdict['test'])]
                if 'state' in qdict and int(qdict['state']) == 0:
                    command = plugin_options['off'][int(qdict['test'])]

                if len(plugin_options['sounds']) > 0 and command != -1:
                    data['song'] = plugin_options['sounds'][command]
                    path = os.path.join(plugin_data_dir(), data['song'])
                    if os.path.isfile(path):
                        log.info(
                            NAME,
                            datetime_string() + u': ' +
                            _(u'Button test, song {}.').format(data['song']))
                        update_song_queue(data)  # save song name to song queue
                    else:
                        log.info(
                            NAME,
                            datetime_string() + u': ' + _(u'File not exists!'))
                else:
                    log.info(
                        NAME,
                        datetime_string() + u': ' + _(u'File not exists!'))

            if stop:
                must_stop = True
                log.info(NAME, datetime_string() + u': ' + _(u'Button Stop.'))

            if clear:
                must_stop = True
                song_queue = read_song_queue()
                while len(song_queue) > 0:
                    song_queue = read_song_queue()
                    del song_queue[0]
                    write_song_queue(song_queue)
                log.clear(NAME)
                log.info(
                    NAME,
                    datetime_string() + u': ' + _(u'Button clear playlist.'))

        try:
            return self.plugin_render.voice_station(plugin_options,
                                                    log.events(NAME))
        except Exception:
            log.error(
                NAME,
                _(u'Voice Station plug-in') + ':\n' + traceback.format_exc())
            set_to_default()
            return self.plugin_render.voice_station(plugin_options,
                                                    log.events(NAME))
Exemplo n.º 4
0
def get_overview():
    """Returns the info data as a list of lines."""
    result = []
    log.clear(NAME)
    meminfo = helpers.get_meminfo()
    netdevs = helpers.get_netdevs()

    result.append('System release: ' + platform.release())
    result.append('System name:    ' + platform.system())
    result.append('Node:           ' + platform.node())
    result.append('Machine:        ' + platform.machine())
    result.append('Total memory:   ' + meminfo['MemTotal'])
    result.append('Free memory:    ' + meminfo['MemFree'])
    if netdevs:
        for dev, info in netdevs.items():
            result.append('%-16s %s MiB %s MiB' %
                          (dev + ':', info['rx'], info['tx']))
    else:
        result.append('Network:        Unknown')
    result.append('Uptime:         ' + helpers.uptime())
    result.append('CPU temp:       ' +
                  helpers.get_cpu_temp(options.temp_unit) + ' ' +
                  options.temp_unit)
    result.append('MAC adress: ' + helpers.get_mac())
    try:
        result.append('I2C HEX Adress:')
        rev = str(0 if helpers.get_rpi_revision() == 1 else 1)
        cmd = 'sudo i2cdetect -y ' + rev
        result.append(process(cmd))
    except Exception:
        log.error(NAME, 'System info plug-in:\n' + traceback.format_exc())
    log.info(NAME, result)
    return result
Exemplo n.º 5
0
 def try_send(self, text):
     log.clear(NAME)
     try:
         send_data(text)  # send get data
         log.info(NAME, _('Remote was sent') + ':\n' + text)
     except Exception:
         log.error(NAME, _('Remote was not sent') + '!\n' + traceback.format_exc())
Exemplo n.º 6
0
    def GET(self):
        global sender
        qdict = web.input()
        delete = helpers.get_input(qdict, 'delete', False, lambda x: True)
        show = helpers.get_input(qdict, 'show', False, lambda x: True)
        state = helpers.get_input(qdict, 'state', False, lambda x: True)

        if sender is not None and 'test' in qdict:
            test = qdict['test']
            if state:
                log.clear(NAME)
                log.info(NAME, _(u'Test CMD: {} ON.').format(int(test) + 1))
                command = plugin_options['on']
                data = command[int(test)]
                if data:
                    run_command(data)
            else:
                log.clear(NAME)
                log.info(NAME, _(u'Test CMD: {} OFF.').format(int(test) + 1))
                command = plugin_options['off']
                data = command[int(test)]
                if data:
                    run_command(data)

        if sender is not None and delete:
            write_log([])
            log.info(NAME, _(u'Deleted all log files OK'))
            raise web.seeother(plugin_url(settings_page), True)

        if sender is not None and show:
            raise web.seeother(plugin_url(log_page), True)

        return self.plugin_render.cli_control(plugin_options, log.events(NAME))
Exemplo n.º 7
0
 def try_mail(self, text, attachment=None):
     log.clear(NAME)
     try:
         email(text, attach=attachment)  # send email with attachment from
         log.info(NAME, 'Email was sent:\n' + text)
     except Exception:
         log.error(NAME, 'Email was not sent!\n' + traceback.format_exc())
Exemplo n.º 8
0
    def GET(self):
        qdict = web.input()
        errorCode = qdict.get('errorCode', 'none')

        if 'delete' in qdict:
            delete = qdict['delete']
            if len(plugin_options['sounds']) > 0:
                del_file = os.path.join(plugin_data_dir(),
                                        plugin_options['sounds'][int(delete)])
                if os.path.isfile(del_file):
                    os.remove(del_file)
                    errorCode = qdict.get('errorCode', 'DelOK')
                    read_folder()
                    log.clear(NAME)
                    log.debug(
                        NAME,
                        datetime_string() + ': ' +
                        _(u'Deleting file has sucesfully.'))
                else:
                    errorCode = qdict.get('errorCode', 'DelNex')
                    log.clear(NAME)
                    log.error(
                        NAME,
                        datetime_string() + ': ' +
                        _(u'File for deleting not found!'))

        return self.plugin_render.voice_notification_sounds(
            plugin_options, errorCode)
Exemplo n.º 9
0
    def GET(self):
        global wind_sender

        qdict = web.input()
        reset = helpers.get_input(qdict, 'reset', False, lambda x: True)
        delete = helpers.get_input(qdict, 'delete', False, lambda x: True)
        show = helpers.get_input(qdict, 'show', False, lambda x: True)

        if wind_sender is not None and reset:
            wind_sender.status['max_meter'] = 0
            wind_sender.status['log_date_maxspeed'] = datetime_string()
            log.clear(NAME)
            log.info(
                NAME,
                datetime_string() + ' ' + _(u'Maximal speed has reseted.'))
            raise web.seeother(plugin_url(settings_page), True)

        if wind_sender is not None and delete:
            write_log([])
            create_default_graph()
            log.info(NAME,
                     datetime_string() + ' ' + _(u'Deleted all log files OK'))
            raise web.seeother(plugin_url(settings_page), True)

        if wind_sender is not None and 'history' in qdict:
            history = qdict['history']
            wind_options.__setitem__('history', int(history))

        if wind_sender is not None and show:
            raise web.seeother(plugin_url(log_page), True)

        return self.plugin_render.wind_monitor(wind_options,
                                               wind_sender.status,
                                               log.events(NAME))
Exemplo n.º 10
0
    def POST(self):
        global saved_emails
        
        email_options.web_update(web.input())
        qdict = web.input()
        test = get_input(qdict, 'test', False, lambda x: True)
        delete = get_input(qdict, 'del', False, lambda x: True)

        if email_sender is not None:
            email_sender.update()

            if test:
                regex = re.compile(r'([A-Za-z0-9]+[.-_])*[A-Za-z0-9]+@[A-Za-z0-9-]+(\.[A-Z|a-z]{2,})+')      # SMTP username
                if not re.fullmatch(regex, email_options['emlusr']):
                    log.clear(NAME)
                    log.info(NAME,datetime_string() + ': ' + _(u'Sender e-mail address appears to be invalid!'))
                    raise web.seeother(plugin_url(settings_page), True)  

                body = datetime_string() + ': ' + _(u'This is test e-mail from OSPy. You can ignore it.')
                logtext = _(u'This is test e-mail from OSPy. You can ignore it.')
                try_mail(body, logtext)
            
            if delete:
                log.info(NAME, datetime_string() + ': ' + _(u'Email Queue was deleted.'))         
                write_email([])
                saved_emails = 0

        raise web.seeother(plugin_url(settings_page), True)
Exemplo n.º 11
0
    def run(self):
        report_index = 0
        while not self._stop.is_set():
            try:
                if lcd_options['use_lcd']:  # if LCD plugin is enabled
                    if lcd_options['debug_line']:
                        log.clear(NAME)

                    line1 = get_report(report_index)
                    line2 = get_report(report_index + 1)

                    if report_index >= 25:
                        report_index = 0

                    line1 = get_report(report_index)
                    line2 = get_report(report_index + 1)
                    
                    update_lcd(line1, line2)
                                           
                    if lcd_options['debug_line'] and line1 is not None:
                        log.info(NAME, line1)
                    if lcd_options['debug_line'] and line2 is not None:
                        log.info(NAME, line2)

                    report_index += 2

                self._sleep(2)

            except Exception:
                log.error(NAME, _('LCD display plug-in:') + '\n' + traceback.format_exc())
                self._sleep(5)
Exemplo n.º 12
0
def read_buttons():
    try:
        import smbus

        bus = smbus.SMBus(0 if helpers.get_rpi_revision() == 1 else 1)

        # Set 8 GPA pins as input pull-UP
        try_io(lambda: bus.write_byte_data(plugin_options[
            'i2c_addr'], 0x0C, 0xFF))  #bus.write_byte_data(0x27,0x0C,0xFF)

        # Wait for device
        time.sleep(0.2)

        # Read state of GPIOA register
        MySwitch = try_io(
            lambda: bus.read_byte_data(plugin_options[
                'i2c_addr'], 0x12))  # MySwitch = bus.read_byte_data(0x27,0x12)

        inBut = 255 - MySwitch
        # inversion number for led off if button is not pressed

        led_outputs(inBut)  # switch on actual led if button is pressed

        button_number = -1
        if inBut == 128:
            button_number = 7
            log.debug(NAME, _(u'Switch 8 pressed'))
        if inBut == 64:
            button_number = 6
            log.debug(NAME, _(u'Switch 7 pressed'))
        if inBut == 32:
            button_number = 5
            log.debug(NAME, _(u'Switch 6 pressed'))
        if inBut == 16:
            button_number = 4
            log.debug(NAME, _(u'Switch 5 pressed'))
        if inBut == 8:
            button_number = 3
            log.debug(NAME, _(u'Switch 4 pressed'))
        if inBut == 4:
            button_number = 2
            log.debug(NAME, _(u'Switch 3 pressed'))
        if inBut == 2:
            button_number = 1
            log.debug(NAME, _(u'Switch 2 pressed'))
        if inBut == 1:
            button_number = 0
            log.debug(NAME, _(u'Switch 1 pressed'))
        return button_number  #if button is not pressed return -1

    except Exception:
        log.clear(NAME)
        log.error(NAME, datetime_string() + ': ' + _(u'Read button - FAULT'))
        log.error(
            NAME,
            _(u'Is hardware connected? Is bus address corectly setuped?'))
        #log.error(NAME, '\n' + traceback.format_exc())
        pass
        return -1
Exemplo n.º 13
0
    def GET(self):
        log.clear(NAME)
        cmd = "sudo echo 'bcm2708_wdog' >> /etc/modules"
        log.debug(NAME, cmd)
        run_process(cmd)
        cmd = "sudo echo 'bcm2835_wdog' >> /etc/modules"
        log.debug(NAME, cmd)
        run_process(cmd)
        cmd = "sudo echo 'bcm2711_wdt' >> /etc/modules"
        log.debug(NAME, cmd)
        run_process(cmd)

        try:
            cmd = "sudo modprobe bcm2708_wdog"
            log.debug(NAME, cmd)
            run_process(cmd)
        except:
            try:
                cmd = "sudo modprobe bcm2835_wdog"
                log.debug(NAME, cmd)
                run_process(cmd)
            except:
                cmd = "sudo modprobe bcm2711_wdog"
                log.debug(NAME, cmd)
                run_process(cmd)

        cmd = "sudo apt-get install -y watchdog chkconfig"
        log.debug(NAME, cmd)
        run_process(cmd)
        cmd = "sudo chkconfig watchdog on"
        log.debug(NAME, cmd)
        run_process(cmd)
        log.debug(NAME, _('Saving config to /etc/watchdog.conf'))

        # http://linux.die.net/man/5/watchdog.conf
        f = open("/etc/watchdog.conf", "wb")
        f.write("watchdog-device = /dev/watchdog\n")
        f.write("watchdog-timeout = 14\n")
        f.write("realtime = yes\n")
        f.write("priority = 1\n")
        f.write("interval = 4\n")
        f.write("max-load-1 = 24\n")
        f.close()

        cmd = "sudo systemctl enable watchdog"
        log.debug(NAME, cmd)
        run_process(cmd)
        cmd = "sudo systemctl daemon-reload"
        log.debug(NAME, cmd)
        run_process(cmd)
        cmd = "sudo systemctl start watchdog"
        log.debug(NAME, cmd)
        run_process(cmd)

        reboot(True)  # reboot HW software after instal watchdog
        msg = _(
            'The system (Linux) will now restart (restart started by the user in the Watch-dog plugins), please wait for the page to reload.'
        )
        return self.core_render.notice(plugin_url(status_page), msg)
Exemplo n.º 14
0
    def POST(self):
        global sender
        plugin_options.web_update(web.input())

        if sender is not None:
            sender.update()
            log.clear(NAME)

        raise web.seeother(plugin_url(settings_page), True)
Exemplo n.º 15
0
def to_decimal(number):
    try:
        import decimal
        return decimal.Decimal(float(number))
    
    except decimal.InvalidOperation:
        log.clear(NAME)
        log.error(NAME, _(u'Water Consumption Counter plug-in') + traceback.format_exc()) 
        pass
        return decimal.Decimal('0.0')
Exemplo n.º 16
0
    def update_statistics(self):
        """Returns the statistics data."""

        try:
            import requests

            link = "https://pihrt.com/ospystats/statistics.json"
            req = requests.get(link)
            bodytext = req.text
            #log.debug(NAME, bodytext) # downloaded text

            import json

            jsonStr = json.loads(bodytext)
            IDlenght = len(jsonStr['user'])

            log.clear(NAME)
            for i in range(0, IDlenght - 1):
                log.info(NAME, _('ID') + ': ' + str(jsonStr['user'][i]['id']))
                log.info(NAME,
                         _('Log') + ': ' + str(jsonStr['user'][i]['log']))
                log.info(NAME,
                         _('OSPy') + ': ' + str(jsonStr['user'][i]['ospy']))
                log.info(NAME,
                         _('CPU') + ': ' + str(jsonStr['user'][i]['cpu']))
                log.info(
                    NAME,
                    _('Distribution') + ': ' +
                    str(jsonStr['user'][i]['distribution']))
                log.info(
                    NAME,
                    _('System') + ': ' + str(jsonStr['user'][i]['system']))
                log.info(
                    NAME,
                    _('Python') + ': ' + str(jsonStr['user'][i]['python']) +
                    '\n')

            self.status['pageOK'] = _(
                u'The data from') + ' www.pihrt.com ' + _(
                    u'was downloaded correctly.') + ' ' + datetime_string()
            self.status['pageOKstate'] = True

            try:
                f = open("./ospy/statistics/user_id", "r")
                userID = (f.read())
                self.status['pageID'] = _(u'Your ID is: ') + str(userID)
            except:
                #log.error(NAME, _('Usage statistics plug-in') + ':\n' + traceback.format_exc())
                pass

        except Exception:
            self.status['pageOK'] = _(
                u'Error: data cannot be downloaded from') + ' www.pihrt.com!'
            self.status['pageOKstate'] = False
            log.clear(NAME)
Exemplo n.º 17
0
    def run(self):
        global stats

        temp_upd = None

        if plugin_options['use_footer']:
            temp_upd = showInFooter(
            )  #  instantiate class to enable data in footer
            temp_upd.button = "system_update/status"  # button redirect on footer
            temp_upd.label = _(u'System Update')  # label on footer
            msg = _(u'Waiting to state')
            temp_upd.val = msg.encode('utf8').decode('utf8')  # value on footer

        while not self._stop_event.is_set():
            try:
                if plugin_options['use_update']:
                    log.clear(NAME)
                    self._update_rev_data()

                    if self.status['can_update']:
                        msg = _(u'New OSPy version is available!')
                        stats['can_update'] = True
                        report_ospyupdate()
                    else:
                        msg = _(u'Up-to-date')
                        stats['can_update'] = False

                    if self.status['can_update'] and plugin_options[
                            'auto_update']:
                        perform_update()

                    self.started.set()
                else:
                    msg = _(u'Plugin is not enabled')

                if plugin_options['use_footer']:
                    if temp_upd is not None:
                        temp_upd.val = msg.encode('utf8').decode(
                            'utf8')  # value on footer
                    else:
                        log.error(
                            NAME,
                            _(u'Error: restart this plugin! Show in homepage footer have enabled.'
                              ))

                self._sleep(3600)

            except Exception:
                self.started.set()
                log.error(
                    NAME,
                    _(u'System update plug-in') + ':\n' +
                    traceback.format_exc())
                self._sleep(60)
Exemplo n.º 18
0
    def POST(self):
        options.__setitem__('sum', 0)
        log.clear(NAME)
        log.info(NAME, _('Water summary was reseting...'))
        log.info(NAME, _('Water in liters'))
        log.info(NAME, _('Water summary') + ': ' + str(options['sum']))

        if water_sender is not None:
            water_sender.update()

        raise web.seeother(plugin_url(settings_page), True)
Exemplo n.º 19
0
    def POST(self):
        speed_options.web_update(
            web.input(**speed_options))  #for save multiple select

        if sender is not None:
            sender.update()

        log.clear(NAME)
        log.info(NAME, _(u'Options has updated.'))

        raise web.seeother(plugin_url(settings_page), True)
Exemplo n.º 20
0
    def run(self):
        global blocker
        report_index = 0

        rebooted = signal('rebooted')
        rebooted.connect(notify_rebooted)

        restarted = signal('restarted')
        restarted.connect(notify_restarted)

        poweroff = signal('poweroff')
        poweroff.connect(notify_poweroff)

        ospyupdate = signal('ospyupdate')
        ospyupdate.connect(notify_ospyupdate)

        while not self._stop_event.is_set():
            try:
                if lcd_options[
                        'use_lcd'] and not blocker:  # if LCD plugin is enabled
                    if lcd_options['debug_line']:
                        log.clear(NAME)

                    line1 = get_report(report_index)
                    line2 = get_report(report_index + 1)

                    if report_index >= 31:
                        report_index = 0

                    skip_lines = False
                    if line1 is None and line2 is None:
                        skip_lines = True

                    if not skip_lines:
                        update_lcd(line1, line2)
                        if lcd_options['debug_line'] and line1 is not None:
                            L1 = line1.decode('utf8')
                            log.info(NAME, L1)
                        if lcd_options['debug_line'] and line2 is not None:
                            L2 = line2.decode('utf8')
                            log.info(NAME, L2)
                        self._sleep(2)

                    report_index += 2

                    time.sleep(0.1)

            except Exception:
                log.error(
                    NAME,
                    _('LCD display plug-in:') + '\n' + traceback.format_exc())
                self._sleep(5)
Exemplo n.º 21
0
 def GET(self):
     log.clear(NAME)
     cmd = "sudo systemctl start watchdog"
     log.debug(NAME, cmd)
     run_process(cmd)
     cmd = "sudo systemctl enable watchdog"
     log.debug(NAME, cmd)
     run_process(cmd)
     cmd = "sudo systemctl daemon-reload"
     log.debug(NAME, cmd)
     run_process(cmd)
     restart(3)
     return self.core_render.restarting(plugin_url(status_page))
Exemplo n.º 22
0
    def GET(self):
        global lcd_sender

        qdict = web.input()
        refind = helpers.get_input(qdict, 'refind', False, lambda x: True)
        if lcd_sender is not None and refind:
            lcd_options['address'] = 0
            log.clear(NAME)
            log.info(NAME, _('I2C address has re-finded.'))
            find_lcd_address()
            raise web.seeother(plugin_url(settings_page), True)

        return self.plugin_render.lcd_display(lcd_options, log.events(NAME))
Exemplo n.º 23
0
    def run(self):
        log.clear(NAME)
        if not self._stop.is_set():
            if plugin_options["use_mqtt"]:
                try:
                    atexit.register(on_restart)
                    publish_status()

                except Exception:
                    log.error(
                        NAME,
                        _('MQTT plug-in') + ':\n' + traceback.format_exc())
                    self._sleep(60)
Exemplo n.º 24
0
    def try_mail(self, text, attachment=None, subject=None):
        log.clear(NAME)
        try:
            email(text, attach=attachment)  # send email with attachment from
            log.info(NAME, _('Email was sent') + ':\n' + text)
            if not options.run_logEM:
                log.info(NAME, _('Email logging is disabled in options...'))
            logEM.save_email_log(subject or email_options['emlsubject'], text, _('Sent'))

        except Exception:
            log.error(NAME, _('Email was not sent!') + '\n' + traceback.format_exc())
            logEM.save_email_log(subject or email_options['emlsubject'], text, _('Unsent'))
            if not options.run_logEM:
                log.info(NAME, _('Email logging is disabled in options...'))
Exemplo n.º 25
0
def on_station_off(name, **kw):
    """ Send CMD to OFF when core program signals in station state."""
    index = int(kw[u"txt"])
    log.clear(NAME)
    log.info(NAME, _(u'Station {} change to OFF').format(index + 1))
    command = plugin_options['off']
    data = command[index]
    if data:
        log.info(NAME,
                 _(u'Im trying to send an OFF command: {}').format(index + 1))
        run_command(data)
    else:
        log.info(NAME, _(u'No command is set for OFF: {}').format(index + 1))
    return
Exemplo n.º 26
0
def set_to_default():
    plugin_options.__setitem__('s_use', [False]*30)
    plugin_options.__setitem__('s_unit', ['']*30)
    plugin_options.__setitem__('s_name', ['']*30)
    plugin_options.__setitem__('s_tick', ['0,10,20,30']*30)
    plugin_options.__setitem__('s_min', ['0']*30)
    plugin_options.__setitem__('s_max', ['30']*30)
    plugin_options.__setitem__('s_a_high_fr', [5]*30)
    plugin_options.__setitem__('s_a_high_to', [10]*30)
    plugin_options.__setitem__('s_b_high_fr', [10]*30)
    plugin_options.__setitem__('s_b_high_to', [20]*30)
    plugin_options.__setitem__('s_c_high_fr', [20]*30)
    plugin_options.__setitem__('s_c_high_to', [30]*30)
    log.clear(NAME)
    log.info(NAME, _(u'Weather stations plug-in has any error, clear plugin settings to default.'))
Exemplo n.º 27
0
    def POST(self):
        plugin_options.web_update(web.input())

        if checker is not None:
            checker.update()

        if plugin_options['enabled']:
            log.clear(NAME)
            log.info(NAME, _('Pressurizer is enabled.'))
        else:
            log.clear(NAME)
            log.info(NAME, _('Pressurizer is disabled.'))

        log.info(NAME, _('Options has updated.'))
        raise web.seeother(plugin_url(settings_page), True)
Exemplo n.º 28
0
    def GET(self):
        global sender, status

        qdict = web.input()
        reset = helpers.get_input(qdict, 'reset', False, lambda x: True)
        if sender is not None and reset:
            plugin_options.__setitem__('sum_one', 0)
            plugin_options.__setitem__('sum_two', 0)
            plugin_options.__setitem__('last_reset', datetime_string())

            log.clear(NAME)
            log.info(NAME, datetime_string() + ': ' + _(u'Counter has reseted'))
            raise web.seeother(plugin_url(settings_page), True)

        return self.plugin_render.water_consumption_counter(plugin_options, log.events(NAME))
Exemplo n.º 29
0
    def run(self):
        try:
            master_one_on = signal('master_one_on')
            master_one_on.connect(notify_master_one_on)
            master_one_off = signal('master_one_off')
            master_one_off.connect(notify_master_one_off)
            master_two_on = signal('master_two_on')
            master_two_on.connect(notify_master_two_on)
            master_two_off = signal('master_two_off')
            master_two_off.connect(notify_master_two_off)

        except Exception:
            log.clear(NAME)
            log.error(NAME, _(u'Water Consumption Counter plug-in') + traceback.format_exc())
            self._sleep(60)
Exemplo n.º 30
0
    def run(self):
        while not self._stop_event.is_set():
            try:
                if plugin_options[
                        'enabled']:  # if Weather-based Rain Delay plug-in is enabled
                    log.clear(NAME)
                    log.info(NAME, 'Checking rain status...')

                    current_data = weather.get_current_data()

                    if 'precipProbability' in current_data:
                        if current_data['precipProbability'] > 0.75:
                            log.info(
                                NAME,
                                'Rain detected: ' + current_data['summary'] +
                                '. Adding delay of ' +
                                str(plugin_options['delay_duration']))
                            rain_blocks[NAME] = datetime.datetime.now(
                            ) + datetime.timedelta(
                                hours=float(plugin_options['delay_duration']))
                            stop_onrain()

                        elif current_data['precipProbability'] > 0.1:
                            log.info(
                                NAME, 'No rain detected: ' +
                                current_data['summary'] + '. No action.')

                        else:
                            log.info(
                                NAME, 'Good weather detected: ' +
                                current_data['summary'] +
                                '. Removing rain delay.')
                            if NAME in rain_blocks:
                                del rain_blocks[NAME]

                    self._sleep(3600)
                else:
                    log.clear(NAME)
                    log.info(NAME, 'Plug-in is disabled.')
                    if NAME in rain_blocks:
                        del rain_blocks[NAME]
                    self._sleep(24 * 3600)

            except Exception:
                log.error(
                    NAME, 'Weather-based Rain Delay plug-in:\n' +
                    traceback.format_exc())
                self._sleep(3600)