![]() |
ThalamOS
a powerful Flask web application designed to enhance your storage management.
|
Functions | |
Annotated[str, "search page as a rendered template"] | index () |
Annotated[str, "search page as a rendered template"] | toggle_light () |
Annotated[str, "item creation page as a rendered template"] | create_item () |
Annotated[tuple, {"status":str, "status_code":int}] | send_creation () |
Annotated[str, "item page as a rendered template"] | item (item_id) |
Annotated[tuple, {"status":str, "status_code":int}] | update_item (item_id) |
Annotated[str, "search page as a rendered template"] | delete_item (item_id) |
Response | search (term) |
Exception | handle_exception (e) |
Response | get_env () |
tuple[Response, int]|Response | get_ollama_models () |
tuple[Response, int]|Response | get_weight () |
Response | ask_llm_question () |
Annotated[tuple, {"status":str, "status_code":int}] | log_message () |
Variables | |
dotenv_path | |
str | IS_SCALE_ENABLED = "true" |
app = Flask(__name__) | |
host | |
debug | |
ThalamOS Application This module sets up a Flask web application for managing storage items, controlling WLED devices, interacting with a WiFi scale, and querying an LLM service. It provides various routes for rendering templates, handling item creation, deletion, and search, as well as retrieving environment configurations, scale weight, and logging messages. Routes: - /: Renders the search page. - /toggleLight: Toggles the power state of the WLED device and renders the search template. - /createItem: Renders the template for creating a new item. - /sendCreation: Handles the creation of a new item by processing the incoming JSON request data. - /item/<item_id>: Handles the request to display an item. - /item/<item_id>/update: Updates an item using the Storage_connector and returns a status message. - /item/<item_id>/delete: Deletes an item using the Storage_connector and renders the search.html template. - /search/<term>: Searches for a term in the storage and returns the results in JSON format. - /config/env: Retrieves the environment configuration. - /config/ollama/models: Fetches the list of available Ollama models. - /wifiscale/weight: Retrieves the weight of the scale. - /llm/ask: Asks a question to the LLM service and returns the response. - /log: Logs a message with a specified log level. Error Handling: - handle_exception: Handles exceptions by passing through HTTP errors. Setup: - Initializes the Flask app and sets up CORS. - Loads environment variables from a .env file. - Sets up the Storage_connector within the app context. Usage: Run the application using the command `python app.py`.
Response app.ask_llm_question | ( | ) |
Ask a question to the Language Learning Model (LLM) service. This function sends a GET request to the LLM service at the specified endpoint and returns the response as a JSON object. Returns: Response: A Flask JSON response containing the response from the LLM service.
Definition at line 274 of file app.py.
Annotated[str, "item creation page as a rendered template"] app.create_item | ( | ) |
Renders the template for creating a new item. Returns: Response: The rendered HTML template for creating a new item.
Definition at line 90 of file app.py.
Annotated[str, "search page as a rendered template"] app.delete_item | ( | item_id | ) |
Deletes an item using the Storage_connector and renders the search.html template. Args: item_id: The id of the item to be deleted. Returns: A rendered template for the search page.
Definition at line 191 of file app.py.
Response app.get_env | ( | ) |
Retrieve the environment configuration. This function uses the config_manager to get the current environment configuration and returns it as a JSON response. Returns: Response: A Flask JSON response containing the environment configuration.
Definition at line 232 of file app.py.
tuple[Response, int] | Response app.get_ollama_models | ( | ) |
Fetches the list of available Ollama models. Returns: Annotated[str, "json response"]: A JSON response containing the list of Ollama models.
Definition at line 244 of file app.py.
tuple[Response, int] | Response app.get_weight | ( | ) |
Retrieve the weight of the scale. This function checks if the scale service is enabled by reading the IS_SCALE_ENABLED environment variable. If the scale service is not enabled, it returns a JSON response with a status message and HTTP status code 412. If the scale service is enabled, it uses the wifiscale module to get the weight of the scale and returns it as a JSON response. Returns: Response: A Flask JSON response containing the weight of the scale or a status message.
Definition at line 257 of file app.py.
Exception app.handle_exception | ( | e | ) |
Handles exceptions by passing through HTTP errors. Parameters: e (Exception): The exception to handle. Returns: Exception: The same exception that was passed in.
Definition at line 218 of file app.py.
Annotated[str, "search page as a rendered template"] app.index | ( | ) |
Renders the search page. Returns: Response: The rendered HTML template for the search page.
Definition at line 65 of file app.py.
Annotated[str, "item page as a rendered template"] app.item | ( | item_id | ) |
Handles the request to display an item. This function performs the following steps: 1. Changes the power state of the WLED device to on. 2. Fetches the item details from the storage using the provided item identifier. 3. Sets the color position on the WLED device based on the fetched item details. 4. If the fetched item contains additional information, it parses the data and renders the 'item.jinja2' template with the item details and information. 6. If the fetched item does not contain additional information, it renders the 'item.jinja2' template with only the item details. Args: item_id (int): The id of the item to display. Returns: The rendered HTML template for the item.
Definition at line 137 of file app.py.
Annotated[tuple, {"status": str, "status_code": int}] app.log_message | ( | ) |
Logs a message with a specified log level. The log level and message content are extracted from the JSON payload of the request. If the log level is not provided, it defaults to 'INFO'. If the message content is not provided, it defaults to an empty string. Returns: tuple: A dictionary with a status message and an HTTP status code 201. Request JSON structure: { "level": "DEBUG" | "INFO" | "WARNING" | "ERROR" | "CRITICAL", "message": "Your log message here" }
Definition at line 290 of file app.py.
Response app.search | ( | term | ) |
Search for a term in the storage and return the results in JSON format. Args: term (str): The term to search for in the storage. Returns: Response: A Flask Response object containing the search results in JSON format.
Definition at line 205 of file app.py.
Annotated[tuple, {"status": str, "status_code": int}] app.send_creation | ( | ) |
Handle the creation of a new item by processing the incoming JSON request data. The function expects a JSON payload with the following structure: { "info": <json>, "type": <str>, "name": <str>, "position": <str> } It extracts the necessary information from the JSON payload and attempts to create a new item using the Storage_connector.CreateItem method. If an exception occurs during the creation process, it prints the exception. Returns: tuple: A dictionary with a status message and an HTTP status code.
Definition at line 100 of file app.py.
Annotated[str, "search page as a rendered template"] app.toggle_light | ( | ) |
Toggles the power state of the WLED device and renders the search template. This function changes the power state of the WLED device to the opposite of its current state by calling the `changePowerState` method of the `wled_requests` object. After toggling the power state, it returns the rendered "search.html" template. Returns: str: The rendered "search.html" template.
Definition at line 75 of file app.py.
Annotated[tuple, {"status": str, "status_code": int}] app.update_item | ( | item_id | ) |
Updates an item using the Storage_connector and returns a status message. Args: item_id: The id of the item to be updated. Returns: A dictionary with a status message and an HTTP status code.
Definition at line 166 of file app.py.