Switch#
- class lvmnps.switch.powerswitchbase.PowerSwitchBase(name, config, log=None)[source]#
Bases:
objectPowerSwitchBase class for multiple power switches from different manufacturers.
The Powerswitch classes will inherit from the
PowerSwitchBaseclass.- Parameters
- collectOutletsByNameAndPort(name=None, portnum=None)[source]#
Collects the outlet by the name and ports, comparing with the name and ports from the Outlet object.
- config_get(key, default=None)[source]#
Read the configuration and extract the data as a structure that we want.
Notice: DOESN’T 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.descto 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.
- async setState(state, name=None, portnum=None)[source]#
Set the state of the Outlet instance to On/Off. (On = 1, Off = 0).
Note that dependending on the values passed to
nameandportnum, multiple outlets may be commanded.
- abstract async start()[source]#
Starts the switch instance, potentially connecting to the device server.
- abstract async switch(state, outlets)[source]#
Changes the state of an outlet.
- Parameters
state (int) – The final state for the outlets. 0: off, 1: on.
outlets (list[lvmnps.switch.outlet.Outlet]) – A list of
Outletswhich status will be updated.
- class lvmnps.switch.outlet.Outlet(switch, name, portnum, description=None, state=0)[source]#
Bases:
objectOutlet class to manage the power switch.
- Parameters
switch (PowerSwitchBase) – The parent
PowerSwitchBaseinstance to which this outlet is associated with.name (str) – The name of the outlet.
portnum (int) – The number of the port.
description (str | None) – The description about the outlet.
state (int) – The state of the outlet (on: 1, off: 0).
- class lvmnps.switch.dli.dli.DLI(hostname, user, password, name=None, log=None, onoff_timeout=3)[source]#
Bases:
objectPowerswitch class to manage the DLI power switch.
- Parameters
hostname (str) – The hostname from the configuration (the IP address for connection).
user (str) – The username from the configuration (the id for login).
password (str) – The password from the configuration (the password for login).
name (str | None) – The name of the DLI Controller.
log (SDSSLogger | None) – The logger for logging.
onoff_timeout – The timeout, in seconds, before failing an on/off command.
- add_client(password)[source]#
Add the
httpx.AsyncClientto the DLI object.- Parameters
password (str) –
- async off(outlet=0)[source]#
Turn off the power to the outlet.
Set the value of the outlet state by using a PUT request. Note that the outlets in the RESTful API are zero-indexed.
- Parameters
outlet – The number indicating the outlet (1-indexed).
- async on(outlet=0)[source]#
Turn on the power to the outlet.
Set the value of the outlet state by using a PUT request. Note that the outlets in the RESTful API are zero-indexed.
- Parameters
outlet (int) – The number indicating the outlet (1-indexed).
- class lvmnps.switch.dli.powerswitch.DLIPowerSwitch(name, config, log=None)[source]#
Bases:
lvmnps.switch.powerswitchbase.PowerSwitchBaseA DLI power switch.
- Parameters
- 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.