Skip to content
Rares Cristian Olteanu edited this page Apr 27, 2025 · 3 revisions

SmartDash Function Documentation

Table of Contents

app.py

User Model

add_device(self, name, ip, device_type)

Adds a new device to the user's device list.

  • Parameters:
    • name (str): The name of the device.
    • ip (str): The IP address of the device.
    • device_type (str): The type of the device.

remove_device(self, name)

Removes a device from the user's device list by name.

  • Parameters:
    • name (str): The name of the device to remove.

get_devices(self)

Returns the list of devices associated with the user.

  • Returns:
    • list: A list of devices.

save_settings(self, user_settings)

Saves user settings such as theme and IP address visibility.

  • Parameters:
    • user_settings (dict): A dictionary of user settings.

get_settings(self)

Returns the user's settings.

  • Returns:
    • dict: A dictionary of user settings.

Flask Routes

home()

Renders the home page, displaying the user's devices. Requires login.

  • Route: /
  • Methods: GET

register()

Handles user registration. Displays the registration form and processes form submissions.

  • Route: /register
  • Methods: GET, POST

login()

Handles user login. Displays the login form and processes form submissions.

  • Route: /login
  • Methods: GET, POST

logout()

Logs out the current user and redirects to the login page.

  • Route: /logout
  • Methods: GET

add_device()

Adds a new device to the user's device list. Requires login.

  • Route: /add_device
  • Methods: POST

remove_device()

Removes a device from the user's device list. Requires login.

  • Route: /remove_device
  • Methods: POST

toggle_device()

Toggles the state of a device.

  • Route: /toggle_device
  • Methods: POST

save_settings()

Saves user settings. Requires login.

  • Route: /save_settings
  • Methods: POST

get_settings()

Returns the user's settings. Requires login.

  • Route: /get_settings
  • Methods: GET

solar_data()

Fetches and returns real-time data from Fronius solar panels.

  • Route: /solar-data
  • Methods: GET

get_temperature_data()

Returns simulated temperature, humidity, and pressure data.

  • Route: /temperature-data
  • Methods: GET

Helper Functions

load_user(user_id)

Loads a user by their ID.

  • Parameters:

    • user_id (int): The ID of the user to load.
  • Returns:

    • User: The user object.

get_device_icon(device_type)

Returns the appropriate icon class for a given device type.

  • Parameters:

    • device_type (str): The type of the device.
  • Returns:

    • str: The icon class.

fetch_fronius_device_data()

Fetches data from Fronius devices associated with the current user.

  • Returns:
    • list: A list of device data.

fetch_fronius_data(ip_address)

Fetches data from a Fronius device by its IP address.

  • Parameters:

    • ip_address (str): The IP address of the Fronius device.
  • Returns:

    • dict: The data from the Fronius device.

setup.py

Utility Functions

check_config_file()

Checks if the config.json file exists.

  • Returns:
    • bool: True if the file exists, False otherwise.

test_connection(db_uri)

Tests the connection to the database using the provided URI.

  • Parameters:

    • db_uri (str): The database URI.
  • Returns:

    • bool: True if the connection is successful, False otherwise.

create_config_file()

Prompts the user to enter database configuration details and creates the config.json file.

  • Returns:
    • str: The database URI.

load_config()

Loads the database configuration from the config.json file.

  • Returns:
    • dict: The database configuration.

open_config_file_location()

Opens the location of the config.json file in the file explorer.