def choices_measurements_units(measurements, units): dict_measurements = add_custom_measurements(measurements) dict_units = add_custom_units(units) # Sort dictionary by keys sorted_keys = sorted(list(dict_measurements), key=lambda s: s.casefold()) sorted_dict_measurements = [] for each_key in sorted_keys: sorted_dict_measurements.append( {'key': each_key, 'measurement': dict_measurements[each_key]}) choices = [] for each_meas in sorted_dict_measurements: for each_unit in each_meas['measurement']['units']: try: value = '{meas},{unit}'.format( meas=each_meas['key'], unit=each_unit) display = '{meas}: {unit_name}'.format( meas=each_meas['measurement']['name'], unit_name=dict_units[each_unit]['name']) if dict_units[each_unit]['unit']: display += ' ({unit})'.format( unit=dict_units[each_unit]['unit']) choices.append({'value': value, 'item': display}) except Exception as e: logger.exception( "Error in choices_measurements_units(): {}".format(e)) return choices
def get(self, unique_id, unit, channel, past_seconds): """ Return the last measurement found within a duration from the past to the present """ if not utils_general.user_has_permission('view_settings'): abort(403) if unit not in add_custom_units(Unit.query.all()): abort(422, custom='Unit ID not found') if channel < 0: abort(422, custom='channel must be >= 0') if past_seconds < 1: abort(422, custom='past_seconds must be >= 1') try: return_ = read_influxdb_single(unique_id, unit, channel, duration_sec=past_seconds) if return_ and len(return_) == 2: return {'time': return_[0], 'value': return_[1]}, 200 else: return return_, 200 except Exception: abort(500, message='An exception occurred', error=traceback.format_exc())
def get_measurement_info(device_id, measurement_id): unit_display = "" name = "" device_measurement = get_measurement(measurement_id) conversion = db_retrieve_table_daemon( Conversion, unique_id=device_measurement.conversion_id) channel, unit, measurement = return_measurement_info( device_measurement, conversion) dict_units = add_custom_units(db_retrieve_table_daemon(Unit, entry='all')) if unit in dict_units: unit_display = dict_units[unit]['unit'] if unit_display: unit_length = len(unit_display.replace('°', u'')) else: unit_length = 0 controllers = [Output, PID, Input, Function] for each_controller in controllers: controller_found = db_retrieve_table_daemon(each_controller, unique_id=device_id) if controller_found: name = controller_found.name break return unit_display, unit_length, name
def choices_measurements_units(measurements, units): dict_measurements = add_custom_measurements(measurements) dict_units = add_custom_units(units) # Sort dictionary by keys sorted_keys = sorted(list(dict_measurements), key=lambda s: s.casefold()) sorted_dict_measurements = OrderedDict() for each_key in sorted_keys: sorted_dict_measurements[each_key] = dict_measurements[each_key] choices = OrderedDict() for each_meas, each_info in sorted_dict_measurements.items(): for each_unit in each_info['units']: try: value = '{meas},{unit}'.format( meas=each_meas, unit=each_unit) display = '{meas}: {unit_name}'.format( meas=each_info['name'], unit_name=dict_units[each_unit]['name']) if dict_units[each_unit]['unit']: display += ' ({unit})'.format( unit=dict_units[each_unit]['unit']) choices.update({value: display}) except Exception as e: logger.exception( "Error in choices_measurements_units(): {}".format(e)) return choices
def get(self, unique_id, unit, channel, past_seconds): """ Return a list of measurements found within a duration from the past to the present """ if not utils_general.user_has_permission('view_settings'): abort(403) if unit not in add_custom_units(Unit.query.all()): abort(422, custom='Unit ID not found') if channel < 0: abort(422, custom='channel must be >= 0') if past_seconds < 1: abort(422, custom='past_seconds must be >= 1') try: return_ = read_influxdb_list(unique_id, unit, channel, duration_sec=past_seconds) if return_ and len(return_) > 0: dict_return = {'measurements': []} for each_set in return_: dict_return['measurements'].append({ 'time': each_set[0], 'value': each_set[1] }) return dict_return, 200 else: return return_, 200 except Exception: abort(500, message='An exception occurred', error=traceback.format_exc())
def check_display_names(measure, unit): dict_measurements = add_custom_measurements(Measurement.query.all()) dict_units = add_custom_units(Unit.query.all()) if measure in dict_measurements: measure = dict_measurements[measure]['name'] if unit in dict_units: unit = dict_units[unit]['unit'] return measure, unit
def settings_input(): """ Display measurement settings """ if not utils_general.user_has_permission('view_settings'): return redirect(url_for('routes_general.home')) form_input = forms_settings.Input() form_input_delete = forms_settings.InputDel() dict_measurements = add_custom_measurements(Measurement.query.all()) dict_units = add_custom_units(Unit.query.all()) # Get list of custom inputs excluded_files = ['__init__.py', '__pycache__'] install_dir = os.path.abspath(INSTALL_DIRECTORY) path_custom_inputs = os.path.join(install_dir, 'mycodo/inputs/custom_inputs') if request.method == 'POST': if not utils_general.user_has_permission('edit_controllers'): return redirect(url_for('routes_general.home')) if form_input.import_input_upload.data: utils_settings.settings_input_import(form_input) elif form_input_delete.delete_input.data: utils_settings.settings_input_delete(form_input_delete) return redirect(url_for('routes_settings.settings_input')) dict_inputs = {} for each_file in os.listdir(path_custom_inputs): if each_file not in excluded_files: try: full_path_file = os.path.join(path_custom_inputs, each_file) input_info = load_module_from_file(full_path_file) dict_inputs[ input_info.INPUT_INFORMATION['input_name_unique']] = {} dict_inputs[input_info.INPUT_INFORMATION['input_name_unique']]['input_name'] = \ input_info.INPUT_INFORMATION['input_name'] dict_inputs[input_info.INPUT_INFORMATION['input_name_unique']]['input_manufacturer'] = \ input_info.INPUT_INFORMATION['input_manufacturer'] dict_inputs[input_info.INPUT_INFORMATION['input_name_unique']]['measurements_name'] = \ input_info.INPUT_INFORMATION['measurements_name'] except: pass # dict_inputs = parse_input_information() return render_template('settings/input.html', dict_inputs=dict_inputs, dict_measurements=dict_measurements, dict_units=dict_units, form_input=form_input, form_input_delete=form_input_delete)
def settings_input(): """ Display measurement settings """ if not utils_general.user_has_permission('view_settings'): return redirect(url_for('routes_general.home')) form_input = forms_settings.Input() form_input_delete = forms_settings.InputDel() dict_measurements = add_custom_measurements(Measurement.query.all()) dict_units = add_custom_units(Unit.query.all()) # Get list of custom inputs excluded_files = ['__init__.py', '__pycache__'] install_dir = os.path.abspath(INSTALL_DIRECTORY) path_custom_inputs = os.path.join(install_dir, 'mycodo/inputs/custom_inputs') if request.method == 'POST': if not utils_general.user_has_permission('edit_controllers'): return redirect(url_for('routes_general.home')) if form_input.import_input_upload.data: utils_settings.settings_input_import(form_input) elif form_input_delete.delete_input.data: utils_settings.settings_input_delete(form_input_delete) return redirect(url_for('routes_settings.settings_input')) dict_inputs = {} for each_file in os.listdir(path_custom_inputs): if each_file not in excluded_files: try: full_path_file = os.path.join(path_custom_inputs, each_file) input_info = load_module_from_file(full_path_file) dict_inputs[input_info.INPUT_INFORMATION['input_name_unique']] = {} dict_inputs[input_info.INPUT_INFORMATION['input_name_unique']]['input_name'] = \ input_info.INPUT_INFORMATION['input_name'] dict_inputs[input_info.INPUT_INFORMATION['input_name_unique']]['input_manufacturer'] = \ input_info.INPUT_INFORMATION['input_manufacturer'] dict_inputs[input_info.INPUT_INFORMATION['input_name_unique']]['measurements_name'] = \ input_info.INPUT_INFORMATION['measurements_name'] except: pass # dict_inputs = parse_input_information() return render_template('settings/input.html', dict_inputs=dict_inputs, dict_measurements=dict_measurements, dict_units=dict_units, form_input=form_input, form_input_delete=form_input_delete)
def get(self, unique_id, unit, channel, epoch_start, epoch_end): """ Return a list of measurements found within a time range """ if not utils_general.user_has_permission('view_settings'): abort(403) if unit not in add_custom_units(Unit.query.all()): abort(422, custom='Unit ID not found') if channel < 0: abort(422, custom='channel must be >= 0') if epoch_start < 0 or epoch_end < 0: abort(422, custom='epoch_start and epoch_end must be >= 0') utc_offset_timedelta = datetime.datetime.utcnow( ) - datetime.datetime.now() if epoch_start: start = datetime.datetime.fromtimestamp(float(epoch_start)) start += utc_offset_timedelta start_str = start.strftime('%Y-%m-%dT%H:%M:%S.%fZ') else: start_str = None if epoch_end: end = datetime.datetime.fromtimestamp(float(epoch_end)) end += utc_offset_timedelta end_str = end.strftime('%Y-%m-%dT%H:%M:%S.%fZ') else: end_str = None try: return_ = read_influxdb_list(unique_id, unit, channel, start_str=start_str, end_str=end_str) if return_ and len(return_) > 0: dict_return = {'measurements': []} for each_set in return_: dict_return['measurements'].append({ 'time': each_set[0], 'value': each_set[1] }) return dict_return, 200 else: return return_, 200 except Exception: abort(500, message='An exception occurred', error=traceback.format_exc())
def settings_widget(): """Display widget settings.""" if not utils_general.user_has_permission('view_settings'): return redirect(url_for('routes_general.home')) form_widget = forms_settings.Widget() form_widget_delete = forms_settings.WidgetDel() dict_measurements = add_custom_measurements(Measurement.query.all()) dict_units = add_custom_units(Unit.query.all()) # Get list of custom widgets excluded_files = ['__init__.py', '__pycache__'] if request.method == 'POST': if not utils_general.user_has_permission('edit_controllers'): return redirect(url_for('routes_general.home')) if form_widget.import_widget_upload.data: utils_settings.settings_widget_import(form_widget) elif form_widget_delete.delete_widget.data: utils_settings.settings_widget_delete(form_widget_delete) return redirect(url_for('routes_settings.settings_widget')) dict_widgets = {} for each_file in os.listdir(PATH_WIDGETS_CUSTOM): if each_file not in excluded_files: try: full_path_file = os.path.join(PATH_WIDGETS_CUSTOM, each_file) widget_info, status = load_module_from_file( full_path_file, 'widgets') if widget_info: dict_widgets[widget_info.WIDGET_INFORMATION[ 'widget_name_unique']] = {} dict_widgets[widget_info.WIDGET_INFORMATION['widget_name_unique']]['widget_name'] = \ widget_info.WIDGET_INFORMATION['widget_name'] dict_widgets[widget_info.WIDGET_INFORMATION['widget_name_unique']]['measurements_name'] = \ widget_info.WIDGET_INFORMATION['measurements_name'] except: pass return render_template('settings/widget.html', dict_widgets=dict_widgets, dict_measurements=dict_measurements, dict_units=dict_units, form_widget=form_widget, form_widget_delete=form_widget_delete)
def settings_output(): """ Display measurement settings """ if not utils_general.user_has_permission('view_settings'): return redirect(url_for('routes_general.home')) form_output = forms_settings.Output() form_output_delete = forms_settings.OutputDel() dict_measurements = add_custom_measurements(Measurement.query.all()) dict_units = add_custom_units(Unit.query.all()) # Get list of custom outputs excluded_files = ['__init__.py', '__pycache__'] if request.method == 'POST': if not utils_general.user_has_permission('edit_controllers'): return redirect(url_for('routes_general.home')) if form_output.import_output_upload.data: utils_settings.settings_output_import(form_output) elif form_output_delete.delete_output.data: utils_settings.settings_output_delete(form_output_delete) return redirect(url_for('routes_settings.settings_output')) dict_outputs = {} for each_file in os.listdir(PATH_OUTPUTS_CUSTOM): if each_file not in excluded_files: try: full_path_file = os.path.join(PATH_OUTPUTS_CUSTOM, each_file) output_info = load_module_from_file(full_path_file, 'outputs') dict_outputs[ output_info.OUTPUT_INFORMATION['output_name_unique']] = {} dict_outputs[output_info.OUTPUT_INFORMATION['output_name_unique']]['output_name'] = \ output_info.OUTPUT_INFORMATION['output_name'] dict_outputs[output_info.OUTPUT_INFORMATION['output_name_unique']]['measurements_name'] = \ output_info.OUTPUT_INFORMATION['measurements_name'] except: pass # dict_outputs = parse_output_information() return render_template('settings/output.html', dict_outputs=dict_outputs, dict_measurements=dict_measurements, dict_units=dict_units, form_output=form_output, form_output_delete=form_output_delete)
def get(self): """Show form choices for all input measurements.""" if not utils_general.user_has_permission('view_settings'): abort(403) try: input_dev = Input.query.all() dict_measurements = add_custom_measurements( Measurement.query.all()) dict_units = add_custom_units(Unit.query.all()) input_choices = utils_general.choices_inputs( input_dev, dict_units, dict_measurements) if input_choices: return {'choices inputs measurements': input_choices}, 200 except Exception: abort(500, message='An exception occurred', error=traceback.format_exc())
def get(self): """Show form choices for all PID measurements""" if not utils_general.user_has_permission('view_settings'): abort(403) try: pid = PID.query.all() dict_measurements = add_custom_measurements( Measurement.query.all()) dict_units = add_custom_units(Unit.query.all()) pid_choices = utils_general.choices_pids(pid, dict_units, dict_measurements) if pid_choices: return {'choices pids measurements': pid_choices}, 200 except Exception: abort(500, message='An exception occurred', error=traceback.format_exc())
def post(self, unique_id, unit, channel, value): """Create a measurement.""" if not utils_general.user_has_permission('edit_controllers'): abort(403) if unit not in add_custom_units(Unit.query.all()): abort(422, custom='Unit ID not found') if channel < 0: abort(422, custom='channel must be >= 0') try: value = float(value) except: abort(422, custom='value does not represent a float') timestamp = None if ns_measurement.payload and 'timestamp' in ns_measurement.payload: ts = ns_measurement.payload["timestamp"] if ts is not None: if valid_date_str(ts): timestamp = datetime.datetime.strptime( ts, '%Y-%m-%dT%H:%M:%S.%fZ') else: abort( 422, custom= 'Invalid timestamp format. Must be formatted as %Y-%m-%dT%H:%M:%S.%fZ' ) try: return_ = write_influxdb_value(unique_id, unit, value, channel=channel, timestamp=timestamp) if return_: abort(500) else: return {'message': 'Success'}, 200 except Exception: abort(500, message='An exception occurred', error=traceback.format_exc())
def get(self): """Show form choices for all output measurements.""" if not utils_general.user_has_permission('view_settings'): abort(403) try: output = Output.query.all() dict_outputs = parse_output_information() dict_measurements = add_custom_measurements( Measurement.query.all()) dict_units = add_custom_units(Unit.query.all()) output_choices = utils_general.choices_outputs( output, OutputChannel, dict_outputs, dict_units, dict_measurements) if output_choices: return {'choices outputs measurements': output_choices}, 200 except Exception: abort(500, message='An exception occurred', error=traceback.format_exc())
def choices_measurements_units(measurements, units): dict_measurements = add_custom_measurements(measurements) dict_units = add_custom_units(units) # Sort dictionary by keys sorted_keys = sorted(list(dict_measurements), key=lambda s: s.casefold()) sorted_dict_measurements = OrderedDict() for each_key in sorted_keys: sorted_dict_measurements[each_key] = dict_measurements[each_key] choices = OrderedDict() for each_meas, each_info in sorted_dict_measurements.items(): for each_unit in each_info['units']: value = '{meas},{unit}'.format( meas=each_meas, unit=each_unit) display = '{meas}: {unit_name}'.format( meas=each_info['name'], unit_name=dict_units[each_unit]['name']) if dict_units[each_unit]['unit']: display += ' ({unit})'.format( unit=dict_units[each_unit]['unit']) choices.update({value: display}) return choices
# Multiple sets of dependencies, append library inputs_info[name_str]['dependencies_module'].append( input_data['dependencies_module']) else: # Only one set of dependencies inputs_info[name_str] = input_data if 'dependencies_module' in input_data: inputs_info[name_str]['dependencies_module'] = [ input_data['dependencies_module'] ] # turn into list inputs_info = dict( OrderedDict(sorted(inputs_info.items(), key=lambda t: t[0]))) dict_measurements = add_custom_measurements([]) dict_units = add_custom_units([]) dict_inputs = {} for name, data in inputs_info.items(): if 'measurements_dict' not in data: continue for channel, measure in data['measurements_dict'].items(): if measure["measurement"]: if measure["measurement"] not in dict_inputs: dict_inputs[measure["measurement"]] = {} dict_inputs[measure["measurement"]][name] = data dict_inputs = dict( OrderedDict(sorted(dict_inputs.items(), key=lambda t: t[0])))
def page_input(): """ Display Data page options """ input_type = request.args.get('input_type', None) input_id = request.args.get('input_id', None) each_input = None if input_type in ['entry', 'options']: each_input = Input.query.filter(Input.unique_id == input_id).first() function = CustomController.query.all() input_dev = Input.query.all() input_channel = InputChannel.query.all() math = Math.query.all() method = Method.query.all() measurement = Measurement.query.all() output = Output.query.all() output_channel = OutputChannel.query.all() pid = PID.query.all() user = User.query.all() unit = Unit.query.all() display_order_input = csv_to_list_of_str(DisplayOrder.query.first().inputs) display_order_math = csv_to_list_of_str(DisplayOrder.query.first().math) form_add_input = forms_input.InputAdd() form_mod_input = forms_input.InputMod() form_mod_math = forms_math.MathMod() form_mod_math_measurement = forms_math.MathMeasurementMod() form_mod_average_single = forms_math.MathModAverageSingle() form_mod_sum_single = forms_math.MathModSumSingle() form_mod_redundancy = forms_math.MathModRedundancy() form_mod_difference = forms_math.MathModDifference() form_mod_equation = forms_math.MathModEquation() form_mod_humidity = forms_math.MathModHumidity() form_mod_verification = forms_math.MathModVerification() form_mod_misc = forms_math.MathModMisc() dict_inputs = parse_input_information() if request.method == 'POST': # TODO: Remove entire POST section and remove Math controllers if not utils_general.user_has_permission('edit_controllers'): return redirect(url_for('routes_input.page_input')) # Mod Math Measurement if form_mod_math_measurement.math_measurement_mod.data: utils_math.math_measurement_mod(form_mod_math_measurement) # Mod other Math settings elif form_mod_math.math_mod.data: math_type = Math.query.filter( Math.unique_id == form_mod_math.math_id.data).first().math_type if math_type == 'humidity': utils_math.math_mod(form_mod_math, form_mod_humidity) elif math_type == 'average_single': utils_math.math_mod(form_mod_math, form_mod_average_single) elif math_type == 'sum_single': utils_math.math_mod(form_mod_math, form_mod_sum_single) elif math_type == 'redundancy': utils_math.math_mod(form_mod_math, form_mod_redundancy) elif math_type == 'difference': utils_math.math_mod(form_mod_math, form_mod_difference) elif math_type == 'equation': utils_math.math_mod(form_mod_math, form_mod_equation) elif math_type == 'verification': utils_math.math_mod(form_mod_math, form_mod_verification) elif math_type == 'vapor_pressure_deficit': utils_math.math_mod(form_mod_math, form_mod_misc) else: utils_math.math_mod(form_mod_math) elif form_mod_math.math_delete.data: utils_math.math_del(form_mod_math) elif form_mod_math.math_order_up.data: utils_math.math_reorder(form_mod_math.math_id.data, display_order_math, 'up') elif form_mod_math.math_order_down.data: utils_math.math_reorder(form_mod_math.math_id.data, display_order_math, 'down') elif form_mod_math.math_activate.data: utils_math.math_activate(form_mod_math) elif form_mod_math.math_deactivate.data: utils_math.math_deactivate(form_mod_math) return redirect(url_for('routes_input.page_input')) custom_options_values_inputs = parse_custom_option_values( input_dev, dict_controller=dict_inputs) custom_options_values_input_channels = parse_custom_option_values_input_channels_json( input_channel, dict_controller=dict_inputs, key_name='custom_channel_options') custom_actions = {} for each_input in input_dev: if 'custom_actions' in dict_inputs[each_input.device]: custom_actions[each_input.device] = True # Generate dict that incorporate user-added measurements/units dict_outputs = parse_output_information() dict_units = add_custom_units(unit) dict_measurements = add_custom_measurements(measurement) # Create list of choices to be used in dropdown menus choices_function = utils_general.choices_functions(function, dict_units, dict_measurements) choices_input = utils_general.choices_inputs(input_dev, dict_units, dict_measurements) choices_math = utils_general.choices_maths(math, dict_units, dict_measurements) choices_method = utils_general.choices_methods(method) choices_output = utils_general.choices_outputs(output, dict_units, dict_measurements) choices_output_channels = utils_general.choices_outputs_channels( output, output_channel, dict_outputs) choices_output_channels_measurements = utils_general.choices_outputs_channels_measurements( output, OutputChannel, dict_outputs, dict_units, dict_measurements) choices_pid = utils_general.choices_pids(pid, dict_units, dict_measurements) choices_pid_devices = utils_general.choices_pids_devices(pid) choices_unit = utils_general.choices_units(unit) choices_measurement = utils_general.choices_measurements(measurement) choices_measurements_units = utils_general.choices_measurements_units( measurement, unit) # Create dict of Input names names_input = {} all_elements = input_dev for each_element in all_elements: names_input[ each_element.unique_id] = '[{id:02d}] ({uid}) {name}'.format( id=each_element.id, uid=each_element.unique_id.split('-')[0], name=each_element.name) # Create dict of Math names names_math = {} all_elements = math for each_element in all_elements: names_math[ each_element.unique_id] = '[{id:02d}] ({uid}) {name}'.format( id=each_element.id, uid=each_element.unique_id.split('-')[0], name=each_element.name) # Create list of file names from the math_options directory # Used in generating the correct options for each math controller math_templates = [] math_path = os.path.join( INSTALL_DIRECTORY, 'mycodo/mycodo_flask/templates/pages/data_options/math_options') for (_, _, file_names) in os.walk(math_path): math_templates.extend(file_names) break # Create list of file names from the input_options directory # Used in generating the correct options for each input controller input_templates = [] input_path = os.path.join( INSTALL_DIRECTORY, 'mycodo/mycodo_flask/templates/pages/data_options/input_options') for (_, _, file_names) in os.walk(input_path): input_templates.extend(file_names) break # If DS18B20 inputs added, compile a list of detected inputs devices_1wire_w1thermsensor = [] if os.path.isdir(PATH_1WIRE): for each_name in os.listdir(PATH_1WIRE): if 'bus' not in each_name and '-' in each_name: devices_1wire_w1thermsensor.append({ 'name': each_name, 'value': each_name.split('-')[1] }) # Add 1-wire devices from ow-shell (if installed) devices_1wire_ow_shell = [] if current_app.config['TESTING']: logger.debug("Testing: Skipping testing for 'ow-shell'") elif not dpkg_package_exists('ow-shell'): logger.debug("Package 'ow-shell' not found") else: logger.debug("Package 'ow-shell' found") try: test_cmd = subprocess.check_output(['owdir']).splitlines() for each_ow in test_cmd: str_ow = re.sub("\ |\/|\'", "", each_ow.decode("utf-8")) # Strip / and ' if '.' in str_ow and len(str_ow) == 15: devices_1wire_ow_shell.append(str_ow) except Exception: logger.error("Error finding 1-wire devices with 'owdir'") # Find FTDI devices ftdi_devices = [] if not current_app.config['TESTING']: for each_input in input_dev: if each_input.interface == "FTDI": from mycodo.devices.atlas_scientific_ftdi import get_ftdi_device_list ftdi_devices = get_ftdi_device_list() break if not input_type: return render_template( 'pages/input.html', and_=and_, choices_function=choices_function, choices_input=choices_input, choices_math=choices_math, choices_output=choices_output, choices_measurement=choices_measurement, choices_measurements_units=choices_measurements_units, choices_method=choices_method, choices_output_channels=choices_output_channels, choices_output_channels_measurements= choices_output_channels_measurements, choices_pid=choices_pid, choices_pid_devices=choices_pid_devices, choices_unit=choices_unit, custom_actions=custom_actions, custom_options_values_inputs=custom_options_values_inputs, custom_options_values_input_channels= custom_options_values_input_channels, dict_inputs=dict_inputs, dict_measurements=dict_measurements, dict_units=dict_units, display_order_input=display_order_input, display_order_math=display_order_math, form_add_input=form_add_input, form_mod_input=form_mod_input, form_mod_average_single=form_mod_average_single, form_mod_sum_single=form_mod_sum_single, form_mod_redundancy=form_mod_redundancy, form_mod_difference=form_mod_difference, form_mod_equation=form_mod_equation, form_mod_humidity=form_mod_humidity, form_mod_math=form_mod_math, form_mod_math_measurement=form_mod_math_measurement, form_mod_verification=form_mod_verification, form_mod_misc=form_mod_misc, ftdi_devices=ftdi_devices, input_channel=input_channel, input_templates=input_templates, math_info=MATH_INFO, math_templates=math_templates, names_input=names_input, names_math=names_math, output=output, output_types=output_types(), pid=pid, table_conversion=Conversion, table_device_measurements=DeviceMeasurements, table_input=Input, table_math=Math, user=user, devices_1wire_ow_shell=devices_1wire_ow_shell, devices_1wire_w1thermsensor=devices_1wire_w1thermsensor) elif input_type == 'entry': return render_template( 'pages/data_options/input_entry.html', and_=and_, choices_function=choices_function, choices_input=choices_input, choices_math=choices_math, choices_output=choices_output, choices_measurement=choices_measurement, choices_measurements_units=choices_measurements_units, choices_method=choices_method, choices_output_channels=choices_output_channels, choices_output_channels_measurements= choices_output_channels_measurements, choices_pid=choices_pid, choices_pid_devices=choices_pid_devices, choices_unit=choices_unit, custom_actions=custom_actions, custom_options_values_inputs=custom_options_values_inputs, custom_options_values_input_channels= custom_options_values_input_channels, dict_inputs=dict_inputs, dict_measurements=dict_measurements, dict_units=dict_units, display_order_input=display_order_input, display_order_math=display_order_math, each_input=each_input, form_add_input=form_add_input, form_mod_input=form_mod_input, form_mod_average_single=form_mod_average_single, form_mod_sum_single=form_mod_sum_single, form_mod_redundancy=form_mod_redundancy, form_mod_difference=form_mod_difference, form_mod_equation=form_mod_equation, form_mod_humidity=form_mod_humidity, form_mod_math=form_mod_math, form_mod_math_measurement=form_mod_math_measurement, form_mod_verification=form_mod_verification, form_mod_misc=form_mod_misc, ftdi_devices=ftdi_devices, input_channel=input_channel, input_templates=input_templates, math_info=MATH_INFO, math_templates=math_templates, names_input=names_input, names_math=names_math, output=output, output_types=output_types(), pid=pid, table_conversion=Conversion, table_device_measurements=DeviceMeasurements, table_input=Input, table_math=Math, user=user, devices_1wire_ow_shell=devices_1wire_ow_shell, devices_1wire_w1thermsensor=devices_1wire_w1thermsensor) elif input_type == 'options': return render_template( 'pages/data_options/input_options.html', and_=and_, choices_function=choices_function, choices_input=choices_input, choices_math=choices_math, choices_output=choices_output, choices_measurement=choices_measurement, choices_measurements_units=choices_measurements_units, choices_method=choices_method, choices_output_channels=choices_output_channels, choices_output_channels_measurements= choices_output_channels_measurements, choices_pid=choices_pid, choices_pid_devices=choices_pid_devices, choices_unit=choices_unit, custom_actions=custom_actions, custom_options_values_inputs=custom_options_values_inputs, custom_options_values_input_channels= custom_options_values_input_channels, dict_inputs=dict_inputs, dict_measurements=dict_measurements, dict_units=dict_units, display_order_input=display_order_input, display_order_math=display_order_math, each_input=each_input, form_add_input=form_add_input, form_mod_input=form_mod_input, form_mod_average_single=form_mod_average_single, form_mod_sum_single=form_mod_sum_single, form_mod_redundancy=form_mod_redundancy, form_mod_difference=form_mod_difference, form_mod_equation=form_mod_equation, form_mod_humidity=form_mod_humidity, form_mod_math=form_mod_math, form_mod_math_measurement=form_mod_math_measurement, form_mod_verification=form_mod_verification, form_mod_misc=form_mod_misc, ftdi_devices=ftdi_devices, input_channel=input_channel, input_templates=input_templates, math_info=MATH_INFO, math_templates=math_templates, names_input=names_input, names_math=names_math, output=output, output_types=output_types(), pid=pid, table_conversion=Conversion, table_device_measurements=DeviceMeasurements, table_input=Input, table_math=Math, user=user, devices_1wire_ow_shell=devices_1wire_ow_shell, devices_1wire_w1thermsensor=devices_1wire_w1thermsensor)
def page_function(): """Display Function page options.""" function_type = request.args.get('function_type', None) function_id = request.args.get('function_id', None) action_id = request.args.get('action_id', None) condition_id = request.args.get('condition_id', None) each_function = None each_action = None each_condition = None function_page_entry = None function_page_options = None controller_type = None if function_type in ['entry', 'options', 'conditions', 'actions'] and function_id != '0': controller_type = determine_controller_type(function_id) if controller_type == "Conditional": each_function = Conditional.query.filter( Conditional.unique_id == function_id).first() function_page_entry = 'pages/function_options/conditional_entry.html' function_page_options = 'pages/function_options/conditional_options.html' elif controller_type == "PID": each_function = PID.query.filter( PID.unique_id == function_id).first() function_page_entry = 'pages/function_options/pid_entry.html' function_page_options = 'pages/function_options/pid_options.html' elif controller_type == "Trigger": each_function = Trigger.query.filter( Trigger.unique_id == function_id).first() function_page_entry = 'pages/function_options/trigger_entry.html' function_page_options = 'pages/function_options/trigger_options.html' elif controller_type == "Function": each_function = Function.query.filter( Function.unique_id == function_id).first() function_page_entry = 'pages/function_options/function_entry.html' function_page_options = 'pages/function_options/function_options.html' elif controller_type == "Function_Custom": each_function = CustomController.query.filter( CustomController.unique_id == function_id).first() function_page_entry = 'pages/function_options/custom_function_entry.html' function_page_options = 'pages/function_options/custom_function_options.html' if function_type == 'actions' and action_id: each_action = Actions.query.filter( Actions.unique_id == action_id).first() if each_action: controller_type = determine_controller_type(each_action.function_id) if function_type == 'conditions'and condition_id: each_condition = ConditionalConditions.query.filter( ConditionalConditions.unique_id == condition_id).first() action = Actions.query.all() camera = Camera.query.all() conditional = Conditional.query.all() conditional_conditions = ConditionalConditions.query.all() function = CustomController.query.all() function_channel = FunctionChannel.query.all() function_dev = Function.query.all() input_dev = Input.query.all() measurement = Measurement.query.all() method = Method.query.all() tags = NoteTags.query.all() output = Output.query.all() output_channel = OutputChannel.query.all() pid = PID.query.all() trigger = Trigger.query.all() unit = Unit.query.all() user = User.query.all() display_order_function = csv_to_list_of_str( DisplayOrder.query.first().function) form_add_function = forms_function.FunctionAdd() form_mod_pid_base = forms_pid.PIDModBase() form_mod_pid_output_raise = forms_pid.PIDModRelayRaise() form_mod_pid_output_lower = forms_pid.PIDModRelayLower() form_mod_pid_pwm_raise = forms_pid.PIDModPWMRaise() form_mod_pid_pwm_lower = forms_pid.PIDModPWMLower() form_mod_pid_value_raise = forms_pid.PIDModValueRaise() form_mod_pid_value_lower = forms_pid.PIDModValueLower() form_mod_pid_volume_raise = forms_pid.PIDModVolumeRaise() form_mod_pid_volume_lower = forms_pid.PIDModVolumeLower() form_function_base = forms_function.FunctionMod() form_trigger = forms_trigger.Trigger() form_conditional = forms_conditional.Conditional() form_conditional_conditions = forms_conditional.ConditionalConditions() form_function = forms_custom_controller.CustomController() form_actions = forms_action.Actions() dict_controllers = parse_function_information() dict_actions = parse_action_information() # Generate all measurement and units used dict_measurements = add_custom_measurements(Measurement.query.all()) dict_units = add_custom_units(Unit.query.all()) dict_outputs = parse_output_information() custom_options_values_controllers = parse_custom_option_values( function, dict_controller=dict_controllers) custom_options_values_function_channels = parse_custom_option_values_function_channels_json( function_channel, dict_controller=function, key_name='custom_channel_options') custom_options_values_actions = {} for each_action_dev in action: try: custom_options_values_actions[each_action_dev.unique_id] = json.loads(each_action_dev.custom_options) except: custom_options_values_actions[each_action_dev.unique_id] = {} # Create lists of built-in and custom functions choices_functions = [] for choice_function in FUNCTIONS: choices_functions.append({'value': choice_function[0], 'item': choice_function[1]}) choices_custom_functions = utils_general.choices_custom_functions() # Combine function lists choices_functions_add = choices_functions + choices_custom_functions # Sort combined list choices_functions_add = sorted(choices_functions_add, key=lambda i: i['item']) custom_commands = {} for choice_function in function: if 'custom_commands' in dict_controllers[choice_function.device]: custom_commands[choice_function.device] = True # Generate Action dropdown for use with Inputs choices_actions = [] list_actions_sorted = generate_form_action_list(dict_actions, application=["functions"]) for name in list_actions_sorted: choices_actions.append((name, dict_actions[name]['name'])) # Create list of choices to be used in dropdown menus choices_function = utils_general.choices_functions( function, dict_units, dict_measurements) choices_input = utils_general.choices_inputs( input_dev, dict_units, dict_measurements) choices_input_devices = utils_general.choices_input_devices(input_dev) choices_method = utils_general.choices_methods(method) choices_output = utils_general.choices_outputs( output, OutputChannel, dict_outputs, dict_units, dict_measurements) choices_output_channels = utils_general.choices_outputs_channels( output, output_channel, dict_outputs) choices_output_channels_measurements = utils_general.choices_outputs_channels_measurements( output, OutputChannel, dict_outputs, dict_units, dict_measurements) choices_pid = utils_general.choices_pids( pid, dict_units, dict_measurements) choices_tag = utils_general.choices_tags(tags) choices_measurements_units = utils_general.choices_measurements_units( measurement, unit) choices_controller_ids = utils_general.choices_controller_ids() actions_dict = { 'conditional': {}, 'trigger': {} } for each_action_dev in action: if (each_action_dev.function_type == 'conditional' and each_action_dev.unique_id not in actions_dict['conditional']): actions_dict['conditional'][each_action_dev.function_id] = True if (each_action_dev.function_type == 'trigger' and each_action_dev.unique_id not in actions_dict['trigger']): actions_dict['trigger'][each_action_dev.function_id] = True conditions_dict = {} for each_cond in conditional_conditions: if each_cond.unique_id not in conditions_dict: conditions_dict[each_cond.conditional_id] = True controllers = [] controllers_all = [('Input', input_dev), ('Conditional', conditional), ('Function', function), ('PID', pid), ('Trigger', trigger)] for each_controller in controllers_all: for each_cont in each_controller[1]: controllers.append((each_controller[0], each_cont.unique_id, each_cont.id, each_cont.name)) # Create dict of Function names names_function = {} all_elements = [conditional, pid, trigger, function_dev, function] for each_element in all_elements: for each_func_name in each_element: names_function[each_func_name.unique_id] = '[{id}] {name}'.format( id=each_func_name.unique_id.split('-')[0], name=each_func_name.name) # Calculate sunrise/sunset times if conditional controller is set up properly sunrise_set_calc = {} for each_trigger in trigger: if each_trigger.trigger_type == 'trigger_sunrise_sunset': sunrise_set_calc[each_trigger.unique_id] = {} if not current_app.config['TESTING']: try: sunrise = suntime_calculate_next_sunrise_sunset_epoch( each_trigger.latitude, each_trigger.longitude, 0, 0, "sunrise", return_dt=True) sunset = suntime_calculate_next_sunrise_sunset_epoch( each_trigger.latitude, each_trigger.longitude, 0, 0, "sunset", return_dt=True) # Adjust for date offset offset_rise = suntime_calculate_next_sunrise_sunset_epoch( each_trigger.latitude, each_trigger.longitude, each_trigger.date_offset_days, each_trigger.time_offset_minutes, "sunrise", return_dt=True) offset_set = suntime_calculate_next_sunrise_sunset_epoch( each_trigger.latitude, each_trigger.longitude, each_trigger.date_offset_days, each_trigger.time_offset_minutes, "sunset", return_dt=True) sunrise_set_calc[each_trigger.unique_id]['sunrise'] = ( sunrise.strftime("%Y-%m-%d %H:%M")) sunrise_set_calc[each_trigger.unique_id]['sunset'] = ( sunset.strftime("%Y-%m-%d %H:%M")) sunrise_set_calc[each_trigger.unique_id]['offset_sunrise'] = ( offset_rise.strftime("%Y-%m-%d %H:%M")) sunrise_set_calc[each_trigger.unique_id]['offset_sunset'] = ( offset_set.strftime("%Y-%m-%d %H:%M")) except: logger.exception(1) sunrise_set_calc[each_trigger.unique_id]['sunrise'] = "ERROR" sunrise_set_calc[each_trigger.unique_id]['sunrise'] = "ERROR" sunrise_set_calc[each_trigger.unique_id]['offset_sunrise'] = "ERROR" sunrise_set_calc[each_trigger.unique_id]['offset_sunset'] = "ERROR" if not function_type: return render_template('pages/function.html', and_=and_, action=action, actions_dict=actions_dict, camera=camera, choices_actions=choices_actions, choices_controller_ids=choices_controller_ids, choices_custom_functions=choices_custom_functions, choices_function=choices_function, choices_functions=choices_functions, choices_functions_add=choices_functions_add, choices_input=choices_input, choices_input_devices=choices_input_devices, choices_measurements_units=choices_measurements_units, choices_method=choices_method, choices_output=choices_output, choices_output_channels=choices_output_channels, choices_output_channels_measurements=choices_output_channels_measurements, choices_pid=choices_pid, choices_tag=choices_tag, conditional_conditions_list=CONDITIONAL_CONDITIONS, conditional=conditional, conditional_conditions=conditional_conditions, conditions_dict=conditions_dict, controllers=controllers, controller_type=controller_type, function=function, function_channel=function_channel, custom_commands=custom_commands, custom_options_values_actions=custom_options_values_actions, custom_options_values_controllers=custom_options_values_controllers, custom_options_values_function_channels=custom_options_values_function_channels, dict_actions=dict_actions, dict_controllers=dict_controllers, dict_measurements=dict_measurements, dict_outputs=dict_outputs, dict_units=dict_units, display_order_function=display_order_function, form_conditional=form_conditional, form_conditional_conditions=form_conditional_conditions, form_function=form_function, form_actions=form_actions, form_add_function=form_add_function, form_function_base=form_function_base, form_mod_pid_base=form_mod_pid_base, form_mod_pid_pwm_raise=form_mod_pid_pwm_raise, form_mod_pid_pwm_lower=form_mod_pid_pwm_lower, form_mod_pid_output_raise=form_mod_pid_output_raise, form_mod_pid_output_lower=form_mod_pid_output_lower, form_mod_pid_value_raise=form_mod_pid_value_raise, form_mod_pid_value_lower=form_mod_pid_value_lower, form_mod_pid_volume_raise=form_mod_pid_volume_raise, form_mod_pid_volume_lower=form_mod_pid_volume_lower, form_trigger=form_trigger, function_dev=function_dev, function_types=FUNCTIONS, input=input_dev, method=method, names_function=names_function, output=output, output_types=output_types(), pid=pid, sunrise_set_calc=sunrise_set_calc, table_conversion=Conversion, table_device_measurements=DeviceMeasurements, table_input=Input, table_output=Output, tags=tags, trigger=trigger, units=MEASUREMENTS, user=user) elif function_type == 'entry': return render_template(function_page_entry, and_=and_, action=action, actions_dict=actions_dict, camera=camera, choices_actions=choices_actions, choices_controller_ids=choices_controller_ids, choices_custom_functions=choices_custom_functions, choices_function=choices_function, choices_functions=choices_functions, choices_functions_add=choices_functions_add, choices_input=choices_input, choices_input_devices=choices_input_devices, choices_measurements_units=choices_measurements_units, choices_method=choices_method, choices_output=choices_output, choices_output_channels=choices_output_channels, choices_output_channels_measurements=choices_output_channels_measurements, choices_pid=choices_pid, choices_tag=choices_tag, conditional_conditions_list=CONDITIONAL_CONDITIONS, conditional=conditional, conditional_conditions=conditional_conditions, conditions_dict=conditions_dict, controllers=controllers, controller_type=controller_type, function=function, function_channel=function_channel, custom_commands=custom_commands, custom_options_values_actions=custom_options_values_actions, custom_options_values_controllers=custom_options_values_controllers, custom_options_values_function_channels=custom_options_values_function_channels, dict_actions=dict_actions, dict_controllers=dict_controllers, dict_measurements=dict_measurements, dict_outputs=dict_outputs, dict_units=dict_units, display_order_function=display_order_function, each_function=each_function, form_conditional=form_conditional, form_conditional_conditions=form_conditional_conditions, form_function=form_function, form_actions=form_actions, form_add_function=form_add_function, form_function_base=form_function_base, form_mod_pid_base=form_mod_pid_base, form_mod_pid_pwm_raise=form_mod_pid_pwm_raise, form_mod_pid_pwm_lower=form_mod_pid_pwm_lower, form_mod_pid_output_raise=form_mod_pid_output_raise, form_mod_pid_output_lower=form_mod_pid_output_lower, form_mod_pid_value_raise=form_mod_pid_value_raise, form_mod_pid_value_lower=form_mod_pid_value_lower, form_mod_pid_volume_raise=form_mod_pid_volume_raise, form_mod_pid_volume_lower=form_mod_pid_volume_lower, form_trigger=form_trigger, function_dev=function_dev, function_types=FUNCTIONS, input=input_dev, method=method, names_function=names_function, output=output, output_types=output_types(), pid=pid, sunrise_set_calc=sunrise_set_calc, table_conversion=Conversion, table_device_measurements=DeviceMeasurements, table_input=Input, table_output=Output, tags=tags, trigger=trigger, units=MEASUREMENTS, user=user) elif function_type == 'options': return render_template(function_page_options, and_=and_, action=action, actions_dict=actions_dict, camera=camera, choices_actions=choices_actions, choices_controller_ids=choices_controller_ids, choices_custom_functions=choices_custom_functions, choices_function=choices_function, choices_functions=choices_functions, choices_functions_add=choices_functions_add, choices_input=choices_input, choices_input_devices=choices_input_devices, choices_measurements_units=choices_measurements_units, choices_method=choices_method, choices_output=choices_output, choices_output_channels=choices_output_channels, choices_output_channels_measurements=choices_output_channels_measurements, choices_pid=choices_pid, choices_tag=choices_tag, conditional_conditions_list=CONDITIONAL_CONDITIONS, conditional=conditional, conditional_conditions=conditional_conditions, conditions_dict=conditions_dict, controllers=controllers, controller_type=controller_type, each_function=each_function, function=function, function_channel=function_channel, custom_commands=custom_commands, custom_options_values_actions=custom_options_values_actions, custom_options_values_controllers=custom_options_values_controllers, custom_options_values_function_channels=custom_options_values_function_channels, dict_actions=dict_actions, dict_controllers=dict_controllers, dict_measurements=dict_measurements, dict_outputs=dict_outputs, dict_units=dict_units, display_order_function=display_order_function, form_conditional=form_conditional, form_conditional_conditions=form_conditional_conditions, form_function=form_function, form_actions=form_actions, form_add_function=form_add_function, form_function_base=form_function_base, form_mod_pid_base=form_mod_pid_base, form_mod_pid_pwm_raise=form_mod_pid_pwm_raise, form_mod_pid_pwm_lower=form_mod_pid_pwm_lower, form_mod_pid_output_raise=form_mod_pid_output_raise, form_mod_pid_output_lower=form_mod_pid_output_lower, form_mod_pid_value_raise=form_mod_pid_value_raise, form_mod_pid_value_lower=form_mod_pid_value_lower, form_mod_pid_volume_raise=form_mod_pid_volume_raise, form_mod_pid_volume_lower=form_mod_pid_volume_lower, form_trigger=form_trigger, function_dev=function_dev, function_types=FUNCTIONS, input=input_dev, method=method, names_function=names_function, output=output, output_types=output_types(), pid=pid, sunrise_set_calc=sunrise_set_calc, table_conversion=Conversion, table_device_measurements=DeviceMeasurements, table_input=Input, table_output=Output, tags=tags, trigger=trigger, units=MEASUREMENTS, user=user) elif function_type == 'actions': return render_template('pages/actions.html', and_=and_, action=action, actions_dict=actions_dict, camera=camera, choices_actions=choices_actions, choices_controller_ids=choices_controller_ids, choices_custom_functions=choices_custom_functions, choices_function=choices_function, choices_functions=choices_functions, choices_functions_add=choices_functions_add, choices_input=choices_input, choices_input_devices=choices_input_devices, choices_measurements_units=choices_measurements_units, choices_method=choices_method, choices_output=choices_output, choices_output_channels=choices_output_channels, choices_output_channels_measurements=choices_output_channels_measurements, choices_pid=choices_pid, choices_tag=choices_tag, conditional_conditions_list=CONDITIONAL_CONDITIONS, conditional=conditional, conditional_conditions=conditional_conditions, conditions_dict=conditions_dict, controllers=controllers, controller_type=controller_type, each_action=each_action, each_function=each_function, function=function, function_channel=function_channel, custom_commands=custom_commands, custom_options_values_actions=custom_options_values_actions, custom_options_values_controllers=custom_options_values_controllers, custom_options_values_function_channels=custom_options_values_function_channels, dict_actions=dict_actions, dict_controllers=dict_controllers, dict_measurements=dict_measurements, dict_outputs=dict_outputs, dict_units=dict_units, display_order_function=display_order_function, form_conditional=form_conditional, form_conditional_conditions=form_conditional_conditions, form_function=form_function, form_actions=form_actions, form_add_function=form_add_function, form_function_base=form_function_base, form_mod_pid_base=form_mod_pid_base, form_mod_pid_pwm_raise=form_mod_pid_pwm_raise, form_mod_pid_pwm_lower=form_mod_pid_pwm_lower, form_mod_pid_output_raise=form_mod_pid_output_raise, form_mod_pid_output_lower=form_mod_pid_output_lower, form_mod_pid_value_raise=form_mod_pid_value_raise, form_mod_pid_value_lower=form_mod_pid_value_lower, form_mod_pid_volume_raise=form_mod_pid_volume_raise, form_mod_pid_volume_lower=form_mod_pid_volume_lower, form_trigger=form_trigger, function_dev=function_dev, function_types=FUNCTIONS, input=input_dev, method=method, names_function=names_function, output=output, output_types=output_types(), pid=pid, sunrise_set_calc=sunrise_set_calc, table_conversion=Conversion, table_device_measurements=DeviceMeasurements, table_input=Input, table_output=Output, tags=tags, trigger=trigger, units=MEASUREMENTS, user=user) elif function_type == 'conditions': return render_template('pages/function_options/conditional_condition.html', and_=and_, action=action, actions_dict=actions_dict, camera=camera, choices_controller_ids=choices_controller_ids, choices_custom_functions=choices_custom_functions, choices_function=choices_function, choices_functions=choices_functions, choices_functions_add=choices_functions_add, choices_input=choices_input, choices_input_devices=choices_input_devices, choices_measurements_units=choices_measurements_units, choices_method=choices_method, choices_output=choices_output, choices_output_channels=choices_output_channels, choices_output_channels_measurements=choices_output_channels_measurements, choices_pid=choices_pid, choices_tag=choices_tag, conditional_conditions_list=CONDITIONAL_CONDITIONS, conditional=conditional, conditional_conditions=conditional_conditions, conditions_dict=conditions_dict, controllers=controllers, controller_type=controller_type, each_condition=each_condition, each_function=each_function, function=function, function_channel=function_channel, custom_commands=custom_commands, custom_options_values_actions=custom_options_values_actions, custom_options_values_controllers=custom_options_values_controllers, custom_options_values_function_channels=custom_options_values_function_channels, dict_actions=dict_actions, dict_controllers=dict_controllers, dict_measurements=dict_measurements, dict_outputs=dict_outputs, dict_units=dict_units, display_order_function=display_order_function, form_conditional=form_conditional, form_conditional_conditions=form_conditional_conditions, form_function=form_function, form_actions=form_actions, form_add_function=form_add_function, form_function_base=form_function_base, form_mod_pid_base=form_mod_pid_base, form_mod_pid_pwm_raise=form_mod_pid_pwm_raise, form_mod_pid_pwm_lower=form_mod_pid_pwm_lower, form_mod_pid_output_raise=form_mod_pid_output_raise, form_mod_pid_output_lower=form_mod_pid_output_lower, form_mod_pid_value_raise=form_mod_pid_value_raise, form_mod_pid_value_lower=form_mod_pid_value_lower, form_mod_pid_volume_raise=form_mod_pid_volume_raise, form_mod_pid_volume_lower=form_mod_pid_volume_lower, form_trigger=form_trigger, function_dev=function_dev, function_types=FUNCTIONS, input=input_dev, method=method, names_function=names_function, output=output, output_types=output_types(), pid=pid, sunrise_set_calc=sunrise_set_calc, table_conversion=Conversion, table_device_measurements=DeviceMeasurements, table_input=Input, table_output=Output, tags=tags, trigger=trigger, units=MEASUREMENTS, user=user) else: return "Could not determine template"
def __init__(self, ready, lcd_id): threading.Thread.__init__(self) self.logger = logging.getLogger("mycodo.lcd_{id}".format(id=lcd_id.split('-')[0])) self.running = False self.thread_startup_timer = timeit.default_timer() self.thread_shutdown_timer = 0 self.ready = ready self.flash_lcd_on = False self.lcd_initialized = False self.lcd_is_on = False self.lcd_id = lcd_id self.display_sets = [] self.display_set_count = 0 try: lcd_dev = db_retrieve_table_daemon(LCD, unique_id=self.lcd_id) self.lcd_type = lcd_dev.lcd_type self.lcd_name = lcd_dev.name self.lcd_i2c_address = int(lcd_dev.location, 16) self.lcd_i2c_bus = lcd_dev.i2c_bus self.lcd_period = lcd_dev.period self.lcd_x_characters = lcd_dev.x_characters self.lcd_y_lines = lcd_dev.y_lines self.timer = time.time() + self.lcd_period self.backlight_timer = time.time() self.list_pids = ['setpoint', 'pid_time'] self.list_outputs = ['duration_time', 'output_time', 'output_state'] # Add custom measurement and units to list self.list_inputs = add_custom_measurements( db_retrieve_table_daemon(Measurement, entry='all')) self.list_inputs.update( {'input_time': {'unit': None, 'name': 'Time'}}) self.list_inputs.update( {'pid_time': {'unit': None, 'name': 'Time'}}) self.dict_units = add_custom_units( db_retrieve_table_daemon(Unit, entry='all')) lcd_data = db_retrieve_table_daemon( LCDData).filter(LCDData.lcd_id == lcd_dev.unique_id).all() self.lcd_string_line = {} self.lcd_line = {} self.lcd_max_age = {} self.lcd_decimal_places = {} for each_lcd_display in lcd_data: self.display_sets.append(each_lcd_display.unique_id) self.lcd_string_line[each_lcd_display.unique_id] = {} self.lcd_line[each_lcd_display.unique_id] = {} self.lcd_max_age[each_lcd_display.unique_id] = {} self.lcd_decimal_places[each_lcd_display.unique_id] = {} for i in range(1, self.lcd_y_lines + 1): self.lcd_string_line[each_lcd_display.unique_id][i] = '' self.lcd_line[each_lcd_display.unique_id][i] = {} if i == 1: self.lcd_max_age[each_lcd_display.unique_id][i] = each_lcd_display.line_1_max_age self.lcd_decimal_places[each_lcd_display.unique_id][i] = each_lcd_display.line_1_decimal_places elif i == 2: self.lcd_max_age[each_lcd_display.unique_id][i] = each_lcd_display.line_2_max_age self.lcd_decimal_places[each_lcd_display.unique_id][i] = each_lcd_display.line_2_decimal_places elif i == 3: self.lcd_max_age[each_lcd_display.unique_id][i] = each_lcd_display.line_3_max_age self.lcd_decimal_places[each_lcd_display.unique_id][i] = each_lcd_display.line_3_decimal_places elif i == 4: self.lcd_max_age[each_lcd_display.unique_id][i] = each_lcd_display.line_4_max_age self.lcd_decimal_places[each_lcd_display.unique_id][i] = each_lcd_display.line_4_decimal_places elif i == 5: self.lcd_max_age[each_lcd_display.unique_id][i] = each_lcd_display.line_5_max_age self.lcd_decimal_places[each_lcd_display.unique_id][i] = each_lcd_display.line_5_decimal_places elif i == 6: self.lcd_max_age[each_lcd_display.unique_id][i] = each_lcd_display.line_6_max_age self.lcd_decimal_places[each_lcd_display.unique_id][i] = each_lcd_display.line_6_decimal_places elif i == 7: self.lcd_max_age[each_lcd_display.unique_id][i] = each_lcd_display.line_7_max_age self.lcd_decimal_places[each_lcd_display.unique_id][i] = each_lcd_display.line_7_decimal_places elif i == 8: self.lcd_max_age[each_lcd_display.unique_id][i] = each_lcd_display.line_8_max_age self.lcd_decimal_places[each_lcd_display.unique_id][i] = each_lcd_display.line_8_decimal_places if self.lcd_y_lines in [2, 4, 8]: self.setup_lcd_line( each_lcd_display.unique_id, 1, each_lcd_display.line_1_id, each_lcd_display.line_1_measurement) self.setup_lcd_line( each_lcd_display.unique_id, 2, each_lcd_display.line_2_id, each_lcd_display.line_2_measurement) if self.lcd_y_lines in [4, 8]: self.setup_lcd_line( each_lcd_display.unique_id, 3, each_lcd_display.line_3_id, each_lcd_display.line_3_measurement) self.setup_lcd_line( each_lcd_display.unique_id, 4, each_lcd_display.line_4_id, each_lcd_display.line_4_measurement) if self.lcd_y_lines == 8: self.setup_lcd_line( each_lcd_display.unique_id, 5, each_lcd_display.line_5_id, each_lcd_display.line_5_measurement) self.setup_lcd_line( each_lcd_display.unique_id, 6, each_lcd_display.line_6_id, each_lcd_display.line_6_measurement) self.setup_lcd_line( each_lcd_display.unique_id, 7, each_lcd_display.line_7_id, each_lcd_display.line_7_measurement) self.setup_lcd_line( each_lcd_display.unique_id, 8, each_lcd_display.line_8_id, each_lcd_display.line_8_measurement) if self.lcd_type in ['16x2_generic', '16x4_generic']: from mycodo.devices.lcd_generic import LCD_Generic self.lcd_out = LCD_Generic(lcd_dev) self.lcd_init() elif self.lcd_type in ['128x32_pioled', '128x64_pioled']: from mycodo.devices.lcd_pioled import LCD_Pioled self.lcd_out = LCD_Pioled(lcd_dev) self.lcd_init() else: self.logger.error("Unknown LCD type: {}".format(self.lcd_type)) if self.lcd_initialized: line_1 = 'Mycodo {}'.format(MYCODO_VERSION) line_2 = 'Start {}'.format(self.lcd_name) self.lcd_out.lcd_write_lines(line_1, line_2, '', '') except Exception as except_msg: self.logger.exception("Error: {err}".format(err=except_msg))
def __init__(self, ready, lcd_id): threading.Thread.__init__(self) self.logger = logging.getLogger( "mycodo.lcd_{id}".format(id=lcd_id.split('-')[0])) self.running = False self.thread_startup_timer = timeit.default_timer() self.thread_shutdown_timer = 0 self.ready = ready self.flash_lcd_on = False self.lcd_initilized = False self.lcd_is_on = False self.lcd_id = lcd_id self.display_ids = [] self.display_count = 0 self.LCD_LINE = {1: 0x80, 2: 0xC0, 3: 0x94, 4: 0xD4} self.LCD_CHR = 1 # Mode - Sending data self.LCD_CMD = 0 # Mode - SenLCDding command self.LCD_BACKLIGHT = 0x08 # On self.LCD_BACKLIGHT_OFF = 0x00 # Off self.ENABLE = 0b00000100 # Enable bit # Timing constants self.E_PULSE = 0.0005 self.E_DELAY = 0.0005 try: lcd = db_retrieve_table_daemon(LCD, unique_id=self.lcd_id) self.lcd_name = lcd.name self.lcd_location = lcd.location self.lcd_i2c_bus = lcd.i2c_bus self.lcd_period = lcd.period self.lcd_x_characters = lcd.x_characters self.lcd_y_lines = lcd.y_lines self.timer = time.time() + self.lcd_period self.backlight_timer = time.time() self.list_pids = ['setpoint', 'pid_time'] self.list_outputs = [ 'duration_time', 'output_time', 'output_state' ] self.list_inputs = MEASUREMENTS self.list_inputs.update( {'input_time': { 'unit': None, 'name': 'Time' }}) self.list_inputs.update( {'pid_time': { 'unit': None, 'name': 'Time' }}) # Add custom measurement and units to list self.list_inputs = add_custom_measurements( db_retrieve_table_daemon(Measurement)) self.dict_units = add_custom_units(db_retrieve_table_daemon(Unit)) lcd_data = db_retrieve_table_daemon(LCDData).filter( LCDData.lcd_id == lcd.unique_id).all() self.lcd_string_line = {} self.lcd_line = {} self.lcd_max_age = {} self.lcd_decimal_places = {} for each_lcd_display in lcd_data: self.display_ids.append(each_lcd_display.unique_id) self.lcd_string_line[each_lcd_display.unique_id] = {} self.lcd_line[each_lcd_display.unique_id] = {} self.lcd_max_age[each_lcd_display.unique_id] = {} self.lcd_decimal_places[each_lcd_display.unique_id] = {} for i in range(1, self.lcd_y_lines + 1): self.lcd_string_line[each_lcd_display.unique_id][i] = '' self.lcd_line[each_lcd_display.unique_id][i] = {} if i == 1: self.lcd_max_age[each_lcd_display.unique_id][ i] = each_lcd_display.line_1_max_age self.lcd_decimal_places[each_lcd_display.unique_id][ i] = each_lcd_display.line_1_decimal_places elif i == 2: self.lcd_max_age[each_lcd_display.unique_id][ i] = each_lcd_display.line_2_max_age self.lcd_decimal_places[each_lcd_display.unique_id][ i] = each_lcd_display.line_2_decimal_places elif i == 3: self.lcd_max_age[each_lcd_display.unique_id][ i] = each_lcd_display.line_3_max_age self.lcd_decimal_places[each_lcd_display.unique_id][ i] = each_lcd_display.line_3_decimal_places elif i == 4: self.lcd_max_age[each_lcd_display.unique_id][ i] = each_lcd_display.line_4_max_age self.lcd_decimal_places[each_lcd_display.unique_id][ i] = each_lcd_display.line_4_decimal_places if self.lcd_y_lines in [2, 4]: self.setup_lcd_line(each_lcd_display.unique_id, 1, each_lcd_display.line_1_id, each_lcd_display.line_1_measurement) self.setup_lcd_line(each_lcd_display.unique_id, 2, each_lcd_display.line_2_id, each_lcd_display.line_2_measurement) if self.lcd_y_lines == 4: self.setup_lcd_line(each_lcd_display.unique_id, 3, each_lcd_display.line_3_id, each_lcd_display.line_3_measurement) self.setup_lcd_line(each_lcd_display.unique_id, 4, each_lcd_display.line_4_id, each_lcd_display.line_4_measurement) self.LCD_WIDTH = self.lcd_x_characters # Max characters per line # Setup I2C bus try: self.bus = SMBus(self.lcd_i2c_bus) except Exception as except_msg: self.logger.exception( "Could not initialize I2C bus: {err}".format( err=except_msg)) self.I2C_ADDR = int(self.lcd_location, 16) self.lcd_init() if self.lcd_initilized: self.lcd_string_write('Mycodo {}'.format(MYCODO_VERSION), self.LCD_LINE[1]) self.lcd_string_write('Start {}'.format(self.lcd_name), self.LCD_LINE[2]) except Exception as except_msg: self.logger.exception("Error: {err}".format(err=except_msg))
def settings_measurement(): """Display measurement settings.""" if not utils_general.user_has_permission('view_settings'): return redirect(url_for('routes_general.home')) measurement = Measurement.query.all() unit = Unit.query.all() conversion = Conversion.query.all() form_add_measurement = forms_settings.MeasurementAdd() form_mod_measurement = forms_settings.MeasurementMod() form_add_unit = forms_settings.UnitAdd() form_mod_unit = forms_settings.UnitMod() form_add_conversion = forms_settings.ConversionAdd() form_mod_conversion = forms_settings.ConversionMod() choices_units = utils_general.choices_units(unit) # Generate all measurement and units used dict_measurements = add_custom_measurements(measurement) dict_units = add_custom_units(unit) if request.method == 'POST': if not utils_general.user_has_permission('edit_controllers'): return redirect(url_for('routes_general.home')) if form_add_measurement.add_measurement.data: utils_settings.settings_measurement_add(form_add_measurement) elif form_mod_measurement.save_measurement.data: utils_settings.settings_measurement_mod(form_mod_measurement) elif form_mod_measurement.delete_measurement.data: utils_settings.settings_measurement_del( form_mod_measurement.measurement_id.data) elif form_add_unit.add_unit.data: utils_settings.settings_unit_add(form_add_unit) elif form_mod_unit.save_unit.data: utils_settings.settings_unit_mod(form_mod_unit) elif form_mod_unit.delete_unit.data: utils_settings.settings_unit_del(form_mod_unit.unit_id.data) elif form_add_conversion.add_conversion.data: utils_settings.settings_convert_add(form_add_conversion) elif form_mod_conversion.save_conversion.data: utils_settings.settings_convert_mod(form_mod_conversion) elif form_mod_conversion.delete_conversion.data: utils_settings.settings_convert_del( form_mod_conversion.conversion_id.data) return redirect(url_for('routes_settings.settings_measurement')) return render_template('settings/measurement.html', dict_measurements=dict_measurements, dict_units=dict_units, choices_units=choices_units, measurement=measurement, unit=unit, conversion=conversion, form_add_measurement=form_add_measurement, form_mod_measurement=form_mod_measurement, form_add_unit=form_add_unit, form_mod_unit=form_mod_unit, form_add_conversion=form_add_conversion, form_mod_conversion=form_mod_conversion)
def __init__(self, ready, lcd_id): threading.Thread.__init__(self) self.logger = logging.getLogger( "mycodo.lcd_{id}".format(id=lcd_id.split('-')[0])) self.running = False self.thread_startup_timer = timeit.default_timer() self.thread_shutdown_timer = 0 self.ready = ready self.flash_lcd_on = False self.lcd_initialized = False self.lcd_is_on = False self.lcd_id = lcd_id self.display_sets = [] self.display_set_count = 0 try: lcd_dev = db_retrieve_table_daemon(LCD, unique_id=self.lcd_id) self.lcd_type = lcd_dev.lcd_type self.lcd_name = lcd_dev.name self.lcd_i2c_address = int(lcd_dev.location, 16) self.lcd_i2c_bus = lcd_dev.i2c_bus self.lcd_period = lcd_dev.period self.lcd_x_characters = lcd_dev.x_characters self.lcd_y_lines = lcd_dev.y_lines self.timer = time.time() + self.lcd_period self.backlight_timer = time.time() self.list_pids = ['setpoint', 'pid_time'] self.list_outputs = [ 'duration_time', 'output_time', 'output_state' ] # Add custom measurement and units to list self.list_inputs = add_custom_measurements( db_retrieve_table_daemon(Measurement, entry='all')) self.list_inputs.update( {'input_time': { 'unit': None, 'name': 'Time' }}) self.list_inputs.update( {'pid_time': { 'unit': None, 'name': 'Time' }}) self.dict_units = add_custom_units( db_retrieve_table_daemon(Unit, entry='all')) lcd_data = db_retrieve_table_daemon(LCDData).filter( LCDData.lcd_id == lcd_dev.unique_id).all() self.lcd_string_line = {} self.lcd_line = {} self.lcd_max_age = {} self.lcd_decimal_places = {} for each_lcd_display in lcd_data: self.display_sets.append(each_lcd_display.unique_id) self.lcd_string_line[each_lcd_display.unique_id] = {} self.lcd_line[each_lcd_display.unique_id] = {} self.lcd_max_age[each_lcd_display.unique_id] = {} self.lcd_decimal_places[each_lcd_display.unique_id] = {} for i in range(1, self.lcd_y_lines + 1): self.lcd_string_line[each_lcd_display.unique_id][i] = '' self.lcd_line[each_lcd_display.unique_id][i] = {} if i == 1: self.lcd_max_age[each_lcd_display.unique_id][ i] = each_lcd_display.line_1_max_age self.lcd_decimal_places[each_lcd_display.unique_id][ i] = each_lcd_display.line_1_decimal_places elif i == 2: self.lcd_max_age[each_lcd_display.unique_id][ i] = each_lcd_display.line_2_max_age self.lcd_decimal_places[each_lcd_display.unique_id][ i] = each_lcd_display.line_2_decimal_places elif i == 3: self.lcd_max_age[each_lcd_display.unique_id][ i] = each_lcd_display.line_3_max_age self.lcd_decimal_places[each_lcd_display.unique_id][ i] = each_lcd_display.line_3_decimal_places elif i == 4: self.lcd_max_age[each_lcd_display.unique_id][ i] = each_lcd_display.line_4_max_age self.lcd_decimal_places[each_lcd_display.unique_id][ i] = each_lcd_display.line_4_decimal_places elif i == 5: self.lcd_max_age[each_lcd_display.unique_id][ i] = each_lcd_display.line_5_max_age self.lcd_decimal_places[each_lcd_display.unique_id][ i] = each_lcd_display.line_5_decimal_places elif i == 6: self.lcd_max_age[each_lcd_display.unique_id][ i] = each_lcd_display.line_6_max_age self.lcd_decimal_places[each_lcd_display.unique_id][ i] = each_lcd_display.line_6_decimal_places elif i == 7: self.lcd_max_age[each_lcd_display.unique_id][ i] = each_lcd_display.line_7_max_age self.lcd_decimal_places[each_lcd_display.unique_id][ i] = each_lcd_display.line_7_decimal_places elif i == 8: self.lcd_max_age[each_lcd_display.unique_id][ i] = each_lcd_display.line_8_max_age self.lcd_decimal_places[each_lcd_display.unique_id][ i] = each_lcd_display.line_8_decimal_places if self.lcd_y_lines in [2, 4, 8]: self.setup_lcd_line(each_lcd_display.unique_id, 1, each_lcd_display.line_1_id, each_lcd_display.line_1_measurement) self.setup_lcd_line(each_lcd_display.unique_id, 2, each_lcd_display.line_2_id, each_lcd_display.line_2_measurement) if self.lcd_y_lines in [4, 8]: self.setup_lcd_line(each_lcd_display.unique_id, 3, each_lcd_display.line_3_id, each_lcd_display.line_3_measurement) self.setup_lcd_line(each_lcd_display.unique_id, 4, each_lcd_display.line_4_id, each_lcd_display.line_4_measurement) if self.lcd_y_lines == 8: self.setup_lcd_line(each_lcd_display.unique_id, 5, each_lcd_display.line_5_id, each_lcd_display.line_5_measurement) self.setup_lcd_line(each_lcd_display.unique_id, 6, each_lcd_display.line_6_id, each_lcd_display.line_6_measurement) self.setup_lcd_line(each_lcd_display.unique_id, 7, each_lcd_display.line_7_id, each_lcd_display.line_7_measurement) self.setup_lcd_line(each_lcd_display.unique_id, 8, each_lcd_display.line_8_id, each_lcd_display.line_8_measurement) if self.lcd_type in ['16x2_generic', '20x4_generic']: from mycodo.devices.lcd_generic import LCD_Generic self.lcd_out = LCD_Generic(lcd_dev) self.lcd_init() elif self.lcd_type in ['128x32_pioled', '128x64_pioled']: from mycodo.devices.lcd_pioled import LCD_Pioled self.lcd_out = LCD_Pioled(lcd_dev) self.lcd_init() else: self.logger.error("Unknown LCD type: {}".format(self.lcd_type)) if self.lcd_initialized: line_1 = 'Mycodo {}'.format(MYCODO_VERSION) line_2 = 'Start {}'.format(self.lcd_name) self.lcd_out.lcd_write_lines(line_1, line_2, '', '') except Exception as except_msg: self.logger.exception("Error: {err}".format(err=except_msg))
def page_dashboard(dashboard_id): """ Generate custom dashboard with various data """ # Retrieve tables from SQL database camera = Camera.query.all() conditional = Conditional.query.all() function = CustomController.query.all() widget = Widget.query.all() this_dashboard = Dashboard.query.filter( Dashboard.unique_id == dashboard_id).first() input_dev = Input.query.all() device_measurements = DeviceMeasurements.query.all() math = Math.query.all() method = Method.query.all() misc = Misc.query.first() output = Output.query.all() output_channel = OutputChannel.query.all() pid = PID.query.all() tags = NoteTags.query.all() # Create form objects form_base = forms_dashboard.DashboardBase() form_dashboard = forms_dashboard.DashboardConfig() if request.method == 'POST': unmet_dependencies = None if not utils_general.user_has_permission('edit_controllers'): return redirect(url_for('routes_general.home')) # Dashboard if form_dashboard.dash_modify.data: utils_dashboard.dashboard_mod(form_dashboard) elif form_dashboard.dash_duplicate.data: utils_dashboard.dashboard_copy(form_dashboard) elif form_dashboard.lock.data: utils_dashboard.dashboard_lock(form_dashboard.dashboard_id.data, True) elif form_dashboard.unlock.data: utils_dashboard.dashboard_lock(form_dashboard.dashboard_id.data, False) elif form_dashboard.dash_delete.data: utils_dashboard.dashboard_del(form_dashboard) return redirect(url_for('routes_dashboard.page_dashboard_default')) # Widget elif form_base.create.data: unmet_dependencies = utils_dashboard.widget_add( form_base, request.form) elif form_base.modify.data: utils_dashboard.widget_mod(form_base, request.form) elif form_base.delete.data: utils_dashboard.widget_del(form_base) if unmet_dependencies: return redirect( url_for('routes_admin.admin_dependencies', device=form_base.graph_type.data)) return redirect( url_for('routes_dashboard.page_dashboard', dashboard_id=dashboard_id)) # Generate all measurement and units used dict_measurements = add_custom_measurements(Measurement.query.all()) dict_units = add_custom_units(Unit.query.all()) # Generate dictionary of each measurement ID with the correct measurement/unit used with it dict_measure_measurements = {} dict_measure_units = {} for each_measurement in device_measurements: # If the measurement is a PID setpoint, set unit to PID measurement. measurement = None unit = None if each_measurement.measurement_type == 'setpoint': setpoint_pid = PID.query.filter( PID.unique_id == each_measurement.device_id).first() if setpoint_pid and ',' in setpoint_pid.measurement: pid_measurement = setpoint_pid.measurement.split(',')[1] setpoint_measurement = DeviceMeasurements.query.filter( DeviceMeasurements.unique_id == pid_measurement).first() if setpoint_measurement: conversion = Conversion.query.filter( Conversion.unique_id == setpoint_measurement.conversion_id).first() _, unit, measurement = return_measurement_info( setpoint_measurement, conversion) else: conversion = Conversion.query.filter( Conversion.unique_id == each_measurement.conversion_id).first() _, unit, measurement = return_measurement_info( each_measurement, conversion) if unit: dict_measure_measurements[each_measurement.unique_id] = measurement dict_measure_units[each_measurement.unique_id] = unit dict_outputs = parse_output_information() dict_widgets = parse_widget_information() custom_options_values_widgets = parse_custom_option_values_json( widget, dict_controller=dict_widgets) custom_options_values_output_channels = parse_custom_option_values_output_channels_json( output_channel, dict_controller=dict_outputs, key_name='custom_channel_options') widget_types_on_dashboard = [] custom_widget_variables = {} widgets_dash = Widget.query.filter( Widget.dashboard_id == dashboard_id).all() for each_widget in widgets_dash: # Make list of widget types on this particular dashboard if each_widget.graph_type not in widget_types_on_dashboard: widget_types_on_dashboard.append(each_widget.graph_type) # Generate dictionary of returned values from widget modules on this particular dashboard if 'generate_page_variables' in dict_widgets[each_widget.graph_type]: custom_widget_variables[each_widget.unique_id] = dict_widgets[ each_widget.graph_type]['generate_page_variables']( each_widget.unique_id, custom_options_values_widgets[each_widget.unique_id]) # generate lists of html files to include in dashboard template list_html_files_body = {} list_html_files_title_bar = {} list_html_files_head = {} list_html_files_configure_options = {} list_html_files_js = {} list_html_files_js_ready = {} list_html_files_js_ready_end = {} for each_widget_type in widget_types_on_dashboard: file_html_head = "widget_template_{}_head.html".format( each_widget_type) path_html_head = os.path.join(PATH_HTML_USER, file_html_head) if os.path.exists(path_html_head): list_html_files_head[each_widget_type] = file_html_head file_html_title_bar = "widget_template_{}_title_bar.html".format( each_widget_type) path_html_title_bar = os.path.join(PATH_HTML_USER, file_html_title_bar) if os.path.exists(path_html_title_bar): list_html_files_title_bar[each_widget_type] = file_html_title_bar file_html_body = "widget_template_{}_body.html".format( each_widget_type) path_html_body = os.path.join(PATH_HTML_USER, file_html_body) if os.path.exists(path_html_body): list_html_files_body[each_widget_type] = file_html_body file_html_configure_options = "widget_template_{}_configure_options.html".format( each_widget_type) path_html_configure_options = os.path.join( PATH_HTML_USER, file_html_configure_options) if os.path.exists(path_html_configure_options): list_html_files_configure_options[ each_widget_type] = file_html_configure_options file_html_js = "widget_template_{}_js.html".format(each_widget_type) path_html_js = os.path.join(PATH_HTML_USER, file_html_js) if os.path.exists(path_html_js): list_html_files_js[each_widget_type] = file_html_js file_html_js_ready = "widget_template_{}_js_ready.html".format( each_widget_type) path_html_js_ready = os.path.join(PATH_HTML_USER, file_html_js_ready) if os.path.exists(path_html_js_ready): list_html_files_js_ready[each_widget_type] = file_html_js_ready file_html_js_ready_end = "widget_template_{}_js_ready_end.html".format( each_widget_type) path_html_js_ready_end = os.path.join(PATH_HTML_USER, file_html_js_ready_end) if os.path.exists(path_html_js_ready_end): list_html_files_js_ready_end[ each_widget_type] = file_html_js_ready_end # Retrieve all choices to populate form drop-down menu choices_camera = utils_general.choices_id_name(camera) choices_function = utils_general.choices_functions(function, dict_units, dict_measurements) choices_input = utils_general.choices_inputs(input_dev, dict_units, dict_measurements) choices_math = utils_general.choices_maths(math, dict_units, dict_measurements) choices_method = utils_general.choices_methods(method) choices_output = utils_general.choices_outputs(output, dict_units, dict_measurements) choices_output_channels_measurements = utils_general.choices_outputs_channels_measurements( output, OutputChannel, dict_outputs, dict_units, dict_measurements) choices_output_pwm = utils_general.choices_outputs_pwm( output, dict_units, dict_measurements, dict_outputs) choices_pid = utils_general.choices_pids(pid, dict_units, dict_measurements) choices_pid_devices = utils_general.choices_pids_devices(pid) choices_tag = utils_general.choices_tags(tags) device_measurements_dict = {} for meas in device_measurements: device_measurements_dict[meas.unique_id] = meas # Get what each measurement uses for a unit use_unit = utils_general.use_unit_generate(device_measurements, input_dev, output, math, function) return render_template( 'pages/dashboard.html', conditional=conditional, custom_options_values_output_channels= custom_options_values_output_channels, custom_options_values_widgets=custom_options_values_widgets, custom_widget_variables=custom_widget_variables, table_conversion=Conversion, table_function=CustomController, table_widget=Widget, table_input=Input, table_math=Math, table_output=Output, table_pid=PID, table_device_measurements=DeviceMeasurements, choices_camera=choices_camera, choices_function=choices_function, choices_input=choices_input, choices_math=choices_math, choices_method=choices_method, choices_output=choices_output, choices_output_channels_measurements= choices_output_channels_measurements, choices_output_pwm=choices_output_pwm, choices_pid=choices_pid, choices_pid_devices=choices_pid_devices, choices_tag=choices_tag, dashboard_id=dashboard_id, device_measurements_dict=device_measurements_dict, dict_measure_measurements=dict_measure_measurements, dict_measure_units=dict_measure_units, dict_measurements=dict_measurements, dict_units=dict_units, dict_widgets=dict_widgets, list_html_files_head=list_html_files_head, list_html_files_title_bar=list_html_files_title_bar, list_html_files_body=list_html_files_body, list_html_files_configure_options=list_html_files_configure_options, list_html_files_js=list_html_files_js, list_html_files_js_ready=list_html_files_js_ready, list_html_files_js_ready_end=list_html_files_js_ready_end, camera=camera, function=function, math=math, misc=misc, pid=pid, output=output, output_types=output_types(), input=input_dev, tags=tags, this_dashboard=this_dashboard, use_unit=use_unit, form_base=form_base, form_dashboard=form_dashboard, widget=widget)
def settings_measurement(): """ Display measurement settings """ if not utils_general.user_has_permission('view_settings'): return redirect(url_for('routes_general.home')) measurement = Measurement.query.all() unit = Unit.query.all() conversion = Conversion.query.all() form_add_measurement = forms_settings.MeasurementAdd() form_mod_measurement = forms_settings.MeasurementMod() form_add_unit = forms_settings.UnitAdd() form_mod_unit = forms_settings.UnitMod() form_add_conversion = forms_settings.ConversionAdd() form_mod_conversion = forms_settings.ConversionMod() choices_units = utils_general.choices_units(unit) # Generate all measurement and units used dict_measurements = add_custom_measurements(measurement) dict_units = add_custom_units(unit) if request.method == 'POST': if not utils_general.user_has_permission('edit_controllers'): return redirect(url_for('routes_general.home')) if form_add_measurement.add_measurement.data: utils_settings.settings_measurement_add(form_add_measurement) elif form_mod_measurement.save_measurement.data: utils_settings.settings_measurement_mod(form_mod_measurement) elif form_mod_measurement.delete_measurement.data: utils_settings.settings_measurement_del(form_mod_measurement.measurement_id.data) elif form_add_unit.add_unit.data: utils_settings.settings_unit_add(form_add_unit) elif form_mod_unit.save_unit.data: utils_settings.settings_unit_mod(form_mod_unit) elif form_mod_unit.delete_unit.data: utils_settings.settings_unit_del(form_mod_unit.unit_id.data) elif form_add_conversion.add_conversion.data: utils_settings.settings_convert_add(form_add_conversion) elif form_mod_conversion.save_conversion.data: utils_settings.settings_convert_mod(form_mod_conversion) elif form_mod_conversion.delete_conversion.data: utils_settings.settings_convert_del(form_mod_conversion.conversion_id.data) return redirect(url_for('routes_settings.settings_measurement')) return render_template('settings/measurement.html', dict_measurements=dict_measurements, dict_units=dict_units, choices_units=choices_units, measurement=measurement, unit=unit, conversion=conversion, form_add_measurement=form_add_measurement, form_mod_measurement=form_mod_measurement, form_add_unit=form_add_unit, form_mod_unit=form_mod_unit, form_add_conversion=form_add_conversion, form_mod_conversion=form_mod_conversion)
def page_function(): """ Display Function page options """ function_type = request.args.get('function_type', None) function_id = request.args.get('function_id', None) action_id = request.args.get('action_id', None) condition_id = request.args.get('condition_id', None) each_function = None each_action = None each_condition = None function_page_entry = None function_page_options = None if function_type in ['entry', 'options', 'actions'] and function_id != '0': controller_type = determine_controller_type(function_id) if controller_type == "Conditional": each_function = Conditional.query.filter( Conditional.unique_id == function_id).first() function_page_entry = 'pages/function_options/conditional_entry.html' function_page_options = 'pages/function_options/conditional_options.html' elif controller_type == "PID": each_function = PID.query.filter( PID.unique_id == function_id).first() function_page_entry = 'pages/function_options/pid_entry.html' function_page_options = 'pages/function_options/pid_options.html' elif controller_type == "Trigger": each_function = Trigger.query.filter( Trigger.unique_id == function_id).first() function_page_entry = 'pages/function_options/trigger_entry.html' function_page_options = 'pages/function_options/trigger_options.html' elif controller_type == "Function": each_function = Function.query.filter( Function.unique_id == function_id).first() function_page_entry = 'pages/function_options/function_entry.html' function_page_options = 'pages/function_options/function_options.html' elif controller_type == "Function_Custom": each_function = CustomController.query.filter( CustomController.unique_id == function_id).first() function_page_entry = 'pages/function_options/custom_function_entry.html' function_page_options = 'pages/function_options/custom_function_options.html' if function_type == 'actions': if action_id: each_action = Actions.query.filter( Actions.unique_id == action_id).first() if function_type == 'conditions': if condition_id: each_condition = ConditionalConditions.query.filter( ConditionalConditions.unique_id == condition_id).first() camera = Camera.query.all() conditional = Conditional.query.all() conditional_conditions = ConditionalConditions.query.all() function = CustomController.query.all() function_channel = FunctionChannel.query.all() function_dev = Function.query.all() actions = Actions.query.all() input_dev = Input.query.all() lcd = LCD.query.all() math = Math.query.all() measurement = Measurement.query.all() method = Method.query.all() tags = NoteTags.query.all() output = Output.query.all() output_channel = OutputChannel.query.all() pid = PID.query.all() trigger = Trigger.query.all() unit = Unit.query.all() user = User.query.all() display_order_function = csv_to_list_of_str( DisplayOrder.query.first().function) form_add_function = forms_function.FunctionAdd() form_mod_measurement = forms_measurement.MeasurementMod() form_mod_pid_base = forms_pid.PIDModBase() form_mod_pid_output_raise = forms_pid.PIDModRelayRaise() form_mod_pid_output_lower = forms_pid.PIDModRelayLower() form_mod_pid_pwm_raise = forms_pid.PIDModPWMRaise() form_mod_pid_pwm_lower = forms_pid.PIDModPWMLower() form_mod_pid_value_raise = forms_pid.PIDModValueRaise() form_mod_pid_value_lower = forms_pid.PIDModValueLower() form_mod_pid_volume_raise = forms_pid.PIDModVolumeRaise() form_mod_pid_volume_lower = forms_pid.PIDModVolumeLower() form_function_base = forms_function.FunctionMod() form_trigger = forms_trigger.Trigger() form_conditional = forms_conditional.Conditional() form_conditional_conditions = forms_conditional.ConditionalConditions() form_function = forms_custom_controller.CustomController() form_actions = forms_function.Actions() dict_controllers = parse_function_information() # Generate all measurement and units used dict_measurements = add_custom_measurements(Measurement.query.all()) dict_units = add_custom_units(Unit.query.all()) dict_outputs = parse_output_information() custom_options_values_controllers = parse_custom_option_values( function, dict_controller=dict_controllers) custom_options_values_function_channels = parse_custom_option_values_function_channels_json( function_channel, dict_controller=function, key_name='custom_channel_options') # TODO: Update actions to use single-file modules and be consistent with other custom_options custom_options_values_actions = {} for each_action in actions: try: custom_options_values_actions[each_action.unique_id] = json.loads( each_action.custom_options) except: custom_options_values_actions[each_action.unique_id] = {} # Create lists of built-in and custom functions choices_functions = [] for choice_function in FUNCTIONS: choices_functions.append({ 'value': choice_function[0], 'item': choice_function[1] }) choices_custom_functions = utils_general.choices_custom_functions() # Combine function lists choices_functions_add = choices_functions + choices_custom_functions # Sort combined list choices_functions_add = sorted(choices_functions_add, key=lambda i: i['item']) custom_actions = {} for choice_function in function: if 'custom_actions' in dict_controllers[choice_function.device]: custom_actions[choice_function.device] = True choices_function = utils_general.choices_functions(function, dict_units, dict_measurements) choices_input = utils_general.choices_inputs(input_dev, dict_units, dict_measurements) choices_input_devices = utils_general.choices_input_devices(input_dev) choices_math = utils_general.choices_maths(math, dict_units, dict_measurements) choices_method = utils_general.choices_methods(method) choices_output = utils_general.choices_outputs(output, dict_units, dict_measurements) choices_output_channels = utils_general.choices_outputs_channels( output, output_channel, dict_outputs) choices_output_channels_measurements = utils_general.choices_outputs_channels_measurements( output, OutputChannel, dict_outputs, dict_units, dict_measurements) choices_pid = utils_general.choices_pids(pid, dict_units, dict_measurements) choices_measurements_units = utils_general.choices_measurements_units( measurement, unit) choices_controller_ids = utils_general.choices_controller_ids() actions_dict = {'conditional': {}, 'trigger': {}} for each_action in actions: if (each_action.function_type == 'conditional' and each_action.unique_id not in actions_dict['conditional']): actions_dict['conditional'][each_action.function_id] = True if (each_action.function_type == 'trigger' and each_action.unique_id not in actions_dict['trigger']): actions_dict['trigger'][each_action.function_id] = True conditions_dict = {} for each_cond in conditional_conditions: if each_cond.unique_id not in conditions_dict: conditions_dict[each_cond.conditional_id] = True controllers = [] controllers_all = [('Input', input_dev), ('Conditional', conditional), ('Function', function), ('LCD', lcd), ('Math', math), ('PID', pid), ('Trigger', trigger)] for each_controller in controllers_all: for each_cont in each_controller[1]: controllers.append((each_controller[0], each_cont.unique_id, each_cont.id, each_cont.name)) # Create dict of Function names names_function = {} all_elements = [conditional, pid, trigger, function_dev, function] for each_element in all_elements: for each_func_name in each_element: names_function[each_func_name.unique_id] = '[{id}] {name}'.format( id=each_func_name.unique_id.split('-')[0], name=each_func_name.name) # Calculate sunrise/sunset times if conditional controller is set up properly sunrise_set_calc = {} for each_trigger in trigger: if each_trigger.trigger_type == 'trigger_sunrise_sunset': sunrise_set_calc[each_trigger.unique_id] = {} try: sun = Sun(latitude=each_trigger.latitude, longitude=each_trigger.longitude, zenith=each_trigger.zenith) sunrise = sun.get_sunrise_time()['time_local'] sunset = sun.get_sunset_time()['time_local'] # Adjust for date offset new_date = datetime.datetime.now() + datetime.timedelta( days=each_trigger.date_offset_days) sun = Sun(latitude=each_trigger.latitude, longitude=each_trigger.longitude, zenith=each_trigger.zenith, day=new_date.day, month=new_date.month, year=new_date.year, offset_minutes=each_trigger.time_offset_minutes) offset_rise = sun.get_sunrise_time()['time_local'] offset_set = sun.get_sunset_time()['time_local'] sunrise_set_calc[each_trigger.unique_id]['sunrise'] = ( sunrise.strftime("%Y-%m-%d %H:%M")) sunrise_set_calc[each_trigger.unique_id]['sunset'] = ( sunset.strftime("%Y-%m-%d %H:%M")) sunrise_set_calc[each_trigger.unique_id]['offset_sunrise'] = ( offset_rise.strftime("%Y-%m-%d %H:%M")) sunrise_set_calc[each_trigger.unique_id]['offset_sunset'] = ( offset_set.strftime("%Y-%m-%d %H:%M")) except: logger.exception(1) sunrise_set_calc[each_trigger.unique_id]['sunrise'] = None sunrise_set_calc[each_trigger.unique_id]['sunrise'] = None sunrise_set_calc[ each_trigger.unique_id]['offset_sunrise'] = None sunrise_set_calc[ each_trigger.unique_id]['offset_sunset'] = None if not function_type: return render_template( 'pages/function.html', and_=and_, actions=actions, actions_dict=actions_dict, camera=camera, choices_controller_ids=choices_controller_ids, choices_custom_functions=choices_custom_functions, choices_function=choices_function, choices_functions=choices_functions, choices_functions_add=choices_functions_add, choices_input=choices_input, choices_input_devices=choices_input_devices, choices_math=choices_math, choices_measurements_units=choices_measurements_units, choices_method=choices_method, choices_output=choices_output, choices_output_channels=choices_output_channels, choices_output_channels_measurements= choices_output_channels_measurements, choices_pid=choices_pid, conditional_conditions_list=CONDITIONAL_CONDITIONS, conditional=conditional, conditional_conditions=conditional_conditions, conditions_dict=conditions_dict, controllers=controllers, function=function, function_channel=function_channel, custom_actions=custom_actions, custom_options_values_actions=custom_options_values_actions, custom_options_values_controllers=custom_options_values_controllers, custom_options_values_function_channels= custom_options_values_function_channels, dict_controllers=dict_controllers, dict_measurements=dict_measurements, dict_outputs=dict_outputs, dict_units=dict_units, display_order_function=display_order_function, form_conditional=form_conditional, form_conditional_conditions=form_conditional_conditions, form_function=form_function, form_actions=form_actions, form_add_function=form_add_function, form_function_base=form_function_base, form_mod_measurement=form_mod_measurement, form_mod_pid_base=form_mod_pid_base, form_mod_pid_pwm_raise=form_mod_pid_pwm_raise, form_mod_pid_pwm_lower=form_mod_pid_pwm_lower, form_mod_pid_output_raise=form_mod_pid_output_raise, form_mod_pid_output_lower=form_mod_pid_output_lower, form_mod_pid_value_raise=form_mod_pid_value_raise, form_mod_pid_value_lower=form_mod_pid_value_lower, form_mod_pid_volume_raise=form_mod_pid_volume_raise, form_mod_pid_volume_lower=form_mod_pid_volume_lower, form_trigger=form_trigger, function_action_info=FUNCTION_ACTION_INFO, function_dev=function_dev, function_types=FUNCTIONS, input=input_dev, lcd=lcd, math=math, method=method, names_function=names_function, output=output, output_types=output_types(), pid=pid, sunrise_set_calc=sunrise_set_calc, table_conversion=Conversion, table_device_measurements=DeviceMeasurements, table_input=Input, table_output=Output, tags=tags, trigger=trigger, units=MEASUREMENTS, user=user) elif function_type == 'entry': return render_template( function_page_entry, and_=and_, actions=actions, actions_dict=actions_dict, camera=camera, choices_controller_ids=choices_controller_ids, choices_custom_functions=choices_custom_functions, choices_function=choices_function, choices_functions=choices_functions, choices_functions_add=choices_functions_add, choices_input=choices_input, choices_input_devices=choices_input_devices, choices_math=choices_math, choices_measurements_units=choices_measurements_units, choices_method=choices_method, choices_output=choices_output, choices_output_channels=choices_output_channels, choices_output_channels_measurements= choices_output_channels_measurements, choices_pid=choices_pid, conditional_conditions_list=CONDITIONAL_CONDITIONS, conditional=conditional, conditional_conditions=conditional_conditions, conditions_dict=conditions_dict, controllers=controllers, function=function, function_channel=function_channel, custom_actions=custom_actions, custom_options_values_actions=custom_options_values_actions, custom_options_values_controllers=custom_options_values_controllers, custom_options_values_function_channels= custom_options_values_function_channels, dict_controllers=dict_controllers, dict_measurements=dict_measurements, dict_outputs=dict_outputs, dict_units=dict_units, display_order_function=display_order_function, each_function=each_function, form_conditional=form_conditional, form_conditional_conditions=form_conditional_conditions, form_function=form_function, form_actions=form_actions, form_add_function=form_add_function, form_function_base=form_function_base, form_mod_measurement=form_mod_measurement, form_mod_pid_base=form_mod_pid_base, form_mod_pid_pwm_raise=form_mod_pid_pwm_raise, form_mod_pid_pwm_lower=form_mod_pid_pwm_lower, form_mod_pid_output_raise=form_mod_pid_output_raise, form_mod_pid_output_lower=form_mod_pid_output_lower, form_mod_pid_value_raise=form_mod_pid_value_raise, form_mod_pid_value_lower=form_mod_pid_value_lower, form_mod_pid_volume_raise=form_mod_pid_volume_raise, form_mod_pid_volume_lower=form_mod_pid_volume_lower, form_trigger=form_trigger, function_action_info=FUNCTION_ACTION_INFO, function_dev=function_dev, function_types=FUNCTIONS, input=input_dev, lcd=lcd, math=math, method=method, names_function=names_function, output=output, output_types=output_types(), pid=pid, sunrise_set_calc=sunrise_set_calc, table_conversion=Conversion, table_device_measurements=DeviceMeasurements, table_input=Input, table_output=Output, tags=tags, trigger=trigger, units=MEASUREMENTS, user=user) elif function_type == 'options': return render_template( function_page_options, and_=and_, actions=actions, actions_dict=actions_dict, camera=camera, choices_controller_ids=choices_controller_ids, choices_custom_functions=choices_custom_functions, choices_function=choices_function, choices_functions=choices_functions, choices_functions_add=choices_functions_add, choices_input=choices_input, choices_input_devices=choices_input_devices, choices_math=choices_math, choices_measurements_units=choices_measurements_units, choices_method=choices_method, choices_output=choices_output, choices_output_channels=choices_output_channels, choices_output_channels_measurements= choices_output_channels_measurements, choices_pid=choices_pid, conditional_conditions_list=CONDITIONAL_CONDITIONS, conditional=conditional, conditional_conditions=conditional_conditions, conditions_dict=conditions_dict, controllers=controllers, each_function=each_function, function=function, function_channel=function_channel, custom_actions=custom_actions, custom_options_values_actions=custom_options_values_actions, custom_options_values_controllers=custom_options_values_controllers, custom_options_values_function_channels= custom_options_values_function_channels, dict_controllers=dict_controllers, dict_measurements=dict_measurements, dict_outputs=dict_outputs, dict_units=dict_units, display_order_function=display_order_function, form_conditional=form_conditional, form_conditional_conditions=form_conditional_conditions, form_function=form_function, form_actions=form_actions, form_add_function=form_add_function, form_function_base=form_function_base, form_mod_measurement=form_mod_measurement, form_mod_pid_base=form_mod_pid_base, form_mod_pid_pwm_raise=form_mod_pid_pwm_raise, form_mod_pid_pwm_lower=form_mod_pid_pwm_lower, form_mod_pid_output_raise=form_mod_pid_output_raise, form_mod_pid_output_lower=form_mod_pid_output_lower, form_mod_pid_value_raise=form_mod_pid_value_raise, form_mod_pid_value_lower=form_mod_pid_value_lower, form_mod_pid_volume_raise=form_mod_pid_volume_raise, form_mod_pid_volume_lower=form_mod_pid_volume_lower, form_trigger=form_trigger, function_action_info=FUNCTION_ACTION_INFO, function_dev=function_dev, function_types=FUNCTIONS, input=input_dev, lcd=lcd, math=math, method=method, names_function=names_function, output=output, output_types=output_types(), pid=pid, sunrise_set_calc=sunrise_set_calc, table_conversion=Conversion, table_device_measurements=DeviceMeasurements, table_input=Input, table_output=Output, tags=tags, trigger=trigger, units=MEASUREMENTS, user=user) elif function_type == 'actions': return render_template( 'pages/function_options/actions.html', and_=and_, actions=actions, actions_dict=actions_dict, camera=camera, choices_controller_ids=choices_controller_ids, choices_custom_functions=choices_custom_functions, choices_function=choices_function, choices_functions=choices_functions, choices_functions_add=choices_functions_add, choices_input=choices_input, choices_input_devices=choices_input_devices, choices_math=choices_math, choices_measurements_units=choices_measurements_units, choices_method=choices_method, choices_output=choices_output, choices_output_channels=choices_output_channels, choices_output_channels_measurements= choices_output_channels_measurements, choices_pid=choices_pid, conditional_conditions_list=CONDITIONAL_CONDITIONS, conditional=conditional, conditional_conditions=conditional_conditions, conditions_dict=conditions_dict, controllers=controllers, each_action=each_action, each_function=each_function, function=function, function_channel=function_channel, custom_actions=custom_actions, custom_options_values_actions=custom_options_values_actions, custom_options_values_controllers=custom_options_values_controllers, custom_options_values_function_channels= custom_options_values_function_channels, dict_controllers=dict_controllers, dict_measurements=dict_measurements, dict_outputs=dict_outputs, dict_units=dict_units, display_order_function=display_order_function, form_conditional=form_conditional, form_conditional_conditions=form_conditional_conditions, form_function=form_function, form_actions=form_actions, form_add_function=form_add_function, form_function_base=form_function_base, form_mod_measurement=form_mod_measurement, form_mod_pid_base=form_mod_pid_base, form_mod_pid_pwm_raise=form_mod_pid_pwm_raise, form_mod_pid_pwm_lower=form_mod_pid_pwm_lower, form_mod_pid_output_raise=form_mod_pid_output_raise, form_mod_pid_output_lower=form_mod_pid_output_lower, form_mod_pid_value_raise=form_mod_pid_value_raise, form_mod_pid_value_lower=form_mod_pid_value_lower, form_mod_pid_volume_raise=form_mod_pid_volume_raise, form_mod_pid_volume_lower=form_mod_pid_volume_lower, form_trigger=form_trigger, function_action_info=FUNCTION_ACTION_INFO, function_dev=function_dev, function_types=FUNCTIONS, input=input_dev, lcd=lcd, math=math, method=method, names_function=names_function, output=output, output_types=output_types(), pid=pid, sunrise_set_calc=sunrise_set_calc, table_conversion=Conversion, table_device_measurements=DeviceMeasurements, table_input=Input, table_output=Output, tags=tags, trigger=trigger, units=MEASUREMENTS, user=user) elif function_type == 'conditions': return render_template( 'pages/function_options/conditional_condition.html', and_=and_, actions=actions, actions_dict=actions_dict, camera=camera, choices_controller_ids=choices_controller_ids, choices_custom_functions=choices_custom_functions, choices_function=choices_function, choices_functions=choices_functions, choices_functions_add=choices_functions_add, choices_input=choices_input, choices_input_devices=choices_input_devices, choices_math=choices_math, choices_measurements_units=choices_measurements_units, choices_method=choices_method, choices_output=choices_output, choices_output_channels=choices_output_channels, choices_output_channels_measurements= choices_output_channels_measurements, choices_pid=choices_pid, conditional_conditions_list=CONDITIONAL_CONDITIONS, conditional=conditional, conditional_conditions=conditional_conditions, conditions_dict=conditions_dict, controllers=controllers, each_action=each_action, each_condition=each_condition, each_function=each_function, function=function, function_channel=function_channel, custom_actions=custom_actions, custom_options_values_actions=custom_options_values_actions, custom_options_values_controllers=custom_options_values_controllers, custom_options_values_function_channels= custom_options_values_function_channels, dict_controllers=dict_controllers, dict_measurements=dict_measurements, dict_outputs=dict_outputs, dict_units=dict_units, display_order_function=display_order_function, form_conditional=form_conditional, form_conditional_conditions=form_conditional_conditions, form_function=form_function, form_actions=form_actions, form_add_function=form_add_function, form_function_base=form_function_base, form_mod_measurement=form_mod_measurement, form_mod_pid_base=form_mod_pid_base, form_mod_pid_pwm_raise=form_mod_pid_pwm_raise, form_mod_pid_pwm_lower=form_mod_pid_pwm_lower, form_mod_pid_output_raise=form_mod_pid_output_raise, form_mod_pid_output_lower=form_mod_pid_output_lower, form_mod_pid_value_raise=form_mod_pid_value_raise, form_mod_pid_value_lower=form_mod_pid_value_lower, form_mod_pid_volume_raise=form_mod_pid_volume_raise, form_mod_pid_volume_lower=form_mod_pid_volume_lower, form_trigger=form_trigger, function_action_info=FUNCTION_ACTION_INFO, function_dev=function_dev, function_types=FUNCTIONS, input=input_dev, lcd=lcd, math=math, method=method, names_function=names_function, output=output, output_types=output_types(), pid=pid, sunrise_set_calc=sunrise_set_calc, table_conversion=Conversion, table_device_measurements=DeviceMeasurements, table_input=Input, table_output=Output, tags=tags, trigger=trigger, units=MEASUREMENTS, user=user) else: return "Could not determine template"
def form_input_choices(choices, each_input, dict_inputs): dict_measurements = add_custom_measurements(Measurement.query.all()) dict_units = add_custom_units(Unit.query.all()) if each_input.device in dict_inputs: is_adc = False if ('analog_to_digital_converter' in dict_inputs[each_input.device] and dict_inputs[each_input.device]['analog_to_digital_converter']): is_adc = True if ('measurements_list' in dict_inputs[each_input.device] and dict_inputs[each_input.device]['measurements_list'] and dict_inputs[each_input.device]['measurements_list'] != 'LinuxCommand' and not is_adc ): for each_measure in dict_inputs[each_input.device]['measurements_list']: value = '{id},{meas}'.format( id=each_input.unique_id, meas=each_measure) try: custom_dict_measurements = {} for each_measurement in each_input.convert_to_unit.split(';'): custom_dict_measurements[each_measurement.split(',')[0]] = each_measurement.split(',')[1] measure_display, unit_display = check_display_names( each_measure, custom_dict_measurements[each_measure]) if unit_display: display = '[Input {id:02d}] {name} ({meas}, {unit})'.format( id=each_input.id, name=each_input.name, meas=measure_display, unit=unit_display) else: display = '[Input {id:02d}] {name} ({meas})'.format( id=each_input.id, name=each_input.name, meas=measure_display) choices.update({value: display}) except: logger.exception("Generating input choices") # Linux Command Input if (each_input.device == 'LinuxCommand' and each_input.convert_to_unit != ''): value = '{id},{meas}'.format( id=each_input.unique_id, meas=each_input.convert_to_unit.split(',')[0]) display = '[Input {id:02d}] {name} ({meas}, {unit})'.format( id=each_input.id, name=each_input.name, meas=dict_measurements[each_input.convert_to_unit.split(',')[0]]['name'], unit=dict_units[each_input.convert_to_unit.split(',')[1]]['unit']) choices.update({value: display}) # ADC if ('analog_to_digital_converter' in dict_inputs[each_input.device] and dict_inputs[each_input.device]['analog_to_digital_converter'] and each_input.convert_to_unit != ''): value = '{id},voltage'.format( id=each_input.unique_id) display = '[Input {id:02d}] {name} (Voltage, volts)'.format( id=each_input.id, name=each_input.name) choices.update({value: display}) value = '{id},{meas}'.format( id=each_input.unique_id, meas=each_input.convert_to_unit.split(',')[0]) display = '[Input {id:02d}] {name} ({meas}, {unit})'.format( id=each_input.id, name=each_input.name, meas=dict_measurements[each_input.convert_to_unit.split(',')[0]]['name'], unit=dict_units[each_input.convert_to_unit.split(',')[1]]['unit']) choices.update({value: display}) return choices
input_data['dependencies_module']) else: # Only one set of dependencies inputs_info[name_str] = input_data if 'dependencies_module' in input_data: inputs_info[name_str]['dependencies_module'] = [ input_data['dependencies_module'] ] # turn into list inputs_info = dict( OrderedDict(sorted(inputs_info.items(), key=lambda t: t[0]))) with session_scope(MYCODO_DB_PATH) as new_session: dict_measurements = add_custom_measurements( new_session.query(Measurement).all()) dict_units = add_custom_units(new_session.query(Unit).all()) dict_inputs = {} for name, data in inputs_info.items(): if 'measurements_dict' not in data: continue for channel, measure in data['measurements_dict'].items(): if measure["measurement"]: if measure["measurement"] not in dict_inputs: dict_inputs[measure["measurement"]] = {} dict_inputs[measure["measurement"]][name] = data dict_inputs = dict( OrderedDict(sorted(dict_inputs.items(), key=lambda t: t[0])))
def page_input(): """Display Data page options.""" input_type = request.args.get('input_type', None) input_id = request.args.get('input_id', None) action_id = request.args.get('action_id', None) each_input = None each_action = None if input_type in ['entry', 'options', 'actions']: each_input = Input.query.filter(Input.unique_id == input_id).first() if input_type == 'actions' and action_id: each_action = Actions.query.filter( Actions.unique_id == action_id).first() action = Actions.query.all() function = CustomController.query.all() input_dev = Input.query.all() input_channel = InputChannel.query.all() method = Method.query.all() measurement = Measurement.query.all() output = Output.query.all() output_channel = OutputChannel.query.all() pid = PID.query.all() user = User.query.all() unit = Unit.query.all() display_order_input = csv_to_list_of_str(DisplayOrder.query.first().inputs) form_add_input = forms_input.InputAdd() form_mod_input = forms_input.InputMod() form_actions = forms_action.Actions() dict_inputs = parse_input_information() dict_actions = parse_action_information() custom_options_values_inputs = parse_custom_option_values( input_dev, dict_controller=dict_inputs) custom_options_values_input_channels = parse_custom_option_values_input_channels_json( input_channel, dict_controller=dict_inputs, key_name='custom_channel_options') custom_options_values_actions = {} for each_action_dev in action: try: custom_options_values_actions[each_action_dev.unique_id] = json.loads(each_action_dev.custom_options) except: custom_options_values_actions[each_action_dev.unique_id] = {} custom_commands = {} for each_input_dev in input_dev: if each_input_dev.device in dict_inputs and 'custom_commands' in dict_inputs[each_input_dev.device]: custom_commands[each_input_dev.device] = True # Generate dict that incorporate user-added measurements/units dict_outputs = parse_output_information() dict_units = add_custom_units(unit) dict_measurements = add_custom_measurements(measurement) # Generate Action dropdown for use with Inputs choices_actions = [] list_actions_sorted = generate_form_action_list(dict_actions, application=["inputs"]) for name in list_actions_sorted: choices_actions.append((name, dict_actions[name]['name'])) # Create list of choices to be used in dropdown menus choices_function = utils_general.choices_functions( function, dict_units, dict_measurements) choices_input = utils_general.choices_inputs( input_dev, dict_units, dict_measurements) choices_method = utils_general.choices_methods(method) choices_output = utils_general.choices_outputs( output, OutputChannel, dict_outputs, dict_units, dict_measurements) choices_output_channels = utils_general.choices_outputs_channels( output, output_channel, dict_outputs) choices_output_channels_measurements = utils_general.choices_outputs_channels_measurements( output, OutputChannel, dict_outputs, dict_units, dict_measurements) choices_pid = utils_general.choices_pids( pid, dict_units, dict_measurements) choices_pid_devices = utils_general.choices_pids_devices(pid) choices_unit = utils_general.choices_units(unit) choices_measurement = utils_general.choices_measurements(measurement) choices_measurements_units = utils_general.choices_measurements_units(measurement, unit) # Create dict of Input names names_input = {} all_elements = input_dev for each_element in all_elements: names_input[each_element.unique_id] = '[{id:02d}] ({uid}) {name}'.format( id=each_element.id, uid=each_element.unique_id.split('-')[0], name=each_element.name) # Create list of file names from the input_options directory # Used in generating the correct options for each input controller input_templates = [] input_path = os.path.join( INSTALL_DIRECTORY, 'mycodo/mycodo_flask/templates/pages/data_options/input_options') for (_, _, file_names) in os.walk(input_path): input_templates.extend(file_names) break # Compile a list of 1-wire devices devices_1wire = [] if os.path.isdir(PATH_1WIRE): for each_name in os.listdir(PATH_1WIRE): if 'bus' not in each_name and '-' in each_name: devices_1wire.append( {'name': each_name, 'value': each_name.split('-')[1]} ) # Compile a list of 1-wire devices (using ow-shell) devices_1wire_ow_shell = [] if not Input.query.filter(Input.device == "DS18B20_OWS").count(): pass elif current_app.config['TESTING']: logger.debug("Testing: Skipping testing for 'ow-shell'") elif not dpkg_package_exists('ow-shell'): logger.debug("Package 'ow-shell' not found") else: logger.debug("Package 'ow-shell' found") try: test_cmd = subprocess.check_output(['owdir']).splitlines() for each_ow in test_cmd: str_ow = re.sub("\ |\/|\'", "", each_ow.decode("utf-8")) # Strip / and ' if '.' in str_ow and len(str_ow) == 15: devices_1wire_ow_shell.append(str_ow) except Exception: logger.error("Error finding 1-wire devices with 'owdir'") # Find FTDI devices ftdi_devices = [] if not current_app.config['TESTING']: for each_input_dev in input_dev: if each_input_dev.interface == "FTDI": from mycodo.devices.atlas_scientific_ftdi import get_ftdi_device_list ftdi_devices = get_ftdi_device_list() break if not input_type: return render_template('pages/input.html', and_=and_, action=action, choices_actions=choices_actions, choices_function=choices_function, choices_input=choices_input, choices_output=choices_output, choices_measurement=choices_measurement, choices_measurements_units=choices_measurements_units, choices_method=choices_method, choices_output_channels=choices_output_channels, choices_output_channels_measurements=choices_output_channels_measurements, choices_pid=choices_pid, choices_pid_devices=choices_pid_devices, choices_unit=choices_unit, custom_commands=custom_commands, custom_options_values_actions=custom_options_values_actions, custom_options_values_inputs=custom_options_values_inputs, custom_options_values_input_channels=custom_options_values_input_channels, dict_actions=dict_actions, dict_inputs=dict_inputs, dict_measurements=dict_measurements, dict_units=dict_units, display_order_input=display_order_input, form_actions=form_actions, form_add_input=form_add_input, form_mod_input=form_mod_input, ftdi_devices=ftdi_devices, input_channel=input_channel, input_templates=input_templates, names_input=names_input, output=output, output_types=output_types(), pid=pid, table_conversion=Conversion, table_device_measurements=DeviceMeasurements, table_input=Input, user=user, devices_1wire_ow_shell=devices_1wire_ow_shell, devices_1wire=devices_1wire) elif input_type == 'entry': return render_template('pages/data_options/input_entry.html', and_=and_, action=action, choices_actions=choices_actions, choices_function=choices_function, choices_input=choices_input, choices_output=choices_output, choices_measurement=choices_measurement, choices_measurements_units=choices_measurements_units, choices_method=choices_method, choices_output_channels=choices_output_channels, choices_output_channels_measurements=choices_output_channels_measurements, choices_pid=choices_pid, choices_pid_devices=choices_pid_devices, choices_unit=choices_unit, custom_commands=custom_commands, custom_options_values_actions=custom_options_values_actions, custom_options_values_inputs=custom_options_values_inputs, custom_options_values_input_channels=custom_options_values_input_channels, dict_actions=dict_actions, dict_inputs=dict_inputs, dict_measurements=dict_measurements, dict_units=dict_units, display_order_input=display_order_input, each_input=each_input, form_actions=form_actions, form_add_input=form_add_input, form_mod_input=form_mod_input, ftdi_devices=ftdi_devices, input_channel=input_channel, input_templates=input_templates, names_input=names_input, output=output, output_types=output_types(), pid=pid, table_conversion=Conversion, table_device_measurements=DeviceMeasurements, table_input=Input, user=user, devices_1wire_ow_shell=devices_1wire_ow_shell, devices_1wire=devices_1wire) elif input_type == 'options': return render_template('pages/data_options/input_options.html', and_=and_, action=action, choices_actions=choices_actions, choices_function=choices_function, choices_input=choices_input, choices_output=choices_output, choices_measurement=choices_measurement, choices_measurements_units=choices_measurements_units, choices_method=choices_method, choices_output_channels=choices_output_channels, choices_output_channels_measurements=choices_output_channels_measurements, choices_pid=choices_pid, choices_pid_devices=choices_pid_devices, choices_unit=choices_unit, custom_commands=custom_commands, custom_options_values_actions=custom_options_values_actions, custom_options_values_inputs=custom_options_values_inputs, custom_options_values_input_channels=custom_options_values_input_channels, dict_actions=dict_actions, dict_inputs=dict_inputs, dict_measurements=dict_measurements, dict_units=dict_units, display_order_input=display_order_input, each_input=each_input, form_actions=form_actions, form_add_input=form_add_input, form_mod_input=form_mod_input, ftdi_devices=ftdi_devices, input_channel=input_channel, input_templates=input_templates, names_input=names_input, output=output, output_types=output_types(), pid=pid, table_conversion=Conversion, table_device_measurements=DeviceMeasurements, table_input=Input, user=user, devices_1wire_ow_shell=devices_1wire_ow_shell, devices_1wire=devices_1wire) elif input_type == 'actions': return render_template('pages/actions.html', and_=and_, action=action, choices_actions=choices_actions, choices_function=choices_function, choices_input=choices_input, choices_output=choices_output, choices_measurement=choices_measurement, choices_measurements_units=choices_measurements_units, choices_method=choices_method, choices_output_channels=choices_output_channels, choices_output_channels_measurements=choices_output_channels_measurements, choices_pid=choices_pid, choices_pid_devices=choices_pid_devices, choices_unit=choices_unit, custom_commands=custom_commands, custom_options_values_actions=custom_options_values_actions, custom_options_values_inputs=custom_options_values_inputs, custom_options_values_input_channels=custom_options_values_input_channels, dict_actions=dict_actions, dict_inputs=dict_inputs, dict_measurements=dict_measurements, dict_units=dict_units, display_order_input=display_order_input, each_action=each_action, each_input=each_input, form_actions=form_actions, form_add_input=form_add_input, form_mod_input=form_mod_input, ftdi_devices=ftdi_devices, input_channel=input_channel, input_templates=input_templates, names_input=names_input, output=output, output_types=output_types(), pid=pid, table_conversion=Conversion, table_device_measurements=DeviceMeasurements, table_input=Input, user=user, devices_1wire_ow_shell=devices_1wire_ow_shell, devices_1wire=devices_1wire)
def page_output(): """Display Output page options.""" output_type = request.args.get('output_type', None) output_id = request.args.get('output_id', None) each_output = None if output_type in ['entry', 'options'] and output_id != '0': each_output = Output.query.filter( Output.unique_id == output_id).first() camera = Camera.query.all() function = CustomController.query.all() input_dev = Input.query.all() method = Method.query.all() misc = Misc.query.first() output = Output.query.all() output_channel = OutputChannel pid = PID.query.all() user = User.query.all() dict_outputs = parse_output_information() form_add_output = forms_output.OutputAdd() form_mod_output = forms_output.OutputMod() # Generate all measurement and units used dict_measurements = add_custom_measurements(Measurement.query.all()) dict_units = add_custom_units(Unit.query.all()) choices_function = utils_general.choices_functions(function, dict_units, dict_measurements) choices_input = utils_general.choices_inputs(input_dev, dict_units, dict_measurements) choices_input_devices = utils_general.choices_input_devices(input_dev) choices_method = utils_general.choices_methods(method) choices_output = utils_general.choices_outputs(output, OutputChannel, dict_outputs, dict_units, dict_measurements) choices_output_channels = utils_general.choices_outputs_channels( output, output_channel.query.all(), dict_outputs) choices_pid = utils_general.choices_pids(pid, dict_units, dict_measurements) custom_options_values_outputs = parse_custom_option_values_json( output, dict_controller=dict_outputs) custom_options_values_output_channels = parse_custom_option_values_output_channels_json( output_channel.query.all(), dict_controller=dict_outputs, key_name='custom_channel_options') custom_commands = {} for each_output_dev in output: if 'custom_commands' in dict_outputs[each_output_dev.output_type]: custom_commands[each_output_dev.output_type] = True # Create dict of Input names names_output = {} all_elements = output for each_element in all_elements: names_output[each_element.unique_id] = '[{id}] {name}'.format( id=each_element.unique_id.split('-')[0], name=each_element.name) # Create list of file names from the output_options directory # Used in generating the correct options for each output/device output_templates = [] output_path = os.path.join( INSTALL_DIRECTORY, 'mycodo/mycodo_flask/templates/pages/output_options') for (_, _, file_names) in os.walk(output_path): output_templates.extend(file_names) break display_order_output = csv_to_list_of_str( DisplayOrder.query.first().output) output_variables = {} for each_output_dev in output: output_variables[each_output_dev.unique_id] = {} for each_channel in dict_outputs[ each_output_dev.output_type]['channels_dict']: output_variables[each_output_dev.unique_id][each_channel] = {} output_variables[ each_output_dev.unique_id][each_channel]['amps'] = None output_variables[each_output_dev. unique_id][each_channel]['trigger_startup'] = None # Find FTDI devices ftdi_devices = [] if not current_app.config['TESTING']: for each_output_dev in output: if each_output_dev.interface == "FTDI": from mycodo.devices.atlas_scientific_ftdi import get_ftdi_device_list ftdi_devices = get_ftdi_device_list() break if not output_type: return render_template( 'pages/output.html', camera=camera, choices_function=choices_function, choices_input=choices_input, choices_input_devices=choices_input_devices, choices_method=choices_method, choices_output=choices_output, choices_output_channels=choices_output_channels, choices_pid=choices_pid, custom_commands=custom_commands, custom_options_values_outputs=custom_options_values_outputs, custom_options_values_output_channels= custom_options_values_output_channels, dict_outputs=dict_outputs, display_order_output=display_order_output, form_add_output=form_add_output, form_mod_output=form_mod_output, ftdi_devices=ftdi_devices, misc=misc, names_output=names_output, output=output, output_channel=output_channel, output_types=output_types(), output_templates=output_templates, output_variables=output_variables, user=user) elif output_type == 'entry': return render_template( 'pages/output_entry.html', camera=camera, choices_function=choices_function, choices_input=choices_input, choices_input_devices=choices_input_devices, choices_method=choices_method, choices_output=choices_output, choices_output_channels=choices_output_channels, choices_pid=choices_pid, custom_commands=custom_commands, custom_options_values_outputs=custom_options_values_outputs, custom_options_values_output_channels= custom_options_values_output_channels, dict_outputs=dict_outputs, display_order_output=display_order_output, each_output=each_output, form_add_output=form_add_output, form_mod_output=form_mod_output, ftdi_devices=ftdi_devices, misc=misc, names_output=names_output, output=output, output_channel=output_channel, output_types=output_types(), output_templates=output_templates, output_variables=output_variables, user=user) elif output_type == 'options': return render_template( 'pages/output_options.html', camera=camera, choices_function=choices_function, choices_input=choices_input, choices_input_devices=choices_input_devices, choices_method=choices_method, choices_output=choices_output, choices_output_channels=choices_output_channels, choices_pid=choices_pid, custom_commands=custom_commands, custom_options_values_outputs=custom_options_values_outputs, custom_options_values_output_channels= custom_options_values_output_channels, dict_outputs=dict_outputs, display_order_output=display_order_output, each_output=each_output, form_add_output=form_add_output, form_mod_output=form_mod_output, ftdi_devices=ftdi_devices, misc=misc, names_output=names_output, output=output, output_channel=output_channel, output_types=output_types(), output_templates=output_templates, output_variables=output_variables, user=user)
def initialize_variables(self): lcd_dev = db_retrieve_table_daemon(LCD, unique_id=self.unique_id) self.lcd_type = lcd_dev.lcd_type self.lcd_name = lcd_dev.name self.lcd_period = lcd_dev.period self.lcd_x_characters = lcd_dev.x_characters self.lcd_y_lines = lcd_dev.y_lines self.timer = time.time() + self.lcd_period self.backlight_timer = time.time() self.log_level_debug = lcd_dev.log_level_debug self.set_log_level_debug(self.log_level_debug) # Add custom measurement and units to list self.list_inputs = add_custom_measurements( db_retrieve_table_daemon(Measurement, entry='all')) self.list_inputs.update( {'input_time': {'unit': None, 'name': 'Time'}}) self.list_inputs.update( {'pid_time': {'unit': None, 'name': 'Time'}}) self.dict_units = add_custom_units( db_retrieve_table_daemon(Unit, entry='all')) lcd_data = db_retrieve_table_daemon( LCDData).filter(LCDData.lcd_id == lcd_dev.unique_id).all() for each_lcd_display in lcd_data: self.display_sets.append(each_lcd_display.unique_id) self.lcd_string_line[each_lcd_display.unique_id] = {} self.lcd_line[each_lcd_display.unique_id] = {} self.lcd_text[each_lcd_display.unique_id] = {} self.lcd_max_age[each_lcd_display.unique_id] = {} self.lcd_decimal_places[each_lcd_display.unique_id] = {} for i in range(1, self.lcd_y_lines + 1): self.lcd_string_line[each_lcd_display.unique_id][i] = '' self.lcd_line[each_lcd_display.unique_id][i] = {} if i == 1: self.lcd_text[each_lcd_display.unique_id][i] = each_lcd_display.line_1_text self.lcd_max_age[each_lcd_display.unique_id][i] = each_lcd_display.line_1_max_age self.lcd_decimal_places[each_lcd_display.unique_id][i] = each_lcd_display.line_1_decimal_places elif i == 2: self.lcd_text[each_lcd_display.unique_id][i] = each_lcd_display.line_2_text self.lcd_max_age[each_lcd_display.unique_id][i] = each_lcd_display.line_2_max_age self.lcd_decimal_places[each_lcd_display.unique_id][i] = each_lcd_display.line_2_decimal_places elif i == 3: self.lcd_text[each_lcd_display.unique_id][i] = each_lcd_display.line_3_text self.lcd_max_age[each_lcd_display.unique_id][i] = each_lcd_display.line_3_max_age self.lcd_decimal_places[each_lcd_display.unique_id][i] = each_lcd_display.line_3_decimal_places elif i == 4: self.lcd_text[each_lcd_display.unique_id][i] = each_lcd_display.line_4_text self.lcd_max_age[each_lcd_display.unique_id][i] = each_lcd_display.line_4_max_age self.lcd_decimal_places[each_lcd_display.unique_id][i] = each_lcd_display.line_4_decimal_places elif i == 5: self.lcd_text[each_lcd_display.unique_id][i] = each_lcd_display.line_5_text self.lcd_max_age[each_lcd_display.unique_id][i] = each_lcd_display.line_5_max_age self.lcd_decimal_places[each_lcd_display.unique_id][i] = each_lcd_display.line_5_decimal_places elif i == 6: self.lcd_text[each_lcd_display.unique_id][i] = each_lcd_display.line_6_text self.lcd_max_age[each_lcd_display.unique_id][i] = each_lcd_display.line_6_max_age self.lcd_decimal_places[each_lcd_display.unique_id][i] = each_lcd_display.line_6_decimal_places elif i == 7: self.lcd_text[each_lcd_display.unique_id][i] = each_lcd_display.line_7_text self.lcd_max_age[each_lcd_display.unique_id][i] = each_lcd_display.line_7_max_age self.lcd_decimal_places[each_lcd_display.unique_id][i] = each_lcd_display.line_7_decimal_places elif i == 8: self.lcd_text[each_lcd_display.unique_id][i] = each_lcd_display.line_8_text self.lcd_max_age[each_lcd_display.unique_id][i] = each_lcd_display.line_8_max_age self.lcd_decimal_places[each_lcd_display.unique_id][i] = each_lcd_display.line_8_decimal_places if self.lcd_y_lines in [2, 4, 8]: self.setup_lcd_line( each_lcd_display.unique_id, 1, each_lcd_display.line_1_id, each_lcd_display.line_1_measurement) self.setup_lcd_line( each_lcd_display.unique_id, 2, each_lcd_display.line_2_id, each_lcd_display.line_2_measurement) if self.lcd_y_lines in [4, 8]: self.setup_lcd_line( each_lcd_display.unique_id, 3, each_lcd_display.line_3_id, each_lcd_display.line_3_measurement) self.setup_lcd_line( each_lcd_display.unique_id, 4, each_lcd_display.line_4_id, each_lcd_display.line_4_measurement) if self.lcd_y_lines == 8: self.setup_lcd_line( each_lcd_display.unique_id, 5, each_lcd_display.line_5_id, each_lcd_display.line_5_measurement) self.setup_lcd_line( each_lcd_display.unique_id, 6, each_lcd_display.line_6_id, each_lcd_display.line_6_measurement) self.setup_lcd_line( each_lcd_display.unique_id, 7, each_lcd_display.line_7_id, each_lcd_display.line_7_measurement) self.setup_lcd_line( each_lcd_display.unique_id, 8, each_lcd_display.line_8_id, each_lcd_display.line_8_measurement) if self.lcd_type in ['16x2_generic', '20x4_generic']: from mycodo.devices.lcd_generic import LCD_Generic self.lcd_out = LCD_Generic(lcd_dev) self.lcd_init() elif self.lcd_type in ['16x2_grove_lcd_rgb']: from mycodo.devices.lcd_grove_lcd_rgb import LCD_Grove_LCD_RGB self.lcd_out = LCD_Grove_LCD_RGB(lcd_dev) self.lcd_init() elif self.lcd_type in ['128x32_pioled', '128x64_pioled']: from mycodo.devices.lcd_pioled import LCD_Pioled self.lcd_out = LCD_Pioled(lcd_dev) self.lcd_init() elif self.lcd_type in ['128x32_pioled_circuit_python', '128x64_pioled_circuit_python']: from mycodo.devices.lcd_pioled_circuitpython import LCD_Pioled_Circuitpython self.lcd_out = LCD_Pioled_Circuitpython(lcd_dev) self.lcd_init() else: self.logger.error("Unknown LCD type: {}".format(self.lcd_type)) if self.lcd_initialized: line_1 = 'Mycodo {}'.format(MYCODO_VERSION) line_2 = 'Start {}'.format(self.lcd_name) self.lcd_out.lcd_write_lines(line_1, line_2, '', '')