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

Functions

None turn_off_lights ()
 
None color_pos (int pos)
 
None load_default_state ()
 
None change_power_state (state)
 
Annotated[bool, "True if power is on, false if power is off"] get_power_state ()
 

Variables

Annotated ENV_PATH
 
 dotenv_path
 
Annotated WLED_HOST
 
Annotated API = f"http://{WLED_HOST}/json"
 

Detailed Description

This module provides functions to interact with a WLED device via its JSON API.
It allows for turning off lights, setting colors at specific positions, loading default states,
changing power states, and retrieving the current power state of the WLED device.

Functions:
    turn_off_lights(): Sends a request to turn off the lights by setting the segment color to black.
    color_pos(pos): Sends a request to set the color of a specific position on a WLED device.
    load_default_state(): Sends a POST request to the WLED API to load the default state.
    change_power_state(state): Change the power state of the device.
    get_power_state(): Retrieves the power state of a WLED device.

Function Documentation

◆ change_power_state()

None wled_requests.change_power_state ( state)
Change the power state of the device.
Args:
    state (bool): The desired power state. True to turn on, False to turn off.
Returns:
    None

Definition at line 71 of file wled_requests.py.

71def change_power_state(state) -> None:
72 """
73 Change the power state of the device.
74 Args:
75 state (bool): The desired power state. True to turn on, False to turn off.
76 Returns:
77 None
78 """
79 req = json.dumps({"on": state})
80 requests.post(API, req, timeout=10)
81
82

◆ color_pos()

None wled_requests.color_pos ( int pos)
Sends a request to set the  color of a specific position on a WLED device.
Args:
    pos (int): The position to set the color for.
Returns:
    None

Definition at line 48 of file wled_requests.py.

48def color_pos(pos: int) -> None:
49 """
50 Sends a request to set the color of a specific position on a WLED device.
51 Args:
52 pos (int): The position to set the color for.
53 Returns:
54 None
55 """
56 req = json.dumps({"seg": {"i": [pos, "FF0000"]}})
57 requests.post(API, req, timeout=10)
58
59

◆ get_power_state()

Annotated[bool, "True if power is on, false if power is off"] wled_requests.get_power_state ( )
Retrieves the power state of a WLED device.
Sends a GET request to the WLED device's JSON API endpoint to fetch the current state.
Parses the JSON response to determine if the device is on or off.
Returns:
    bool: True if the WLED device is on, False otherwise.

Definition at line 83 of file wled_requests.py.

83def get_power_state() -> Annotated[bool, "True if power is on, false if power is off"]:
84 """
85 Retrieves the power state of a WLED device.
86 Sends a GET request to the WLED device's JSON API endpoint to fetch the current state.
87 Parses the JSON response to determine if the device is on or off.
88 Returns:
89 bool: True if the WLED device is on, False otherwise.
90 """
91 state = requests.get(f"http://{WLED_HOST}/json/state", timeout=10)
92 return json.loads(state.text)["on"]

◆ load_default_state()

None wled_requests.load_default_state ( )
Sends a POST request to the WLED API to load the default state.
This function creates a JSON payload with a preset state identifier and sends it to the WLED API endpoint using a POST request.
Raises:
    requests.exceptions.RequestException: If there is an issue with the HTTP request.

Definition at line 60 of file wled_requests.py.

60def load_default_state() -> None:
61 """
62 Sends a POST request to the WLED API to load the default state.
63 This function creates a JSON payload with a preset state identifier and sends it to the WLED API endpoint using a POST request.
64 Raises:
65 requests.exceptions.RequestException: If there is an issue with the HTTP request.
66 """
67 req = json.dumps({"ps": 1})
68 requests.post(API, req, timeout=10)
69
70

◆ turn_off_lights()

None wled_requests.turn_off_lights ( )
Sends a request to turn off the lights by setting the segment color to black.
This function creates a JSON payload to set the color of a segment of lights to black (hex code "000000")
and sends a POST request to the specified API endpoint to turn off the lights.
Raises:
    requests.exceptions.RequestException: If there is an issue with the HTTP request.

Definition at line 36 of file wled_requests.py.

36def turn_off_lights() -> None:
37 """
38 Sends a request to turn off the lights by setting the segment color to black.
39 This function creates a JSON payload to set the color of a segment of lights to black (hex code "000000")
40 and sends a POST request to the specified API endpoint to turn off the lights.
41 Raises:
42 requests.exceptions.RequestException: If there is an issue with the HTTP request.
43 """
44 req = json.dumps({"seg": {"i": [0, 50, "000000"]}})
45 requests.post(API, req, timeout=10)
46
47

Variable Documentation

◆ API

Annotated wled_requests.API = f"http://{WLED_HOST}/json"

Definition at line 33 of file wled_requests.py.

◆ dotenv_path

wled_requests.dotenv_path

Definition at line 26 of file wled_requests.py.

◆ ENV_PATH

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

Definition at line 23 of file wled_requests.py.

◆ WLED_HOST

Annotated wled_requests.WLED_HOST
Initial value:
1= os.getenv(
2 "WLED_HOST"
3)

Definition at line 28 of file wled_requests.py.