ThalamOS
a powerful Flask web application designed to enhance your storage management.
Loading...
Searching...
No Matches
weigh_fi_manager Namespace Reference

Functions

Annotated[float, "weight in grams"] get_weight ()
 

Variables

Annotated ENV_PATH
 
 dotenv_path
 
Annotated SCALE_HOST
 

Detailed Description

wifiscalemanager.py

This module provides functionality to interact with a WiFi-enabled scale.
It retrieves the weight from the scale by sending a GET request to the specified API endpoint.

Functions:
    get_weight(): Retrieves the weight of the scale.

Environment Variables:
    SCALE_HOST: The hostname or IP address of the WiFi scale, loaded from a .env file.

Dependencies:
    - requests: To send HTTP requests.
    - os: To handle file paths and environment variables.
    - dotenv: To load environment variables from a .env file.

Function Documentation

◆ get_weight()

Annotated[float, "weight in grams"] weigh_fi_manager.get_weight ( )
Retrieve the weight of the scale.
This function sends a GET request to the specified API endpoint
to retrieve the weight of the scale.
Returns:
    float: The weight of the scale.

Definition at line 37 of file weigh_fi_manager.py.

37def get_weight() -> Annotated[float, "weight in grams"]:
38 """
39 Retrieve the weight of the scale.
40 This function sends a GET request to the specified API endpoint
41 to retrieve the weight of the scale.
42 Returns:
43 float: The weight of the scale.
44 """
45 api = f"http://{SCALE_HOST}/getWeight"
46 try:
47 response = requests.get(api, timeout=10)
48 response.raise_for_status()
49 except requests.RequestException as e:
50 logger.error(f"Error retrieving weight: {e}")
51 return "ERROR SCALE NOT FOUND"
52 weight = response.content.decode("utf-8")
53 return weight

Variable Documentation

◆ dotenv_path

weigh_fi_manager.dotenv_path

Definition at line 29 of file weigh_fi_manager.py.

◆ ENV_PATH

Annotated weigh_fi_manager.ENV_PATH
Initial value:
1= os.path.join(
2 os.path.dirname(__file__), "data/.env"
3)

Definition at line 26 of file weigh_fi_manager.py.

◆ SCALE_HOST

Annotated weigh_fi_manager.SCALE_HOST
Initial value:
1= os.getenv(
2 "SCALE_HOST"
3)

Definition at line 31 of file weigh_fi_manager.py.