def get(self): """Show all output settings and statuses""" if not utils_general.user_has_permission('view_settings'): abort(403) try: list_data = get_from_db(OutputSchema, Output) list_channels = get_from_db(OutputChannelSchema, OutputChannel) states = get_all_output_states() # Change integer channel keys to strings (flask-restx limitation?) new_state_dict = {} for each_id in states: new_state_dict[each_id] = {} for each_channel in states[each_id]: new_state_dict[each_id][str( each_channel)] = states[each_id][each_channel] if list_data: return { 'output devices': list_data, 'output channels': list_channels, 'output states': new_state_dict }, 200 except Exception: abort(500, message='An exception occurred', error=traceback.format_exc())
def get(self): """Show all function settings""" if not utils_general.user_has_permission('view_settings'): abort(403) try: list_data = get_from_db(FunctionSchema, CustomController) list_channels = get_from_db(FunctionChannelSchema, FunctionChannel) if list_data: return {'function settings': list_data, 'function channels': list_channels}, 200 except Exception: abort(500, message='An exception occurred', error=traceback.format_exc())
def get(self, unique_id): """Show the settings and status for an output""" if not utils_general.user_has_permission('edit_controllers'): abort(403) try: dict_data = get_from_db(OutputSchema, Output, unique_id=unique_id) measure_schema = DeviceMeasurementsSchema() list_data = return_list_of_dictionaries( measure_schema.dump(DeviceMeasurements.query.filter_by( device_id=unique_id).all(), many=True)) control = DaemonControl() output_state = control.output_state(unique_id) return { 'output settings': dict_data, 'output device measurements': list_data, 'output state': output_state }, 200 except Exception: abort(500, message='An exception occurred', error=traceback.format_exc())
def get(self, unique_id): """Show the settings and status for an output.""" if not utils_general.user_has_permission('edit_controllers'): abort(403) try: list_data = get_from_db(OutputSchema, Output, unique_id=unique_id) output_channel_schema = OutputChannelSchema() list_channels = return_list_of_dictionaries( output_channel_schema.dump( OutputChannel.query.filter_by( output_id=unique_id).all(), many=True)) states = get_all_output_states() # Change integer channel keys to strings (flask-restx limitation?) new_state_dict = {} for each_channel in states[unique_id]: new_state_dict[str(each_channel)] = states[unique_id][each_channel] return {'output device': list_data, 'output device channels': list_channels, 'output device channel states': new_state_dict}, 200 except Exception: abort(500, message='An exception occurred', error=traceback.format_exc())
def get(self, unique_id): """Show the settings for an function""" if not utils_general.user_has_permission('view_settings'): abort(403) try: list_data = get_from_db(FunctionSchema, CustomController, unique_id=unique_id) function_channel_schema = FunctionChannelSchema() list_channels = return_list_of_dictionaries( function_channel_schema.dump( FunctionChannel.query.filter_by( function_id=unique_id).all(), many=True)) measure_schema = DeviceMeasurementsSchema() list_measurements = return_list_of_dictionaries( measure_schema.dump( DeviceMeasurements.query.filter_by( device_id=unique_id).all(), many=True)) return {'function settings': list_data, 'function channels': list_channels, 'device measurements': list_measurements}, 200 except Exception: abort(500, message='An exception occurred', error=traceback.format_exc())
def get(self, unique_id): """Show the settings for an input.""" if not utils_general.user_has_permission('view_settings'): abort(403) try: list_data = get_from_db(InputSchema, Input, unique_id=unique_id) measure_schema = InputChannelSchema() list_channels = return_list_of_dictionaries( measure_schema.dump( InputChannel.query.filter_by(input_id=unique_id).all(), many=True)) measure_schema = DeviceMeasurementsSchema() list_measurements = return_list_of_dictionaries( measure_schema.dump(DeviceMeasurements.query.filter_by( device_id=unique_id).join(DeviceMeasurements.conversion, isouter=True).all(), many=True)) return { 'input settings': list_data, 'input channels': list_channels, 'device measurements': list_measurements }, 200 except Exception: abort(500, message='An exception occurred', error=traceback.format_exc())
def get(self): """Show all input settings.""" if not utils_general.user_has_permission('view_settings'): abort(403) try: list_data = get_from_db(InputSchema, Input) list_channels = get_from_db(InputChannelSchema, InputChannel) if list_data: return { 'input settings': list_data, 'input channels': list_channels }, 200 except Exception: abort(500, message='An exception occurred', error=traceback.format_exc())
def get(self): """Show all math settings""" if not utils_general.user_has_permission('view_settings'): abort(403) try: list_data = get_from_db(MathSchema, Math) if list_data: return {'math settings': list_data}, 200 except Exception: abort(500, message='An exception occurred', error=traceback.format_exc())
def get(self, unique_id): """Show the settings for a unit with the unique_id""" if not utils_general.user_has_permission('view_settings'): abort(403) try: dict_data = get_from_db(UnitSchema, Unit, unique_id=unique_id) if dict_data: return dict_data, 200 except Exception: abort(500, message='An exception occurred', error=traceback.format_exc())
def get(self): """Show all output settings and statuses""" if not utils_general.user_has_permission('view_settings'): abort(403) try: list_data = get_from_db(OutputSchema, Output) states = get_all_output_states() if list_data: return {'output settings': list_data, 'output states': states}, 200 except Exception: abort(500, message='An exception occurred', error=traceback.format_exc())
def get(self, unique_id): """Show the settings for a math""" if not utils_general.user_has_permission('view_settings'): abort(403) try: dict_data = get_from_db(MathSchema, Math, unique_id=unique_id) measure_schema = DeviceMeasurementsSchema() list_data = return_list_of_dictionaries( measure_schema.dump( DeviceMeasurements.query.filter_by( device_id=unique_id).all(), many=True)) return {'math settings': dict_data, 'device measurements': list_data}, 200 except Exception: abort(500, message='An exception occurred', error=traceback.format_exc())