Esempio n. 1
0
def notify_ospyupdate(name, **kw):
    ### OSPy new version availbale ###
    global blocker
    blocker = True
    log.info(NAME, datetime_string() + ': ' + _('System OSPy Has Update'))
    if lcd_options['address'] == 0:
        find_lcd_address()
    if lcd_options['address'] != 0:
        from . import pylcd  # Library for LCD 16x2 PCF8574
        lcd = pylcd.lcd(lcd_options['address'],
                        0 if helpers.get_rpi_revision() == 1 else 1,
                        lcd_options['hw_PCF8574']
                        )  # (address, bus, hw version for expander)
        # DF - alter RPi version test fallback to value that works on BBB
    else:
        lcd = dummy_lcd

    try_io(lambda: lcd.lcd_clear())
    try_io(lambda: lcd.lcd_puts(ASCI_convert(_('System OSPy')), 1))
    try_io(lambda: lcd.lcd_puts(ASCI_convert(_('Has Update')), 2))
Esempio n. 2
0
def run_process(cmd):
    try:
        proc = subprocess.Popen(
            cmd,
            stderr=subprocess.STDOUT,  # merge stdout and stderr
            stdout=subprocess.PIPE,
            shell=True)
        output = proc.communicate()[0]
        log.info(NAME,
                 _('System watchodg plug-in') + ':\n' + ASCI_convert(output))

    except:
        log.info(
            NAME,
            _('System watchodg plug-in') + ':\n' + _('Error in Converting'))
Esempio n. 3
0
def get_report(index):
    result = None

    if index == 0:
        if lcd_options['d_system_name']:
            result = ASCI_convert(_('System:'))
        else:
            result = None
    elif index == 1:
        if lcd_options['d_system_name']:
            result = ASCI_convert(options.name)
        else:
            result = None
    elif index == 2:
        if lcd_options['d_sw_version_date']:
            result = ASCI_convert(_('SW Version:'))
        else:
            result = None
    elif index == 3:
        if lcd_options['d_sw_version_date']:
            result = ASCI_convert('{} {}'.format(version.ver_str,
                                                 version.ver_date))
        else:
            result = None
    elif index == 4:
        if lcd_options['d_ip']:
            result = ASCI_convert(_('My IP is:'))
        else:
            result = None
    elif index == 5:
        if lcd_options['d_ip']:
            if options.use_ssl:
                result = ASCI_convert(
                    ('https://{}:{}').format(helpers.get_ip(),
                                             options.web_port))
            else:
                result = ASCI_convert(
                    ('http://{}:{}').format(helpers.get_ip(),
                                            options.web_port))
        else:
            result = None
    elif index == 6:
        if lcd_options['d_port']:
            result = ASCI_convert(_('My Port is:'))
        else:
            result = None
    elif index == 7:
        if lcd_options['d_port']:
            result = ASCI_convert('{}'.format(options.web_port))
        else:
            result = None
    elif index == 8:
        if lcd_options['d_cpu_temp']:
            result = ASCI_convert(_('CPU Temperature:'))
        else:
            result = None
    elif index == 9:
        if lcd_options['d_cpu_temp']:
            result = ASCI_convert('{} {}'.format(
                helpers.get_cpu_temp(options.temp_unit), options.temp_unit))
        else:
            result = None
    elif index == 10:
        if lcd_options['d_time_date']:
            result = ASCI_convert(
                _('Date:') + ' {}'.format(datetime.now().strftime('%d.%m.%Y')))
        else:
            result = None
    elif index == 11:
        if lcd_options['d_time_date']:
            result = ASCI_convert(
                _('Time:') + ' {}'.format(datetime.now().strftime('%H:%M:%S')))
        else:
            result = None
    elif index == 12:
        if lcd_options['d_uptime']:
            result = ASCI_convert(_('System Uptime:'))
        else:
            result = None
    elif index == 13:
        if lcd_options['d_uptime']:
            result = ASCI_convert(helpers.uptime())
        else:
            result = None
    elif index == 14:
        if lcd_options['d_rain_sensor']:
            result = ASCI_convert(_('Rain Sensor:'))
        else:
            result = None
    elif index == 15:
        if lcd_options['d_rain_sensor']:
            if inputs.rain_sensed():
                result = ASCI_convert(_('Active'))
            else:
                result = ASCI_convert(_('Inactive'))
        else:
            result = None
    elif index == 16:
        if lcd_options['d_last_run']:
            result = ASCI_convert(_('Last Program:'))
        else:
            result = None
    elif index == 17:
        if lcd_options['d_last_run']:
            finished = [
                run for run in log.finished_runs() if not run['blocked']
            ]
            if finished:
                str_fin = '{}{}'.format(
                    finished[-1]['program_name'],
                    finished[-1]['start'].strftime(' %d.%m.%Y %H:%M:%S'))
                result = ASCI_convert(str_fin)
            else:
                result = ASCI_convert(_('None'))
        else:
            result = None
    elif index == 18:
        if lcd_options['d_pressure_sensor']:
            result = ASCI_convert(_('Pressure Sensor:'))
        else:
            result = None
    elif index == 19:
        if lcd_options['d_pressure_sensor']:
            try:
                from plugins import pressure_monitor
                state_press = pressure_monitor.get_check_pressure()
                if state_press:
                    result = ASCI_convert(_('Inactive'))
                else:
                    result = ASCI_convert(_('Active'))
            except Exception:
                result = ASCI_convert(_('Not Available'))
        else:
            result = None
    elif index == 20:
        if lcd_options['d_water_tank_level']:
            result = ASCI_convert(_('Water Tank Level:'))
        else:
            result = None
    elif index == 21:
        if lcd_options['d_water_tank_level']:
            try:
                from plugins import tank_monitor
                cm = tank_monitor.get_all_values()[0]
                percent = tank_monitor.get_all_values()[1]
                ping = tank_monitor.get_all_values()[2]
                volume = tank_monitor.get_all_values()[3]
                units = tank_monitor.get_all_values()[4]
            except Exception:
                cm = -1
                percent = 0
                ping = -1
                volume = 0
                units = -1

            if cm > 0 and units != -1:
                result = ASCI_convert(
                    _('Level') + ' {}'.format(cm) + _('cm') +
                    ' {}'.format(percent) + _('%') + ' {}'.format(int(volume)))
                if units:
                    result += ASCI_convert(_('liter'))
                else:
                    result += ASCI_convert(_('m3'))
            elif units == -1:
                result = ASCI_convert(_('Not Available'))
            else:
                result = ASCI_convert(_('Error - I2C Device Not Found!'))
        else:
            result = None
    elif index == 22:
        if lcd_options['d_temperature']:
            result = ASCI_convert(_('DS Temperature:'))
        else:
            result = None
    elif index == 23:
        if lcd_options['d_temperature']:
            try:
                from plugins import air_temp_humi
                air_options = air_temp_humi.plugin_options
                if air_options['ds_enabled']:
                    air_result = ''
                    for i in range(0, air_options['ds_used']):
                        air_result += '{}:{} '.format(
                            air_options['label_ds%d' % i],
                            air_temp_humi.DS18B20_read_probe(i))
                    result = ASCI_convert(air_result)
                else:
                    result = ASCI_convert(_('DS temperature not use'))
            except Exception:
                result = ASCI_convert(_('Not Available'))
        else:
            result = None
    elif index == 24:
        if lcd_options['d_running_stations']:
            result = ASCI_convert(_('Station running:'))
        else:
            result = None
    elif index == 25:
        if lcd_options['d_running_stations']:
            if get_active_state() == False:
                result = ASCI_convert(_('Nothing running'))
            else:
                result = ASCI_convert(get_active_state())
        else:
            result = None
    elif index == 26:
        if lcd_options['d_sched_manu']:
            result = ASCI_convert(_('Control:'))
        else:
            result = None
    elif index == 27:
        if lcd_options['d_sched_manu']:
            if options.manual_mode:
                result = ASCI_convert(_('Manual mode'))
            else:
                result = ASCI_convert(_('Scheduler'))
        else:
            result = None
    elif index == 28:
        if lcd_options['d_syst_enabl']:
            result = ASCI_convert(_('Scheduler:'))
        else:
            result = None
    elif index == 29:
        if lcd_options['d_syst_enabl']:
            if options.scheduler_enabled:
                result = ASCI_convert(_('Enabled'))
            else:
                result = ASCI_convert(_('Disabled'))
        else:
            result = None
    ### OSPy sensors ###
    elif index == 30:
        if lcd_options['d_sensors']:
            result = ASCI_convert(_('Sensors:'))
        else:
            result = None
    elif index == 31:
        if lcd_options['d_sensors']:
            try:
                if sensors.count() > 0:
                    sensor_result = ''
                    for sensor in sensors.get():
                        if sensor.enabled:
                            if sensor.response == 1:
                                sensor_result += sensor.name + ': '
                                if sensor.sens_type == 1:  # dry contact
                                    if sensor.last_read_value[4] == 1:
                                        sensor_result += _('Contact Closed')
                                    elif sensor.last_read_value[4] == 0:
                                        sensor_result += _('Contact Open')
                                    else:
                                        sensor_result += _('Probe Error')
                                if sensor.sens_type == 2:  # leak detector
                                    if sensor.last_read_value[5] != -127:
                                        sensor_result += '{}'.format(
                                            sensor.last_read_value[5]
                                        ) + ' ' + _('l/s')
                                    else:
                                        sensor_result += _('Probe Error')
                                if sensor.sens_type == 3:  # moisture
                                    if sensor.last_read_value[6] != -127:
                                        sensor_result += '{}'.format(
                                            sensor.last_read_value[6]) + _('%')
                                    else:
                                        sensor_result += _('Probe Error')
                                if sensor.sens_type == 4:  # motion
                                    if sensor.last_read_value[7] != -127:
                                        sensor_result += _(
                                            'Motion Detected') if int(
                                                sensor.last_read_value[7]
                                            ) == 1 else _('No Motion')
                                    else:
                                        sensor_result += _('Probe Error')
                                if sensor.sens_type == 5:  # temperature
                                    if sensor.last_read_value[0] != -127:
                                        sensor_result += '{}'.format(
                                            sensor.last_read_value[0])
                                    else:
                                        sensor_result += _('Probe Error')
                                if sensor.sens_type == 6:  # multi sensor
                                    if sensor.multi_type >= 0 and sensor.multi_type < 4:  # multi temperature DS1-DS4
                                        if sensor.last_read_value[
                                                sensor.multi_type] != -127:
                                            sensor_result += '{}'.format(
                                                sensor.last_read_value[
                                                    sensor.multi_type])
                                        else:
                                            sensor_result += _('Probe Error')
                                    if sensor.multi_type == 4:  #  multi dry contact
                                        if sensor.last_read_value[4] != -127:
                                            sensor_result += _(
                                                'Contact Closed') if int(
                                                    sensor.last_read_value[4]
                                                ) == 1 else _('Contact Open')
                                        else:
                                            sensor_result += _('Probe Error')
                                    if sensor.multi_type == 5:  #  multi leak detector
                                        if sensor.last_read_value[5] != -127:
                                            sensor_result += '{}'.format(
                                                sensor.last_read_value[5]
                                            ) + ' ' + _('l/s')
                                        else:
                                            sensor_result += _('Probe Error')
                                    if sensor.multi_type == 6:  #  multi moisture
                                        if sensor.last_read_value[6] != -127:
                                            sensor_result += '{}'.format(
                                                sensor.last_read_value[6]
                                            ) + ' ' + _('%')
                                        else:
                                            sensor_result += _('Probe Error')
                                    if sensor.multi_type == 7:  #  multi motion
                                        if sensor.last_read_value[7] != -127:
                                            sensor_result += _(
                                                'Motion Detected') if int(
                                                    sensor.last_read_value[7]
                                                ) == 1 else _('No Motion')
                                        else:
                                            sensor_result += _('Probe Error')
                                    if sensor.multi_type == 8:  #  multi ultrasonic
                                        if sensor.last_read_value[8] != -127:
                                            get_level = get_tank_cm(
                                                sensor.last_read_value[8],
                                                sensor.distance_bottom,
                                                sensor.distance_top)
                                            get_perc = get_percent(
                                                get_level,
                                                sensor.distance_bottom,
                                                sensor.distance_top)
                                            sensor_result += '{}'.format(
                                                get_level) + ' ' + _(
                                                    'cm') + ' (' + '{}'.format(
                                                        get_perc) + ' %)'
                                        else:
                                            sensor_result += _('Probe Error')
                                    if sensor.multi_type == 9:  #  multi soil moisture
                                        err_check = 0
                                        calculate_soil = [0.0] * 16
                                        state = [-127] * 16
                                        for i in range(0, 16):
                                            if type(sensor.
                                                    soil_last_read_value[i]
                                                    ) == float:
                                                state[
                                                    i] = sensor.soil_last_read_value[
                                                        i]
                                                ### voltage from probe to humidity 0-100% with calibration range (for footer info)
                                                if sensor.soil_invert_probe_in[
                                                        i]:  # probe: rotated state 0V=100%, 3V=0% humidity
                                                    calculate_soil[i] = maping(
                                                        state[i],
                                                        float(
                                                            sensor.
                                                            soil_calibration_max[
                                                                i]),
                                                        float(
                                                            sensor.
                                                            soil_calibration_min[
                                                                i]), 0.0,
                                                        100.0)
                                                    calculate_soil[i] = round(
                                                        calculate_soil[i], 1
                                                    )  # round to one decimal point
                                                    calculate_soil[
                                                        i] = 100.0 - calculate_soil[
                                                            i]  # ex: 90% - 90% = 10%, 10% is output in invert probe mode
                                                else:  # probe: normal state 0V=0%, 3V=100%
                                                    calculate_soil[i] = maping(
                                                        state[i],
                                                        float(
                                                            sensor.
                                                            soil_calibration_min[
                                                                i]),
                                                        float(
                                                            sensor.
                                                            soil_calibration_max[
                                                                i]), 0.0,
                                                        100.0)
                                                    calculate_soil[i] = round(
                                                        calculate_soil[i], 1
                                                    )  # round to one decimal point
                                                if state[i] > 0.1:
                                                    if sensor.soil_show_in_footer[
                                                            i]:
                                                        sensor_result += '{} {}% ({}V) '.format(
                                                            sensor.
                                                            soil_probe_label[
                                                                i],
                                                            round(
                                                                calculate_soil[
                                                                    i], 2),
                                                            round(state[i], 2))
                                            else:
                                                err_check += 1
                                        if err_check > 15:
                                            sensor_result += _('Probe Error')
                            else:
                                sensor_result += sensor.name + ': ' + _(
                                    'No response!')
                        else:
                            sensor_result += sensor.name + ': ' + _('Disabled')
                        if sensors.count() > 1:
                            sensor_result += ', '
                    result = ASCI_convert(sensor_result)
                else:
                    result = ASCI_convert(_('No sensors available'))
            except Exception:
                result = ASCI_convert(_('Not Available'))
        else:
            result = None

    return result
Esempio n. 4
0
def get_report(index):
    result = None
    if (options.lang == 'cs_CZ'):
           if index == 0:  # start text to 16x1
             if lcd_options['d_system_name']:
                result = "ID systemu:"
             else: 
                result = None
           elif index == 1:
             if lcd_options['d_system_name']:
                result = options.name
             else:
                result = None 

           elif index == 2:
             if lcd_options['d_sw_version_date']:
                result = "FW Verze:"
             else: 
                result = None
           elif index == 3:
             if lcd_options['d_sw_version_date']:
                result = version.ver_str + ' (' + version.ver_date + ')' 
             else: 
                result = None

           elif index == 4:
             if lcd_options['d_ip']:
                result = "IP adresa:" 
             else: 
                result = None
           elif index == 5:
             if lcd_options['d_ip']:
                 ip = helpers.get_ip()
                 result = str(ip)
             else: 
                result = None

           elif index == 6:
             if lcd_options['d_port']:
                result = "Port:"
             else: 
                result = None
           elif index == 7:
             if lcd_options['d_port']:
                result = str(options.web_port)
             else: 
                result = None

           elif index == 8:
             if lcd_options['d_cpu_temp']:
                result = "Teplota CPU:"
             else: 
                result = None
           elif index == 9:
             if lcd_options['d_cpu_temp']:
                result = helpers.get_cpu_temp(options.temp_unit) + ' ' + options.temp_unit
             else: 
                result = None

           elif index == 10:
             if lcd_options['d_time_date']:
                result = datetime.now().strftime('Dat %d.%m.%Y')
             else: 
                result = None
           elif index == 11:
             if lcd_options['d_time_date']:
                result = datetime.now().strftime('Cas %H:%M:%S')
             else: 
                result = None

           elif index == 12:
             if lcd_options['d_uptime']:
                result = "V provozu:"
             else: 
                result = None
           elif index == 13:
             if lcd_options['d_uptime']:
                result = helpers.uptime() 
             else: 
                result = None

           elif index == 14:
             if lcd_options['d_rain_sensor']:
                result = "Cidlo deste:"
             else: 
                result = None
           elif index == 15:
             if lcd_options['d_rain_sensor']:
                if inputs.rain_sensed():
                    result = "aktivni"
                else:
                    result = "neaktivni"
             else: 
                result = None

           elif index == 16:
             if lcd_options['d_last_run']:
                result = 'Naposledy bezel'
             else: 
                result = None
           elif index == 17:
             if lcd_options['d_last_run']:
                finished = [run for run in log.finished_runs() if not run['blocked']]
                if finished:
                   result = finished[-1]['start'].strftime('%d-%m-%Y v %H:%M:%S program: ') + finished[-1]['program_name']
                   result = result.replace('Run-Once', 'Jednorazovy')
                   result = result.replace('Manual', 'Rucne')
                else:
                   result = 'zadny program'
             else: 
                result = None

           elif index == 18:
             if lcd_options['d_pressure_sensor']:
                result = "Cidlo tlaku:"
             else: 
                result = None
           elif index == 19:
             if lcd_options['d_pressure_sensor']:
                try:
                   from plugins import pressure_monitor
                   state_press = pressure_monitor.get_check_pressure()
                   if state_press:
                      result = "neaktivni"
                   else:
                      result = "aktivni"

                except Exception:
                   result = "neni k dispozici"
             else: 
                result = None

           elif index == 20:    
             if lcd_options['d_water_tank_level']:    
                result = "Nadrz s vodou:"
             else: 
                result = None
           elif index == 21:
             if lcd_options['d_water_tank_level']:
                try:
                   from plugins import tank_humi_monitor
                   cm = tank_humi_monitor.get_sonic_tank_cm()
                   if cm > 0: 
                      result = str(cm) + ' cm'
                   else:
                      result = "chyba - I2C zarizeni nenalezeno!"

                except Exception:
                   result = "neni k dispozici"
             else: 
                result = None

           elif index == 22:    
             if lcd_options['d_temperature']:    
                result = "Teplota DS1-6:"
             else: 
                result = None
           elif index == 23:
             if lcd_options['d_temperature']:
                try:
                   from plugins import air_temp_humi
                 
                   result = air_temp_humi.DS18B20_read_string_data()
                  
                except Exception:
                   result = "neni k dispozici"
             else: 
                result = None

           elif index == 24:    
             if lcd_options['d_running_stations']:    
                result = "Stanice v chodu:"
             else: 
                result = None
           elif index == 25:
             if get_active_state()==False:   
                result = "nic nebezi" 
             else:
                result = get_active_state()

           return ASCI_convert(result)


    if (options.lang == 'sk_SK'):
           if index == 0:  # start text to 16x1
             if lcd_options['d_system_name']:
                result = "ID systemu:"
             else: 
                result = None
           elif index == 1:
             if lcd_options['d_system_name']:
                result = options.name
             else:
                result = None 

           elif index == 2:
             if lcd_options['d_sw_version_date']:
                result = "FW Verzia:"
             else: 
                result = None
           elif index == 3:
             if lcd_options['d_sw_version_date']:
                result = version.ver_str + ' (' + version.ver_date + ')' 
             else: 
                result = None

           elif index == 4:
             if lcd_options['d_ip']:
                result = "IP adresa:" 
             else: 
                result = None
           elif index == 5:
             if lcd_options['d_ip']:
                 ip = helpers.get_ip()
                 result = str(ip)
             else: 
                result = None

           elif index == 6:
             if lcd_options['d_port']:
                result = "Port:"
             else: 
                result = None
           elif index == 7:
             if lcd_options['d_port']:
                result = str(options.web_port)
             else: 
                result = None

           elif index == 8:
             if lcd_options['d_cpu_temp']:
                result = "Teplota CPU:"
             else: 
                result = None
           elif index == 9:
             if lcd_options['d_cpu_temp']:
                result = helpers.get_cpu_temp(options.temp_unit) + ' ' + options.temp_unit
             else: 
                result = None

           elif index == 10:
             if lcd_options['d_time_date']:
                result = datetime.now().strftime('Dat %d.%m.%Y')
             else: 
                result = None
           elif index == 11:
             if lcd_options['d_time_date']:
                result = datetime.now().strftime('Cas %H:%M:%S')
             else: 
                result = None

           elif index == 12:
             if lcd_options['d_uptime']:
                result = "V prevadzke:"
             else: 
                result = None
           elif index == 13:
             if lcd_options['d_uptime']:
                result = helpers.uptime() 
             else: 
                result = None

           elif index == 14:
             if lcd_options['d_rain_sensor']:
                result = "Cidlo dazda:"
             else: 
                result = None
           elif index == 15:
             if lcd_options['d_rain_sensor']:
                if inputs.rain_sensed():
                    result = "aktivny"
                else:
                    result = "neaktivny"
             else: 
                result = None

           elif index == 16:
             if lcd_options['d_last_run']:
                result = 'Naposledy bezal'
             else: 
                result = None
           elif index == 17:
             if lcd_options['d_last_run']:
                finished = [run for run in log.finished_runs() if not run['blocked']]
                if finished:
                   result = finished[-1]['start'].strftime('%d-%m-%Y v %H:%M:%S program: ') + finished[-1]['program_name']
                   result = result.replace('Run-Once', 'Jednorazovy')
                   result = result.replace('Manual', 'Rucne')
                else:
                   result = 'ziadny program'
             else: 
                result = None

           elif index == 18:
             if lcd_options['d_pressure_sensor']:
                result = "Cidlo tlaku:"
             else: 
                result = None
           elif index == 19:
             if lcd_options['d_pressure_sensor']:
                try:
                   from plugins import pressure_monitor
                   state_press = pressure_monitor.get_check_pressure()
                   if state_press:
                      result = "neaktivny"
                   else:
                      result = "aktivny"

                except Exception:
                   result = "neni k dispozicii"
             else: 
                result = None

           elif index == 20:    
             if lcd_options['d_water_tank_level']:    
                result = "Nadrz s vodou:"
             else: 
                result = None
           elif index == 21:
             if lcd_options['d_water_tank_level']:
                try:
                   from plugins import tank_humi_monitor
                   cm = tank_humi_monitor.get_sonic_tank_cm()
                   if cm > 0: 
                      result = str(cm) + ' cm'
                   else:
                      result = "chyba - I2C zarizeni nenajdene!"

                except Exception:
                   result = "neni k dispozicii"
             else: 
                result = None

           elif index == 22:    
             if lcd_options['d_temperature']:    
                result = "Teplota DS1-6:"
             else: 
                result = None
           elif index == 23:
             if lcd_options['d_temperature']:
                try:
                   from plugins import air_temp_humi
                 
                   result = air_temp_humi.DS18B20_read_string_data()
                  
                except Exception:
                   result = "neni k dispozicii"
             else: 
                result = None

           elif index == 24:    
             if lcd_options['d_running_stations']:    
                result = "Stanice v chode:"
             else: 
                result = None
           elif index == 25:
             if get_active_state()==False:   
                result = "nic nebezi" 
             else:
                result = get_active_state()

           return ASCI_convert(result)

    if (options.lang == 'en_US') or (options.lang == 'default'):
          if index == 0:  
             if lcd_options['d_system_name']:
                result = options.name
             else: 
                result = None
          elif index == 1:
             if lcd_options['d_system_name']:
                result = "Irrigation system"
             else: 
                result = None

          elif index == 2:
             if lcd_options['d_sw_version_date']:
                result = "SW Version:"
             else: 
                result = None
          elif index == 3:
             if lcd_options['d_sw_version_date']:
                result = version.ver_str + ' (' + version.ver_date + ')'
             else: 
                result = None

          elif index == 4:
             if lcd_options['d_ip']:
                result = "My IP is:"
             else: 
                result = None
          elif index == 5:
             if lcd_options['d_ip']:
                ip = helpers.get_ip()
                result = str(ip)
             else: 
                result = None

          elif index == 6:
             if lcd_options['d_port']:
                result = "My Port is:"
             else: 
                result = None
          elif index == 7:
             if lcd_options['d_port']:
                result = str(options.web_port)
             else: 
                result = None

          elif index == 8:
             if lcd_options['d_cpu_temp']:
                result = "CPU Temperature:"
             else: 
                result = None
          elif index == 9:
             if lcd_options['d_cpu_temp']:
                result = helpers.get_cpu_temp(options.temp_unit) + ' ' + options.temp_unit
             else: 
                result = None

          elif index == 10:
             if lcd_options['d_time_date']:
                result = datetime.now().strftime('Date: %d.%m.%Y')
             else: 
                result = None
          elif index == 11:
             if lcd_options['d_time_date']:
                result = datetime.now().strftime('Time: %H:%M:%S')
             else: 
                result = None

          elif index == 12:
             if lcd_options['d_uptime']:
                result = "System Uptime:"
             else: 
                result = None
          elif index == 13:
             if lcd_options['d_uptime']:
                result = helpers.uptime()
             else: 
                result = None

          elif index == 14:
             if lcd_options['d_rain_sensor']:
                result = "Rain Sensor:"
             else: 
                result = None
          elif index == 15:
             if lcd_options['d_rain_sensor']:
                if inputs.rain_sensed():
                   result = "Active"
                else:
                   result = "Inactive"
             else: 
                result = None

          elif index == 16:
             if lcd_options['d_last_run']:
                result = 'Last Program:'
             else: 
                result = None
          elif index == 17:
             if lcd_options['d_last_run']:
                finished = [run for run in log.finished_runs() if not run['blocked']]
                if finished:
                   result = finished[-1]['start'].strftime('%H:%M: ') + finished[-1]['program_name']
                   result = result.replace('Run-Once', 'Jednorazovy') 
                else:
                   result = 'None'
             else: 
                result = None

          elif index == 18:
             if lcd_options['d_pressure_sensor']:
                result = "Pressure Sensor:"
             else: 
                result = None
          elif index == 19:
             if lcd_options['d_pressure_sensor']:
                try:
                   from plugins import pressure_monitor
                   state_press = pressure_monitor.get_check_pressure()
                   if state_press:
                       result = "GPIO is HIGH"
                   else:
                       result = "GPIO is LOW"

                except Exception:
                   result = "Not Available"
             else: 
                result = None


          elif index == 20:    
             if lcd_options['d_water_tank_level']:        
                result = "Water Tank Level:"
             else: 
                result = None
          elif index == 21:
             if lcd_options['d_water_tank_level']:    
                try:
                   from plugins import tank_humi_monitor
                   cm = tank_humi_monitor.get_sonic_tank_cm()
                   if cm > 0: 
                      result = str(cm) + ' cm'
                   else:
                      result = "Error - I2C Device Not Found!"

                except Exception:
                   result = "Not Available"
             else: 
                result = None

          elif index == 22:    
            if lcd_options['d_temperature']:    
               result = "DS Temperature:"
            else: 
               result = None
          elif index == 23:
            if lcd_options['d_temperature']:
               try:
                  from plugins import air_temp_humi
                 
                  result = air_temp_humi.DS18B20_read_string_data()
                                     
               except Exception:
                  result = "Not Available"
            else: 
               result = None

          elif index == 24:    
            if lcd_options['d_running_stations']:    
               result = "Station running:"
            else: 
                result = None
          elif index == 25:
            if get_active_state()==False:   
               result = "nothing running" 
            else:
               result = get_active_state()

          return result
Esempio n. 5
0
def get_report(index):
    result = None
    station_state = False
    station_result = ''

    for station in stations.get():  # check if station runing
        if station.active:
            station_state = True  # yes runing
            station_result += str(
                station.index +
                1) + ', '  # station number runing ex: 2, 6, 20,

    if (options.lang == 'cs_CZ'):
        if station_state and lcd_options[
                'd_running_stations']:  # print on LCD only this text
            if index == 0 or index == 2 or index == 4 or index == 6 or index == 8 or index == 10 or index == 12 or index == 14 or index == 16 or index == 18 or index == 20:  # start text to 16x1
                result = "Stanice v chodu:"
            elif index == 1 or index == 3 or index == 5 or index == 7 or index == 9 or index == 11 or index == 13 or index == 15 or index == 17 or index == 19 or index == 21:
                result = station_result
            return result

        else:
            if index == 0:  # start text to 16x1
                if lcd_options['d_system_name']:
                    result = "ID systemu:"
                else:
                    result = None
            elif index == 1:
                if lcd_options['d_system_name']:
                    result = options.name
                else:
                    result = None

            elif index == 2:
                if lcd_options['d_sw_version_date']:
                    result = "FW Verze:"
                else:
                    result = None
            elif index == 3:
                if lcd_options['d_sw_version_date']:
                    result = version.ver_str + ' (' + version.ver_date + ')'
                else:
                    result = None

            elif index == 4:
                if lcd_options['d_ip']:
                    result = "IP adresa:"
                else:
                    result = None
            elif index == 5:
                if lcd_options['d_ip']:
                    ip = helpers.get_ip()
                    result = str(ip)
                else:
                    result = None

            elif index == 6:
                if lcd_options['d_port']:
                    result = "Port:"
                else:
                    result = None
            elif index == 7:
                if lcd_options['d_port']:
                    result = str(options.web_port)
                else:
                    result = None

            elif index == 8:
                if lcd_options['d_cpu_temp']:
                    result = "Teplota CPU:"
                else:
                    result = None
            elif index == 9:
                if lcd_options['d_cpu_temp']:
                    result = helpers.get_cpu_temp(
                        options.temp_unit) + ' ' + options.temp_unit
                else:
                    result = None

            elif index == 10:
                if lcd_options['d_time_date']:
                    result = datetime.now().strftime('Dat %d.%m.%Y')
                else:
                    result = None
            elif index == 11:
                if lcd_options['d_time_date']:
                    result = datetime.now().strftime('Cas %H:%M:%S')
                else:
                    result = None

            elif index == 12:
                if lcd_options['d_uptime']:
                    result = "V provozu:"
                else:
                    result = None
            elif index == 13:
                if lcd_options['d_uptime']:
                    result = helpers.uptime()
                else:
                    result = None

            elif index == 14:
                if lcd_options['d_rain_sensor']:
                    result = "Cidlo deste:"
                else:
                    result = None
            elif index == 15:
                if lcd_options['d_rain_sensor']:
                    if inputs.rain_sensed():
                        result = "aktivni"
                    else:
                        result = "neaktivni"
                else:
                    result = None

            elif index == 16:
                if lcd_options['d_last_run']:
                    result = 'Naposledy bezel'
                else:
                    result = None
            elif index == 17:
                if lcd_options['d_last_run']:
                    finished = [
                        run for run in log.finished_runs()
                        if not run['blocked']
                    ]
                    if finished:
                        result = finished[-1]['start'].strftime(
                            '%d-%m-%Y v %H:%M:%S program: '
                        ) + finished[-1]['program_name']
                        result = result.replace('Run-Once', 'Jednorazovy')
                        result = result.replace('Manual', 'Rucne')
                    else:
                        result = 'zadny program'
                else:
                    result = None

            elif index == 18:
                if lcd_options['d_pressure_sensor']:
                    result = "Cidlo tlaku:"
                else:
                    result = None
            elif index == 19:
                if lcd_options['d_pressure_sensor']:
                    try:
                        from plugins import pressure_monitor
                        state_press = pressure_monitor.get_check_pressure()
                        if state_press:
                            result = "neaktivni"
                        else:
                            result = "aktivni"

                    except Exception:
                        result = "neni k dispozici"
                else:
                    result = None

            elif index == 20:
                if lcd_options['d_water_tank_level']:
                    result = "Nadrz s vodou:"
                else:
                    result = None
            elif index == 21:
                if lcd_options['d_water_tank_level']:
                    try:
                        from plugins import tank_humi_monitor
                        cm = tank_humi_monitor.get_sonic_tank_cm()
                        if cm > 0:
                            result = str(cm) + ' cm'
                        else:
                            result = "chyba - I2C zarizeni nenalezeno!"

                    except Exception:
                        result = "neni k dispozici"
                else:
                    result = None

            return ASCI_convert(result)

    if (options.lang == 'en_US') or (options.lang == 'default'):
        if station_state and lcd_options[
                'd_running_stations']:  # print on LCD only this text
            if index == 0 or index == 2 or index == 4 or index == 6 or index == 8 or index == 10 or index == 12 or index == 14 or index == 16 or index == 18 or index == 20:  # start text to 16x1
                result = "Running stations:"
            elif index == 1 or index == 3 or index == 5 or index == 7 or index == 9 or index == 11 or index == 13 or index == 15 or index == 17 or index == 19 or index == 21:
                result = station_result
            return result

        else:

            if index == 0:
                if lcd_options['d_system_name']:
                    result = options.name
                else:
                    result = None
            elif index == 1:
                if lcd_options['d_system_name']:
                    result = "Irrigation system"
                else:
                    result = None

            elif index == 2:
                if lcd_options['d_sw_version_date']:
                    result = "SW Version:"
                else:
                    result = None
            elif index == 3:
                if lcd_options['d_sw_version_date']:
                    result = version.ver_str + ' (' + version.ver_date + ')'
                else:
                    result = None

            elif index == 4:
                if lcd_options['d_ip']:
                    result = "My IP is:"
                else:
                    result = None
            elif index == 5:
                if lcd_options['d_ip']:
                    ip = helpers.get_ip()
                    result = str(ip)
                else:
                    result = None

            elif index == 6:
                if lcd_options['d_port']:
                    result = "My Port is:"
                else:
                    result = None
            elif index == 7:
                if lcd_options['d_port']:
                    result = str(options.web_port)
                else:
                    result = None

            elif index == 8:
                if lcd_options['d_cpu_temp']:
                    result = "CPU Temperature:"
                else:
                    result = None
            elif index == 9:
                if lcd_options['d_cpu_temp']:
                    result = helpers.get_cpu_temp(
                        options.temp_unit) + ' ' + options.temp_unit
                else:
                    result = None

            elif index == 10:
                if lcd_options['d_time_date']:
                    result = datetime.now().strftime('Date: %d.%m.%Y')
                else:
                    result = None
            elif index == 11:
                if lcd_options['d_time_date']:
                    result = datetime.now().strftime('Time: %H:%M:%S')
                else:
                    result = None

            elif index == 12:
                if lcd_options['d_uptime']:
                    result = "System Uptime:"
                else:
                    result = None
            elif index == 13:
                if lcd_options['d_uptime']:
                    result = helpers.uptime()
                else:
                    result = None

            elif index == 14:
                if lcd_options['d_rain_sensor']:
                    result = "Rain Sensor:"
                else:
                    result = None
            elif index == 15:
                if lcd_options['d_rain_sensor']:
                    if inputs.rain_sensed():
                        result = "Active"
                    else:
                        result = "Inactive"
                else:
                    result = None

            elif index == 16:
                if lcd_options['d_last_run']:
                    result = 'Last Program:'
                else:
                    result = None
            elif index == 17:
                if lcd_options['d_last_run']:
                    finished = [
                        run for run in log.finished_runs()
                        if not run['blocked']
                    ]
                    if finished:
                        result = finished[-1]['start'].strftime(
                            '%H:%M: ') + finished[-1]['program_name']
                        result = result.replace('Run-Once', 'Jednorazovy')
                    else:
                        result = 'None'
                else:
                    result = None

            elif index == 18:
                if lcd_options['d_pressure_sensor']:
                    result = "Pressure Sensor:"
                else:
                    result = None
            elif index == 19:
                if lcd_options['d_pressure_sensor']:
                    try:
                        from plugins import pressure_monitor
                        state_press = pressure_monitor.get_check_pressure()
                        if state_press:
                            result = "GPIO is HIGH"
                        else:
                            result = "GPIO is LOW"

                    except Exception:
                        result = "Not Available"
                else:
                    result = None

            elif index == 20:
                if lcd_options['d_water_tank_level']:
                    result = "Water Tank Level:"
                else:
                    result = None
            elif index == 21:
                if lcd_options['d_water_tank_level']:
                    try:
                        from plugins import tank_humi_monitor
                        cm = tank_humi_monitor.get_sonic_tank_cm()
                        if cm > 0:
                            result = str(cm) + ' cm'
                        else:
                            result = "Error - I2C Device Not Found!"

                    except Exception:
                        result = "Not Available"
                else:
                    result = None

            return result
Esempio n. 6
0
    def POST(self):
        qdict = web.input()

        change = False  # if change language -> restart ospy

        if 'lang' in qdict and qdict['lang']:
            if options.lang != qdict['lang']:
                change = True

        newname = qdict['name']  # if name is asci char
        try:
            from ospy.helpers import ASCI_convert
            qdict['name'] = ASCI_convert(newname)
        except:
            qdict['name'] = ' '

        save_to_options(qdict)

        if 'master' in qdict:
            m = int(qdict['master'])
            if m < 0:
                stations.master = None
            elif m < stations.count():
                stations.master = m

        if 'master_two' in qdict:
            m = int(qdict['master_two'])
            if m < 0:
                stations.master_two = None
            elif m < stations.count():
                stations.master_two = m

        if 'old_password' in qdict and qdict['old_password'] != "":
            try:
                if test_password(qdict['old_password']):
                    if qdict['new_password'] == "":
                        raise web.seeother('/options?errorCode=pw_blank')
                    elif qdict['new_password'] == qdict['check_password']:
                        options.password_salt = password_salt(
                        )  # Make a new salt
                        options.password_hash = password_hash(
                            qdict['new_password'], options.password_salt)
                    else:
                        raise web.seeother('/options?errorCode=pw_mismatch')
                else:
                    raise web.seeother('/options?errorCode=pw_wrong')
            except KeyError:
                pass

        if 'rbt' in qdict and qdict['rbt'] == '1':
            reboot(True)  # Linux HW software
            return self.core_render.home()

        if 'rstrt' in qdict and qdict['rstrt'] == '1':
            restart()  # OSPy software
            return self.core_render.restarting(home_page)

        if 'pwrdwn' in qdict and qdict['pwrdwn'] == '1':
            poweroff()  # shutdown HW system
            return self.core_render.restarting(home_page)

        if 'deldef' in qdict and qdict['deldef'] == '1':
            OPTIONS_FILE = './ospy/data'
            try:
                import shutil, time
                shutil.rmtree(OPTIONS_FILE)  # delete data folder
                time.sleep(2)
                os.makedirs(OPTIONS_FILE)  # create data folder
                restart()  # restart OSPy software
                return self.core_render.restarting(home_page)
            except:
                pass

        if change:
            restart()  # OSPy software
            return self.core_render.restarting(home_page)

        raise web.seeother('/')