class cl_fact_main_sensor: # Only a singleton instance for main_sensor __o_sensor_type = cl_fact_main_sensor_type().get_instance() __o_instance = None @classmethod def get_instance(self, i_address=None): cl_fact_logger.get_instance().debug(cl_fact_logger.get_instance().me()) if cl_fact_main_sensor.__o_instance is not None: return (cl_fact_main_sensor.__o_instance) try: if cl_fact_main_sensor.__o_sensor_type._get_type_ui() == 'SHT75': cl_fact_main_sensor.__o_instance = cl_fact_sensor_sht75.get_instance( ) elif cl_fact_main_sensor.__o_sensor_type._get_type_ui() == 'SHT3x': cl_fact_main_sensor.__o_instance = cl_fact_sensor_sht3x.get_instance( i_address) elif cl_fact_main_sensor.__o_sensor_type._get_type_ui() == 'SHT85': cl_fact_main_sensor.__o_instance = cl_fact_sensor_sht85.get_instance( i_address) elif cl_fact_main_sensor.__o_sensor_type._get_type_ui() == 'DHT22': cl_fact_main_sensor.__o_instance = cl_fact_sensor_dht22.get_instance( ) elif cl_fact_main_sensor.__o_sensor_type._get_type_ui() == 'DHT11': cl_fact_main_sensor.__o_instance = cl_fact_sensor_dht11.get_instance( ) except Exception as original_error: raise original_error return (cl_fact_main_sensor.__o_instance) @classmethod def set_instance(self, i_instance): cl_fact_logger.get_instance().debug(cl_fact_logger.get_instance().me()) cl_fact_main_sensor.__o_instance = i_instance def __init__(self): cl_fact_logger.get_instance().debug(cl_fact_logger.get_instance().me()) pass
class cl_fact_sensor_dht22: fact_main_sensor_type = cl_fact_main_sensor_type() # Only a singleton instance for main_sensor __o_sensor_type = fact_main_sensor_type.get_instance() __o_instance = None @classmethod def get_instance(self): cl_fact_logger.get_instance().debug(cl_fact_logger.get_instance().me()) if cl_fact_sensor_dht22.__o_instance is not None: return (cl_fact_sensor_dht22.__o_instance) cl_fact_sensor_dht22.__o_instance = cl_main_sensor_dht22() return (cl_fact_sensor_dht22.__o_instance) @classmethod def set_instance(self, i_instance): cl_fact_logger.get_instance().debug(cl_fact_logger.get_instance().me()) cl_fact_sensor_dht22.__o_instance = i_instance def __init__(self): cl_fact_logger.get_instance().debug(cl_fact_logger.get_instance().me()) pass
def read_dictionary_write_settings(period_dictionary): """ function for writing the settings into the DB """ from sensors.pi_ager_cl_sensor_type import cl_fact_main_sensor_type global period_endtime global period_starttime_seconds global day_in_seconds global switch_on_cooling_compressor global switch_off_cooling_compressor global switch_on_humidifier global switch_off_humidifier global delay_humidify global sensorname global sensortype cl_fact_logger.get_instance().debug('read_dictionary_write_settings()') # Variablen aus Dictionary setzen for key, value in iter(period_dictionary.items()): if value == None or value == '': # wenn ein Wert leer ist muss er aus der letzten settings.json ausgelesen werden value = pi_ager_database.get_table_value( pi_ager_names.config_settings_table, key) period_dictionary[key] = value else: value = int(value) period_dictionary[key] = value global duration_sleep duration_sleep = get_duration_sleep( int(period_dictionary['days']) ) # Anzahl der Tage von "column" mit 86400 (Sekunden) multipliziert fuer wartezeit bis zur naechsten Periode # Aufbereitung fuer die Lesbarkeit im Logfile und Fuellen der Variablen modus = int( period_dictionary['modus'] + 0.5 ) # Rundet auf Ganzzahl, Integer da der Modus immer Integer sein sollte #-------Logstring--------- if modus == 0: operating_mode = "\n" + '.................................' + _( 'operation mode') + ': ' + _('cooling') elif modus == 1: operating_mode = "\n" + '.................................' + _( 'operation mode') + ': ' + _('cooling with humidify') elif modus == 2: operating_mode = "\n" + '.................................' + _( 'operation mode') + ': ' + _('heating with humidify') elif modus == 3: operating_mode = "\n" + '.................................' + _( 'operation mode') + ': ' + _('automatic with humidify') elif modus == 4: operating_mode = "\n" + '.................................' + _( 'operation mode') + ': ' + _( 'automatic with dehumidify and humidify') else: operating_mode = "\n" + '.................................' + _( 'operation mode wrong or set incorrectly') setpoint_temperature_logstring = "\n" + '.................................' + _( 'setpoint temperature') + ": " + str( period_dictionary['setpoint_temperature']) + " C" switch_on_cooling_compressor_logstring = "\n" + '.................................' + _( 'switch-on value temperature') + ": " + str( switch_on_cooling_compressor) + " C" switch_off_cooling_compressor_logstring = "\n" + '.................................' + _( 'switch-off value temperature') + ": " + str( switch_off_cooling_compressor) + " C" setpoint_humidity_logstring = "\n" + '.................................' + _( 'setpoint humidity') + ": " + str( period_dictionary['setpoint_humidity']) + "%" switch_on_humidifier_logstring = "\n" + '.................................' + _( 'switch-on value humidity') + ": " + str(switch_on_humidifier) + "%" switch_off_humidifier_logstring = "\n" + '.................................' + _( 'switch-off value humidity') + ": " + str(switch_off_humidifier) + "%" delay_humidify_logstring = "\n" + '.................................' + _( 'humidification delay') + ": " + str(delay_humidify) + ' ' + _( "minutes") circulation_air_period_format = int( period_dictionary['circulation_air_period']) / 60 circulation_air_period_logstring = "\n" + '.................................' + _( 'timer circulation air period every') + ": " + str( circulation_air_period_format) + ' ' + _("minutes") circulation_air_duration_format = int( period_dictionary['circulation_air_duration']) / 60 circulation_air_duration_logstring = "\n" + '.................................' + _( 'timer circulation air') + ": " + str( circulation_air_duration_format) + ' ' + _("minutes") exhaust_air_period_format = int( period_dictionary['exhaust_air_period']) / 60 exhaust_air_period_logstring = "\n" + '.................................' + _( 'timer exhaust air period every') + ": " + str( exhaust_air_period_format) + ' ' + _("minutes") exhaust_air_duration_format = int( period_dictionary['exhaust_air_duration']) / 60 exhaust_air_duration_logstring = "\n" + '.................................' + _( 'timer exhausting air') + ": " + str( exhaust_air_duration_format) + ' ' + _("minutes") period_days_logstring = "\n" + '.................................' + _( 'duration') + ": " + str(period_dictionary['days']) + ' ' + _('days') sensor_logstring = '.................................' + _( 'sensortype') + ": " + cl_fact_main_sensor_type().get_instance( )._get_type_ui() pi_ager_database.write_settings( modus, period_dictionary['setpoint_temperature'], period_dictionary['setpoint_humidity'], period_dictionary['circulation_air_period'], period_dictionary['circulation_air_duration'], period_dictionary['exhaust_air_period'], period_dictionary['exhaust_air_duration']) period_starttime_seconds = pi_ager_database.get_current_time() pi_ager_database.write_current_value( pi_ager_names.agingtable_period_starttime_key, period_starttime_seconds) period_endtime = datetime.datetime.now() + datetime.timedelta( days=period_dictionary['days'] ) # days = parameter von datetime.timedelta logstring = _( 'values' ) + ': ' + operating_mode + setpoint_temperature_logstring + switch_on_cooling_compressor_logstring + switch_off_cooling_compressor_logstring + "\n" + setpoint_humidity_logstring + switch_on_humidifier_logstring + switch_off_humidifier_logstring + delay_humidify_logstring + "\n" + circulation_air_period_logstring + circulation_air_duration_logstring + "\n" + exhaust_air_period_logstring + exhaust_air_duration_logstring + "\n" + period_days_logstring + "\n" + sensor_logstring + "\n" cl_fact_logger.get_instance().info(logstring)
#global logger pi_ager_names.create_json_file() pi_ager_database_check.check_and_update_database() pi_ager_init.set_language() #logger = pi_ager_logging.create_logger('main') #logger.debug('logging initialised') cl_fact_logger.get_instance().debug(('logging initialised __________________________')) #logger.info(pi_ager_names.logspacer) cl_fact_logger.get_instance().info((pi_ager_names.logspacer)) pi_revision.get_and_write_revision_in_database() pi_ager_init.setup_GPIO() #pi_ager_init.set_sensortype() cl_fact_main_sensor_type().get_instance()._is_valid() pi_ager_init.set_system_starttime() os.system('sudo /var/sudowebscript.sh pkillscale &') time.sleep(2) os.system('sudo /var/sudowebscript.sh startscale &') #logger.debug('scale restart done') cl_fact_logger.get_instance().debug(('scale restart done')) exception_known = True # Send a start message try: cl_fact_logic_messenger().get_instance().send_mail('Pi-Ager Start', 'Pi-Ager was started') except Exception as cx_error: exception_known = cl_fact_logic_messenger().get_instance().handle_exception(cx_error) pass