switch

powerswitchbase

class lvmnps.switch.powerswitchbase.PowerSwitchBase(name, config, log)[source]

Bases: object

PowerswitchBase class for multiple power switches from different manufacturers The Powerswitch classes will inherit the PowerSwitchBase class.

Parameters
  • name (str) – A name identifying the power switch. ‘DLI Controller’ for Dli switch

  • config ([]) – The configuration defined on the .yaml file under /etc/lvmnps.yml

  • log (sdsstools.logger.SDSSLogger) – The logger for logging

collectOutletsByNameAndPort(name, portnum=0)[source]

Collects the outlet by the name and ports, comparing with the name and ports from the Outlet object.

Parameters
  • name (str) – The string to compare with the name in Outlet instance.

  • portnum (int) – The integer for indicating each Outlet instances

config_get(key, default=None)[source]

Read the configuration and extract the data as a structure that we want. Notice: DOESNT work for keys with dots !!!

Parameters

key

The tree structure as a string to extract the data. For example, if the configuration structure is

ports;
1;

desc; “Hg-Ar spectral callibration lamp”

You can input the key as “ports.1.desc” to take the information “Hg-Ar spectral callibration lamp”

findOutletByName(name)[source]

Find the outlet by the name, comparing with the name from the Outlet object.

Parameters

name (str) – The string to compare with the name in Outlet instance.

abstract async isReachable()[source]

Verify we can reach the switch, returns true if ok

async setState(state, name='', portnum=0)[source]

Set the state of the Outlet instance to On/Off. (On = 1, Off = 0)

Parameters
  • state – The boolian value (True, False) to set the state inside the Outlet object.

  • name (str) – The string to compare with the name in Outlet instance.

  • portnum (int) – The integer for indicating each Outlet instances

abstract async start()[source]
async statusAsDict(name='', portnum=0)[source]

Get the status of the Outlets by dictionary.

Parameters
  • name (str) – The string to compare with the name in Outlet instance. ‘name’ can be a switch or an outlet name.

  • portnum (int) – The integer for indicating each Outlet instances

abstract async stop()[source]
abstract async switch(state, outlets)[source]
abstract async update(outlets)[source]

outlet

class lvmnps.switch.outlet.Outlet(swname, name, portnum, description, state)[source]

Bases: object

Outlet class to manage the power switch.

Parameters
  • swname – the name of the switch (from the configuration file)

  • name – The name of the outlet

  • portnum – The number of the port (in the range of 1~8)

  • description – The description about the outlet

  • state – the state of the outlet (on: 1, off:0)

isOff()[source]

Return the state of the outlet.

isOn()[source]

Return the state of the outlet.

isValid()[source]

Return the validity of the outlet.

static parse(value)[source]

Parse the input data for ON/OFF.

setState(value)[source]

Class method: Set the state of the outlet inside the class.

toDict()[source]

Return the dictionary describing the status of the outlet.

digital-loggers

dli

class lvmnps.switch.dli.dli.Dli(log=None, name=None, userid=None, password=None, hostname=None, onoff_timeout=3)[source]

Bases: object

Powerswitch class to manage the dli power switch.

Parameters
  • log – The logger for logging

  • name – the name of the Dli Controller

  • userid – The username from the configuration (the id for login)

  • password – The password from the configuration (the password for login)

  • hostname – The hostname from the configuration (the ip address for connection)

  • onoff_timeout – the onoff_timeout seconds for sending the on/off command.

async add_client()[source]

Add the httpx AsyncClient on the Dli object.

async close()[source]

Close the Client.

async compare(json, outlets)[source]

Compares the name of outlets from the json object and the name of the Outlet object list. The name of the Outlet object is from the configuration file in /etc/lvmnps_dli.yml

Parameters
  • json – The json list from the restful API. The current status of the power switch is contained here.

  • outlets – list of Outlet objects defined on /switch/outlet.py each Oulet object indicates one of eight outlets of the dli power switch.

async off(outlet=0)[source]

Turn off the power of the outlet. Set the value of the outlet state by “put” method. The outlet value is integer, but the outlet number is 1, 2, 3, 4, 5, 6, 7 ,8 So we have to put 0, 1, 2, 3, 4, 5, 6, 7 to indicate the outlet inside the python list.

Parameters

outlet – (int) The number indicating the outlet. The input will be 1, 2, 3, 4, 5, 6, 7, 8.

async on(outlet=0)[source]

Turn on the power of the outlet. Set the value of the outlet state by “put” method. The outlet value is integer, but the outlet number is 1, 2, 3, 4, 5, 6, 7 ,8 So we have to put 0, 1, 2, 3, 4, 5, 6, 7 to indicate the outlet inside the python list.

Parameters

outlet – (int) The number indicating the outlet. The input will be 1, 2, 3, 4, 5, 6, 7, 8.

async statusdictionary()[source]

Sets the status as a dictionary memeber of the class from the outlets of the real switch. Receives the data from the switch by the ‘get’ method as a json.

async verify(outlets)[source]

Verifies if we can reach the switch by the “get” method. Also compares the outlet lists with the configuration, and returns true if it’s identical.

Parameters

outlets – list of Outlet objects defined on /switch/outlet.py each Oulet object indicates one of eight outlets of the dli power switch.

Powerswitch

class lvmnps.switch.dli.powerswitch.PowerSwitch(name, config, log)[source]

Bases: lvmnps.switch.powerswitchbase.PowerSwitchBase

Powerswitch class inherited from the PowerSwitchBase class, the middle library to parse commands from the actor to the Dli class.

Parameters
  • name (str) – A name identifying the power switch. ‘DLI Controller’ for Dli switch

  • config ([]) – The configuration defined on the .yaml file under /etc/lvmnps_dli.yml

  • log (sdsstools.logger.SDSSLogger) – The logger for logging

async isReachable()[source]

Check if the Power switch is reachable by the verify method which is the member of Dli class.

async start()[source]

Adds the client controlling the DLI Power Switch. Checks if the Power switch is reachable. If the Power switch is reachable, updates the data of Outlet objects.

async stop()[source]

Closes the connection with the httpx client.

async switch(state, outlets)[source]

Controls the switch (Turning on or off)

Parameters
  • state – the destination of the state that each outlet will be changed. the type is bool. (True/False)

  • outlets – list of Outlet objects defined on /switch/outlet.py each Oulet object indicates one of eight outlets of the dli power switch

async update(outlets)[source]

Updates the data based on the received status dictionary from the Dli class.

Parameters

outlets – list of Outlet objects defined on /switch/outlet.py each Oulet object indicates one of eight outlets of the dli power switch

iboot

iboot

Powerswitch