Skip to content

Commit

Permalink
Docs: added section on how to use the library
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Nov 24, 2023
1 parent 958691d commit 9c29f48
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

* Issue an NPS refresh before issuing any status.

### 📖 Documentation

* Added section on how to use the library.


## 1.0.1 - November 24, 2023

Expand Down
47 changes: 47 additions & 0 deletions docs/sphinx/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,52 @@ and then install using `poetry <https://python-poetry.org>`__
poetry install
Using the library
-----------------

To connect to an NPS, first import the switch client class (available implementations are `.DLIClient` and `.NetIOClient`) and instantiate them with the appropriate parameters. Then call `.NPSClient.setup` to initialise the connection and refresh the list of outlets.

.. code:: python
from lvmnps import DLIClient
client = DLIClient(host='127.0.0.1', port=8088, user='admin', password='admin')
await client.setup()
We can then retrieve the list of outlets and their status

.. code:: python
>>> client.outlets
{'argon': DLIOutletModel(id=1, name='Argon', normalised_name='argon', state=False, index=0, physical_state=False, transient_state=False, critical=False, locked=False, cycle_delay=None),
'neon': DLIOutletModel(id=2, name='Neon', normalised_name='neon', state=False, index=1, physical_state=False, transient_state=False, critical=False, locked=False, cycle_delay=None),
'ldls': DLIOutletModel(id=3, name='LDLS', normalised_name='ldls', state=False, index=2, physical_state=False, transient_state=False, critical=False, locked=False, cycle_delay=None),
'quartz': DLIOutletModel(id=4, name='Quartz', normalised_name='quartz', state=False, index=3, physical_state=False, transient_state=False, critical=False, locked=False, cycle_delay=None),
'hgne': DLIOutletModel(id=5, name='HgNe', normalised_name='hgne', state=False, index=4, physical_state=False, transient_state=False, critical=False, locked=False, cycle_delay=None),
'xenon': DLIOutletModel(id=6, name='Xenon', normalised_name='xenon', state=False, index=5, physical_state=False, transient_state=False, critical=False, locked=False, cycle_delay=None),
'outlet_7': DLIOutletModel(id=7, name='Outlet 7', normalised_name='outlet_7', state=False, index=6, physical_state=False, transient_state=False, critical=False, locked=False, cycle_delay=None),
'outlet8': DLIOutletModel(id=8, name='Outlet8', normalised_name='outlet8', state=False, index=7, physical_state=False, transient_state=False, critical=False, locked=False, cycle_delay=None)}
All outlets share some common attributes, including ``id`` (a numerical identifier), ``name``, ``normalised_name`` (a normalised version of the name, useful for programmatic access), and ``state`` (the current state of the outlet). Certain types of outlets may include additional parameters.

To retrieve an outlet by name or id ::

>>> client.get(5)
DLIOutletModel(id=5, name='HgNe', normalised_name='hgne', state=False, index=4, physical_state=False, transient_state=False, critical=False, locked=False, cycle_delay=None)

To refresh the internal state of the outlets you can issue ::

await client.refresh()

And to switch an outlet on or off ::

await client.set_state(5, on=True)
await client.set_state('hgne', on=False)

`.NPSClient.set_state` accepts either a single outlet (identifid by its name or id) or a list of outlets. In the latter case, the NPS implementation will try to switch on/off the outlets are quickly as possible while preventing in-rush overcurrent.


Configuration files
-------------------

Expand All @@ -54,6 +100,7 @@ To run as an actor, a YAML configuration file is required. An example of a valid
The ``actor`` section is common to other CLU actors, and we refer the reader to the `CLU documentation <https://clu.readthedocs.io/en/latest/getting-started.html#configuration-files>`__. An ``nps`` section is required, defining the type of the power supply (valid types are ``dli`` and ``netio``) and the parameters necessary to initialise the relevant client class.


Running the actor
-----------------

Expand Down

0 comments on commit 9c29f48

Please sign in to comment.