Ejemplo n.º 1
0
    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())
Ejemplo n.º 2
0
    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())
Ejemplo n.º 3
0
def gpio_state():
    """Return the GPIO state, for output page status"""
    states = get_all_output_states()
    # Convert list of dictionaries to dictionary of key/value pairs
    states_dict = {}
    for each_state in states:
        states_dict[each_state['unique_id']] = each_state['state']
    return jsonify(states_dict)
Ejemplo n.º 4
0
 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())
Ejemplo n.º 5
0
def gpio_state():
    """Return all output states"""
    return jsonify(get_all_output_states())