Core Components
⚙️ Core Components¶
Core client classes and API interface for WyreStorm NetworkHD devices.
🎛️ NHD API Interface¶
Typed wrapper for all NHD command groups.
Provides organized access to all NetworkHD API commands, grouped by functionality. Each command group contains related commands for a specific domain.
This class supports any NetworkHD client implementation, including SSH and RS232 clients. Future client implementations are automatically supported.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client
|
_BaseNetworkHDClient
|
A NetworkHD client instance (NetworkHDClientSSH, NetworkHDClientRS232, etc.) |
required |
Example
from wyrestorm_networkhd import NetworkHDClientSSH, NHDAPI
# Create a client
client = NetworkHDClientSSH(
host="192.168.1.100",
port=22,
username="admin",
password="password",
ssh_host_key_policy="auto_add"
)
# Create API wrapper
api = NHDAPI(client)
# Use command groups
await api.api_query.get_device_info()
🔌 RS232 Client¶
RS232 client for NetworkHD devices with simplified architecture.
NetworkHDClientRS232
¶
NetworkHDClientRS232(port: str, baudrate: int, timeout: float = 10.0, *, circuit_breaker_timeout: float = 30.0, heartbeat_interval: float = 30.0, message_dispatcher_interval: float = 0.05, **serial_kwargs)
Bases: _BaseNetworkHDClient
RS232 client for NetworkHD devices.
Provides a simplified interface for connecting to NetworkHD devices via RS232, with automatic message dispatching and notification handling.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
port
|
str
|
The serial port (e.g., '/dev/ttyUSB0' on Linux, 'COM1' on Windows). |
required |
baudrate
|
int
|
The baud rate for serial communication. |
required |
timeout
|
float
|
Connection timeout in seconds (default: 10.0). |
10.0
|
circuit_breaker_timeout
|
float
|
Time in seconds after which the circuit breaker will automatically reset after being opened (default: 30.0). |
30.0
|
heartbeat_interval
|
float
|
Interval in seconds between heartbeat checks (default: 30.0). |
30.0
|
message_dispatcher_interval
|
float
|
Sleep interval in seconds for the message dispatcher loop to prevent busy waiting (default: 0.05). |
0.05
|
**serial_kwargs
|
Additional serial port configuration options. |
{}
|
Raises:
Type | Description |
---|---|
ValueError
|
If any parameters are invalid. |
connect
async
¶
Establish RS232 connection to the NetworkHD device.
Raises:
Type | Description |
---|---|
ConnectionError
|
If the connection fails. |
disconnect
async
¶
Disconnect from the NetworkHD device.
Closes the RS232 connection and stops the message dispatcher.
is_connected
¶
Check if connected to the device via RS232.
Returns:
Type | Description |
---|---|
bool
|
True if connected, False otherwise. |
send_command
async
¶
Send a command to the device via RS232 and get the response.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
command
|
str
|
The command string to send. |
required |
response_timeout
|
float
|
Maximum time to wait for response in seconds. |
10.0
|
Returns:
Type | Description |
---|---|
str
|
The response string from the device. |
Raises:
Type | Description |
---|---|
ConnectionError
|
If not connected to the device. |
CommandError
|
If the command fails or times out. |
🔌 SSH Client¶
SSH client for NetworkHD devices with simplified architecture.
NetworkHDClientSSH
¶
NetworkHDClientSSH(host: str, port: int, username: str, password: str, ssh_host_key_policy: HostKeyPolicy, timeout: float = 10.0, *, circuit_breaker_timeout: float = 30.0, heartbeat_interval: float = 30.0, message_dispatcher_interval: float = 0.1)
Bases: _BaseNetworkHDClient
SSH client for NetworkHD devices.
Provides a simplified interface for connecting to NetworkHD devices via SSH, with automatic message dispatching and notification handling.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
host
|
str
|
The hostname or IP address of the device. |
required |
port
|
int
|
The SSH port number. |
required |
username
|
str
|
The SSH username. |
required |
password
|
str
|
The SSH password. |
required |
ssh_host_key_policy
|
HostKeyPolicy
|
SSH host key verification policy. Must be one of: 'auto_add', 'reject', or 'warn'. |
required |
timeout
|
float
|
Connection timeout in seconds (default: 10.0). |
10.0
|
circuit_breaker_timeout
|
float
|
Time in seconds after which the circuit breaker will automatically reset after being opened (default: 30.0). |
30.0
|
heartbeat_interval
|
float
|
Interval in seconds between heartbeat checks (default: 30.0). |
30.0
|
message_dispatcher_interval
|
float
|
Sleep interval in seconds for the message dispatcher loop to prevent busy waiting (default: 0.1). |
0.1
|
Raises:
Type | Description |
---|---|
ValueError
|
If required parameters are missing or invalid. |
connect
async
¶
Establish SSH connection to the NetworkHD device.
Raises:
Type | Description |
---|---|
ConnectionError
|
If the connection fails. |
AuthenticationError
|
If authentication fails. |
disconnect
async
¶
Disconnect from the NetworkHD device.
Closes the SSH connection and stops the message dispatcher.
is_connected
¶
Check if connected to the device via SSH.
Returns:
Type | Description |
---|---|
bool
|
True if connected, False otherwise. |
send_command
async
¶
Send a command to the device via SSH and get the response.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
command
|
str
|
The command string to send. |
required |
response_timeout
|
float
|
Maximum time to wait for response in seconds. |
10.0
|
Returns:
Type | Description |
---|---|
str
|
The response string from the device. |
Raises:
Type | Description |
---|---|
ConnectionError
|
If not connected to the device. |
CommandError
|
If the command fails or times out. |