API Reference

This page contains the complete API reference for the Power Switch Pro library.

Main Client

Main client class for Power Switch Pro device.

class power_switch_pro.client.PowerSwitchPro(host, username, password, use_https=False, verify_ssl=True, port=None)[source]

Bases: object

Main client for interacting with Digital Loggers Power Switch Pro device.

This class provides a high-level interface to the REST API.

Parameters:
__init__(host, username, password, use_https=False, verify_ssl=True, port=None)[source]

Initialize Power Switch Pro client.

Parameters:
  • host (str) – Device IP address or hostname

  • username (str) – Admin username

  • password (str) – Admin password

  • use_https (bool) – Use HTTPS instead of HTTP (default: False)

  • verify_ssl (bool) – Verify SSL certificates (default: True)

  • port (Optional[int]) – Custom port number (optional)

get(path, params=None, headers=None)[source]

Make GET request.

Parameters:
Return type:

Response

post(path, data=None, json_data=None, headers=None)[source]

Make POST request.

Parameters:
Return type:

Response

put(path, data=None, json_data=None, headers=None)[source]

Make PUT request.

Parameters:
Return type:

Response

patch(path, data=None, json_data=None, headers=None)[source]

Make PATCH request.

Parameters:
Return type:

Response

delete(path, headers=None)[source]

Make DELETE request.

Parameters:
Return type:

Response

property info: Dict[str, Any]

Get device information.

Returns:

Dictionary with device info (serial, version, hostname, etc.)

test_connection()[source]

Test connection to device.

Return type:

bool

Returns:

True if connection successful, False otherwise

Outlet Management

Outlet management for Power Switch Pro.

class power_switch_pro.outlets.Outlet(manager, outlet_id)[source]

Bases: object

Represents a single power outlet.

Parameters:
__init__(manager, outlet_id)[source]

Initialize outlet.

Parameters:
  • manager (OutletManager) – Parent OutletManager instance

  • outlet_id (int) – Outlet index (0-based)

on()[source]

Turn outlet on.

Return type:

bool

Returns:

True if successful

off()[source]

Turn outlet off.

Return type:

bool

Returns:

True if successful

cycle()[source]

Cycle outlet (off, then on).

Return type:

bool

Returns:

True if successful

property state: bool

Get outlet state.

Returns:

True if on, False if off

property physical_state: bool

Get physical outlet state.

Returns:

True if physically on, False if off

property name: str

Get outlet name.

property locked: bool

Get outlet lock status.

__repr__()[source]

String representation.

Return type:

str

class power_switch_pro.outlets.OutletManager(client)[source]

Bases: object

Manager for power outlets.

__init__(client)[source]

Initialize outlet manager.

Parameters:

client – PowerSwitchPro client instance

__getitem__(outlet_id)[source]

Get outlet by index.

Parameters:

outlet_id (int) – Outlet index (0-based)

Return type:

Outlet

Returns:

Outlet instance

on(outlet_id)[source]

Turn on outlet.

Parameters:

outlet_id (int) – Outlet index (0-based)

Return type:

bool

Returns:

True if successful

off(outlet_id)[source]

Turn off outlet.

Parameters:

outlet_id (int) – Outlet index (0-based)

Return type:

bool

Returns:

True if successful

cycle(outlet_id)[source]

Cycle outlet (turn off, then on).

Parameters:

outlet_id (int) – Outlet index (0-based)

Return type:

bool

Returns:

True if successful

get_state(outlet_id)[source]

Get outlet state.

Parameters:

outlet_id (int) – Outlet index (0-based)

Return type:

bool

Returns:

True if on, False if off

get_physical_state(outlet_id)[source]

Get physical outlet state.

Parameters:

outlet_id (int) – Outlet index (0-based)

Return type:

bool

Returns:

True if physically on, False if off

get_name(outlet_id)[source]

Get outlet name.

Parameters:

outlet_id (int) – Outlet index (0-based)

Return type:

str

Returns:

Outlet name

set_name(outlet_id, name)[source]

Set outlet name.

Parameters:
  • outlet_id (int) – Outlet index (0-based)

  • name (str) – New outlet name

Return type:

bool

Returns:

True if successful

get_locked(outlet_id)[source]

Get outlet lock status.

Parameters:

outlet_id (int) – Outlet index (0-based)

Return type:

bool

Returns:

True if locked, False otherwise

set_locked(outlet_id, locked)[source]

Set outlet lock status.

Parameters:
  • outlet_id (int) – Outlet index (0-based)

  • locked (bool) – Lock status

Return type:

bool

Returns:

True if successful

get_all_states()[source]

Get states of all outlets.

Return type:

List[bool]

Returns:

List of outlet states

get_states(outlet_ids)[source]

Get states of specific outlets.

Parameters:

outlet_ids (List[int]) – List of outlet indices

Return type:

List[bool]

Returns:

List of outlet states

bulk_operation(action, locked=None, **filters)[source]

Perform bulk operation on outlets matching filters.

Parameters:
  • action (str) – Action to perform (‘on’, ‘off’, ‘cycle’)

  • locked (Optional[bool]) – Filter by locked status (optional)

  • **filters – Additional filters (e.g., name=’lamp’)

Return type:

bool

Returns:

True if successful

Examples

# Turn off all unlocked outlets manager.bulk_operation(‘off’, locked=False)

# Cycle all outlets named ‘server’ manager.bulk_operation(‘cycle’, name=’server’)

count()[source]

Get number of outlets.

Return type:

int

Returns:

Number of outlets

list_all()[source]

Get information about all outlets.

Return type:

List[Dict[str, Any]]

Returns:

List of outlet information dictionaries

Authentication & Users

Authentication and user management for Power Switch Pro.

class power_switch_pro.auth.AuthManager(client)[source]

Bases: object

Manager for authentication and users.

__init__(client)[source]

Initialize auth manager.

Parameters:

client – PowerSwitchPro client instance

list_users()[source]

Get list of all users.

Return type:

List[Dict[str, Any]]

Returns:

List of user dictionaries

get_user(user_id)[source]

Get user by ID.

Parameters:

user_id (int) – User index

Return type:

Dict[str, Any]

Returns:

User dictionary

get_user_by_name(name)[source]

Get user by name.

Parameters:

name (str) – Username

Return type:

Optional[Dict[str, Any]]

Returns:

User dictionary or None if not found

add_user(name, password, is_allowed=True, is_admin=False, outlet_access=None)[source]

Add a new user.

Parameters:
  • name (str) – Username

  • password (str) – User password

  • is_allowed (bool) – Whether user is allowed to login

  • is_admin (bool) – Whether user is admin

  • outlet_access (Optional[List[bool]]) – List of outlet access permissions (one per outlet)

Return type:

Dict[str, Any]

Returns:

Created user dictionary

update_user(user_id, name=None, password=None, is_allowed=None, outlet_access=None)[source]

Update user information.

Parameters:
  • user_id (int) – User index

  • name (Optional[str]) – New username (optional)

  • password (Optional[str]) – New password (optional)

  • is_allowed (Optional[bool]) – New allowed status (optional)

  • outlet_access (Optional[List[bool]]) – New outlet access permissions (optional)

Return type:

bool

Returns:

True if successful

delete_user(user_id)[source]

Delete user.

Parameters:

user_id (int) – User index

Return type:

bool

Returns:

True if successful

delete_user_by_name(name)[source]

Delete user by name.

Parameters:

name (str) – Username

Return type:

bool

Returns:

True if successful

change_admin_password(old_password, new_password)[source]

Change administrator password.

Parameters:
  • old_password (str) – Current password

  • new_password (str) – New password

Return type:

bool

Returns:

True if successful

Configuration

Configuration management for Power Switch Pro.

class power_switch_pro.config.ConfigManager(client)[source]

Bases: object

Manager for device configuration.

__init__(client)[source]

Initialize config manager.

Parameters:

client – PowerSwitchPro client instance

get_all(depth=2)[source]

Get all configuration.

Parameters:

depth (int) – Depth limit for response (default: 2)

Return type:

Dict[str, Any]

Returns:

Configuration dictionary

get(key)[source]

Get specific configuration value.

Parameters:

key (str) – Configuration key

Return type:

Any

Returns:

Configuration value

set(key, value)[source]

Set configuration value.

Parameters:
  • key (str) – Configuration key

  • value (Any) – New value

Return type:

bool

Returns:

True if successful

get_hostname()[source]

Get device hostname.

Return type:

str

set_hostname(hostname)[source]

Set device hostname.

Parameters:

hostname (str)

Return type:

bool

get_timezone()[source]

Get device timezone.

Return type:

str

set_timezone(timezone)[source]

Set device timezone.

Parameters:

timezone (str) – Timezone string (e.g., “UTC”, “UTC-5”)

Return type:

bool

Returns:

True if successful

get_http_port()[source]

Get HTTP port.

Return type:

int

set_http_port(port)[source]

Set HTTP port.

Parameters:

port (int)

Return type:

bool

get_https_port()[source]

Get HTTPS port.

Return type:

int

set_https_port(port)[source]

Set HTTPS port.

Parameters:

port (int)

Return type:

bool

get_ssh_enabled()[source]

Get SSH enabled status.

Return type:

bool

set_ssh_enabled(enabled)[source]

Set SSH enabled status.

Parameters:

enabled (bool)

Return type:

bool

get_ssh_port()[source]

Get SSH port.

Return type:

int

set_ssh_port(port)[source]

Set SSH port.

Parameters:

port (int)

Return type:

bool

allow_plaintext_logins(allow)[source]

Allow/disallow plaintext (Basic auth) logins.

Parameters:

allow (bool) – Whether to allow plaintext logins

Return type:

bool

Returns:

True if successful

get_refresh_enabled()[source]

Get web UI auto-refresh status.

Return type:

bool

set_refresh_enabled(enabled)[source]

Set web UI auto-refresh status.

Parameters:

enabled (bool)

Return type:

bool

get_refresh_delay()[source]

Get web UI refresh delay in minutes.

Return type:

int

set_refresh_delay(minutes)[source]

Set web UI refresh delay in minutes.

Parameters:

minutes (int)

Return type:

bool

get_lockout_delay()[source]

Get failed login lockout delay in seconds.

Return type:

int

set_lockout_delay(seconds)[source]

Set failed login lockout delay in seconds.

Parameters:

seconds (int)

Return type:

bool

get_syslog_address()[source]

Get syslog server IP address.

Return type:

str

set_syslog_address(address)[source]

Set syslog server IP address.

Parameters:

address (str)

Return type:

bool

Power Meters

Power meter management for Power Switch Pro.

class power_switch_pro.meters.MeterManager(client)[source]

Bases: object

Manager for power meters and metrics.

__init__(client)[source]

Initialize meter manager.

Parameters:

client – PowerSwitchPro client instance

get_all_values()[source]

Get all meter values.

Return type:

List[Dict[str, Any]]

Returns:

List of meter dictionaries with names and values

get_value(meter_name)[source]

Get specific meter value.

Parameters:

meter_name (str) – Meter identifier (e.g., “bus.0.current”)

Return type:

float

Returns:

Meter value

get_voltage(bus=0)[source]

Get voltage reading.

Parameters:

bus (int) – Bus number (default: 0)

Return type:

float

Returns:

Voltage in volts

Raises:

ResourceNotFoundError – If device does not have power metering hardware

get_current(bus=0)[source]

Get current reading.

Parameters:

bus (int) – Bus number (default: 0)

Return type:

float

Returns:

Current in amps

Raises:

ResourceNotFoundError – If device does not have power metering hardware

get_power(bus=0)[source]

Get power reading.

Parameters:

bus (int) – Bus number (default: 0)

Return type:

float

Returns:

Power in watts

Raises:

ResourceNotFoundError – If device does not have power metering hardware

get_total_energy(bus=0)[source]

Get total energy consumed.

Parameters:

bus (int) – Bus number (default: 0)

Return type:

float

Returns:

Total energy in kWh

get_bus_values(bus=0)[source]

Get all meter values for a specific bus.

Parameters:

bus (int) – Bus number (default: 0)

Return type:

Dict[str, float]

Returns:

Dictionary of meter names and values

list_meters()[source]

Get list of all available meters.

Return type:

List[Dict[str, Any]]

Returns:

List of meter information dictionaries

AutoPing

AutoPing management for Power Switch Pro.

class power_switch_pro.autoping.AutoPingManager(client)[source]

Bases: object

Manager for AutoPing functionality.

__init__(client)[source]

Initialize AutoPing manager.

Parameters:

client – PowerSwitchPro client instance

list_entries()[source]

Get list of all AutoPing entries.

Return type:

List[Dict[str, Any]]

Returns:

List of AutoPing entry dictionaries

get_entry(entry_id)[source]

Get AutoPing entry by ID.

Parameters:

entry_id (int) – Entry index

Return type:

Dict[str, Any]

Returns:

AutoPing entry dictionary

add_entry(host, outlet, enabled=True, interval=60, retries=3)[source]

Add AutoPing entry.

Parameters:
  • host (str) – Host to ping (IP address or hostname)

  • outlet (int) – Outlet index to control

  • enabled (bool) – Whether entry is enabled

  • interval (int) – Ping interval in seconds

  • retries (int) – Number of retries before cycling outlet

Return type:

Dict[str, Any]

Returns:

Created entry dictionary

update_entry(entry_id, host=None, outlet=None, enabled=None, interval=None, retries=None)[source]

Update AutoPing entry.

Parameters:
  • entry_id (int) – Entry index

  • host (Optional[str]) – New host (optional)

  • outlet (Optional[int]) – New outlet (optional)

  • enabled (Optional[bool]) – New enabled status (optional)

  • interval (Optional[int]) – New interval (optional)

  • retries (Optional[int]) – New retries count (optional)

Return type:

bool

Returns:

True if successful

delete_entry(entry_id)[source]

Delete AutoPing entry.

Parameters:

entry_id (int) – Entry index

Return type:

bool

Returns:

True if successful

enable_entry(entry_id)[source]

Enable AutoPing entry.

Parameters:

entry_id (int) – Entry index

Return type:

bool

Returns:

True if successful

disable_entry(entry_id)[source]

Disable AutoPing entry.

Parameters:

entry_id (int) – Entry index

Return type:

bool

Returns:

True if successful

Script Execution

Script execution management for Power Switch Pro.

class power_switch_pro.script.ScriptManager(client)[source]

Bases: object

Manager for script execution.

__init__(client)[source]

Initialize script manager.

Parameters:

client – PowerSwitchPro client instance

start(function_name, source=None)[source]

Start script execution.

Parameters:
  • function_name (str) – Name of the user function to execute

  • source (Optional[str]) – Optional source code with function call and arguments

Return type:

str

Returns:

Thread identifier as string

Examples

# Run function without arguments thread_id = manager.start(“test”)

# Run function with arguments thread_id = manager.start(“test”, ‘test(1.5, “hello”)’)

get_status(thread_id)[source]

Get script execution status.

Parameters:

thread_id (str) – Thread identifier from start()

Return type:

Dict[str, Any]

Returns:

Status dictionary

stop(thread_id)[source]

Stop script execution.

Parameters:

thread_id (str) – Thread identifier from start()

Return type:

bool

Returns:

True if successful

list_functions()[source]

Get list of available user functions.

Return type:

List[str]

Returns:

List of function names

Exceptions

Exception classes for Power Switch Pro library.

exception power_switch_pro.exceptions.PowerSwitchError[source]

Bases: Exception

Base exception for all Power Switch Pro errors.

exception power_switch_pro.exceptions.AuthenticationError[source]

Bases: PowerSwitchError

Raised when authentication fails.

exception power_switch_pro.exceptions.ConnectionError[source]

Bases: PowerSwitchError

Raised when connection to device fails.

exception power_switch_pro.exceptions.APIError(message, status_code=None, response=None)[source]

Bases: PowerSwitchError

Raised when API returns an error response.

__init__(message, status_code=None, response=None)[source]

Initialize API error.

Parameters:
  • message – Error message

  • status_code – HTTP status code

  • response – Full response object

exception power_switch_pro.exceptions.ValidationError[source]

Bases: PowerSwitchError

Raised when input validation fails.

exception power_switch_pro.exceptions.ResourceNotFoundError(message, status_code=None, response=None)[source]

Bases: APIError

Raised when a requested resource is not found.

exception power_switch_pro.exceptions.ConflictError(message, status_code=None, response=None)[source]

Bases: APIError

Raised when there is a conflict (409 status).