hid_usb_relay
hid based usb relay package
source manual
This module provides functions to interact with a USB relay device using command-line commands. It allows users to get and set the state of the relay device, as well as retrieve information about the relay device's status.
get_all_relay_device_state()
Get the status of all connected relay devices.
Returns:
Type | Description |
---|---|
Optional[str]
|
Optional[str]: Status string, or None on error. |
get_bin_path()
Get the absolute path to the package's binary folder.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Path to the binary folder. |
get_default_relay_device_relay_state(relay_number)
Get the state of a specific relay on the default device.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
relay_number
|
str
|
Relay number as string (e.g., "1"). |
required |
Returns:
Type | Description |
---|---|
Optional[str]
|
Optional[str]: State ("ON"/"OFF") or None on error. |
get_default_relay_device_state()
Get the status of the default relay device.
Returns:
Type | Description |
---|---|
Optional[List[str]]
|
Optional[List[str]]: List of relay states, or None on error. |
get_platform_and_architecture()
Get the current system platform and architecture.
Returns:
Name | Type | Description |
---|---|---|
tuple |
Tuple[str, str]
|
(system, architecture), both lowercase strings. |
get_relay_device_relay_state(relay_id, relay_number)
Get the state of a specific relay on a specific device.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
relay_id
|
str
|
Relay device ID. |
required |
relay_number
|
str
|
Relay number as string (e.g., "1"). |
required |
Returns:
Type | Description |
---|---|
Optional[str]
|
Optional[str]: State ("ON"/"OFF") or None on error. |
get_relay_device_state(relay_id)
Get the status of a specific relay device by ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
relay_id
|
str
|
Relay device ID. |
required |
Returns:
Type | Description |
---|---|
Optional[List[str]]
|
Optional[List[str]]: List of relay states, or None on error. |
get_relay_executable()
Get the path to the relay command-line executable for the current platform.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Full path to the relay executable. |
get_relay_library()
Get the path to the relay library for the current platform.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Full path to the relay library. |
get_relay_path(file_name)
Build the path to a relay binary/library for the current platform and architecture.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_name
|
str
|
Name of the binary/library file. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Full path to the file. |
Raises:
Type | Description |
---|---|
OSError
|
If the system platform is unsupported. |
run_command(command)
Run a command using subprocess and return its output.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
command
|
List[str]
|
Command and arguments as a list. |
required |
Returns:
Type | Description |
---|---|
Optional[str]
|
Optional[str]: Output string if successful, None otherwise. |
set_default_relay_device_relay_state(relay_number, relay_state)
Set the state of a specific relay on the default device.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
relay_number
|
str
|
Relay number as string (e.g., "1"). |
required |
relay_state
|
str
|
"ON" or "OFF". |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if successful, False otherwise. |
set_default_relay_device_state(relay_state)
Set all relays on the default device to a given state.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
relay_state
|
str
|
"ON" or "OFF". |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if successful, False otherwise. |
set_relay_device_relay_state(relay_id, relay_number, relay_state)
Set the state of a specific relay on a specific device.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
relay_id
|
str
|
Relay device ID. |
required |
relay_number
|
str
|
Relay number as string (e.g., "1"). |
required |
relay_state
|
str
|
"ON" or "OFF". |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if successful, False otherwise. |
set_relay_device_state(relay_id, relay_state)
Set all relays on a specific device to a given state.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
relay_id
|
str
|
Relay device ID. |
required |
relay_state
|
str
|
"ON" or "OFF". |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if successful, False otherwise. |
default_relay_control(relay_number, relay_state)
Controls the state of a relay or all relays on the default relay device.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
relay_number
|
str
|
The relay number to control. Use "all" to control all relays. |
required |
relay_state
|
str
|
The desired state of the relay(s). Typically "on" or "off". |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
A dictionary containing the status of the operation and the current state of the relay(s). |
Raises:
Type | Description |
---|---|
HTTPException
|
If the relay state could not be set or if an internal error occurs. |
relay_control_by_id(relay_id, relay_number, relay_state)
Controls the state of a relay by its ID and relay number.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
relay_id
|
str
|
The ID of the relay device. |
required |
relay_number
|
str
|
The number of the relay to control. Use "all" to control all relays. |
required |
relay_state
|
str
|
The desired state of the relay (e.g., "on", "off"). |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
A dictionary containing the status of the operation and the current state of the relay. |
Raises:
Type | Description |
---|---|
HTTPException
|
If the relay state could not be set or if an internal server error occurs. |
root_page_help()
Provides help text for the root page.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The help text for the root page. |