Code

Internal Implementation Documentation.

maaspower package

maaspower

automodule below.

maaspower.__version__: str

Version number as calculated by https://github.com/dls-controls/versiongit

massconfig.py

This module uses APISchema to serialize and deserialize the config file, plus provides a schema for easy editing of the config.

The MaasConfig class plus SwitchDevice derived classes in the devices folder provide an in memory representation of the contents of the maaspower YAML configuration file that specifies the set of power manager devices for which to serve web hooks.

maaspower.maasconfig

class maaspower.maasconfig.SwitchDevice(name: str[str], on: str[str], off: str[str], query: str[str], query_on_regex: str[str] = 'on', query_off_regex: str[str] = 'off', description: Optional[str][Optional[str]] = '', type: str = 'none')[source]

A base class for the switching devices that the webhook server will control. Concrete subclasses are found in the devices subfolder

class maaspower.maasconfig.MaasConfig(name: str[str], ip_address: str[str], port: int[int], username: str[str], password: str[str], devices: Sequence[maaspower.maasconfig.SwitchDevice][Sequence[maaspower.maasconfig.SwitchDevice]])[source]

Provides global information regarding webhook address, passwords etc.

Plus a list of switch devices. The devices are generic in this module, config definitions and function for specific device types are in the devices folder.

webhook.py

Use Flask to implement a web server that provides web hooks based on the provided configuration

maaspower.webhook

maaspower.webhook.command(devicename: str, command: str)[source]

Accept webhooks at /maaspower/<devicename>/<command>

maaspower.webhook.load_web_hook(c: maaspower.maasconfig.MaasConfig)[source]

Setup config for the webserver

maaspower.webhook.run_web_hook(c: maaspower.maasconfig.MaasConfig)[source]

Launch the webserver

devices package

Each SwitchDevice derived class in this package adds support for a type of switching device.

maaspower.devices

smart_thing.py

Classes to represent the configuration and functionality for devices that can be controlled via the SmartThings API.

See https://www.smartthings.com/

maaspower.devices.smart_thing

class maaspower.devices.smart_thing.SmartThing(name: str[str], on: str[str], off: str[str], query: str[str], query_on_regex: str[str] = 'on', query_off_regex: str[str] = 'off', description: Optional[str][Optional[str]] = '', type: Literal['SmartThingDevice'] = 'SmartThingDevice', api_token: str[str] = 'none', device_id: str[str] = 'none')[source]

A device controlled via SmartThings

shell_cmd.py

Classes to represent the configuration and functionality for devices that can be controlled via a command line utility.

e.g. smart power switching usb hubs https://github.com/mvp/uhubctl

maaspower.devices.shell_cmd

class maaspower.devices.shell_cmd.CommandLine(name: str[str], on: str[str], off: str[str], query: str[str], query_on_regex: str[str] = 'on', query_off_regex: str[str] = 'off', description: Optional[str][Optional[str]] = '', type: Literal['CommandLine'] = 'CommandLine')[source]

A device controlled via a command line utility