API¶
Base client¶
- class lvmnps.nps.core.NPSClient[source]¶
Bases:
ABCBase NPS client.
- async cycle(outlets, delay=3) list[OutletModel][source]¶
Turns off the selected outlets and turns them on again after a delay.
- Parameters:
outlets (
Union[OutletModel,int,str,Sequence[str|int|OutletModel]]) – An outlet or list of outlets whose state will be set. An outlet can be specified by its name, number, or model instance.delay (
float) – Number of seconds the code will wait before turning on the outlets again.
- Return type:
- async set_state(outlets, on=False, off_after=None) list[OutletModel][source]¶
Sets the state of an outlet or list of outlets.
- Parameters:
outlets (
Union[OutletModel,int,str,Sequence[str|int|OutletModel]]) – An outlet or list of outlets whose state will be set. An outlet can be specified by its name, number, or model instance. If a list of outlet is provided the behaviour will depend on the client implementation. Outlets may be switched concurrently or sequentially, with a delay to avoid in-rush currents.on (
bool) – Whether to turn the outlet on (ifTrue) or off.off_after (
float|None) – Turns off the outlet after the specified number of seconds. Only relevant ifon=True.
- Return type:
Implementations¶
Digital Loggers Inc¶
- class lvmnps.nps.implementations.dli.DLIClient(*args, **kwargs) None[source]¶
Bases:
NPSClientAn NPS client for a Digital Loggers switch.
- async list_running_scripts() dict[int, str][source]¶
Returns a mapping of running thread number to script name.
- pydantic model lvmnps.nps.implementations.dli.DLIOutletModel[source]¶
Bases:
OutletModelA model for a DLI outlet status.
- Config:
arbitrary_types_allowed: bool = True
- Fields:
- field critical: bool = False¶
- field cycle_delay: float | None = None¶
- field index: int = 0¶
- field locked: bool = False¶
- field physical_state: bool = False¶
- field transient_state: bool = False¶
NetIO¶
- class lvmnps.nps.implementations.netio.NetIOClient(*args, **kwargs) None[source]¶
Bases:
NPSClientAn NPS client for a NetIO switch.
This implementation uses the JSON API, see https://www.netio-products.com/files/NETIO-M2M-API-Protocol-JSON.pdf
Actor¶
Tools¶
- class lvmnps.tools.APIClient(*args, **kwargs) None[source]¶
Bases:
objectA wrapper around
httpx.AsyncClientto yield a new client.
- lvmnps.tools.get_outlet_by_id(outlet_data, id)[source]¶
Gets an outlet by id.
- Parameters:
outlet_data (
dict[str,OutletModel]) – The mapping of outlet name to outlet model data.id (
int) – The id of the outlet to retrieve.
- Returns:
The outlet matching the id.
- Return type:
outlet
- Raises:
ValueError – If the outlet cannot be found.
- lvmnps.tools.get_outlet_by_name(outlet_data, name)[source]¶
Gets an outlet from a list of outlets.
- Parameters:
outlet_data (
dict[str,OutletModel]) – The mapping of outlet name to outlet model data.name (
str) – The name of the outlet to retrieve.
- Returns:
The outlet matching the input name.
- Return type:
outlet
- Raises:
ValueError – If the outlet cannot be found.