Async version of apcaccess library implemented in python.
Project description
aioapcaccess
An async implementation of apcaccess. This library provides programmatic access to the status information provided by apcupsd over its Network Information Server (NIS) which usually listens on TCP port 3551.
This project is a re-implementation of the synchronous version flyte/apcaccess using asyncio, where a lot of the logic is borrowed and improved.
Install
Install with pip:
$ pip install aioapcaccess
Usage
The primary API for getting the status from APCUPS is aioapcaccess.request_status
.
It returns a collections.OrderedDict
mapping from field names (e.g., "SERIALNO") to
their values in string format. What fields are available will depend on the model of
your APC UPS, see APCUPSD manual for details.
The following example shows a typical usage of aioapcaccess
import asyncio
import aioapcaccess
async def main():
result = await aioapcaccess.request_status(host='localhost', port=3551)
print(result)
if __name__ == '__main__':
asyncio.run(main())
The example above will print the following (prettified and simplified):
OrderedDict([
('APC', '001,036,0879'),
...,
('BATTV', '13.7 Volts'),
('CUMONBATT', '0 Seconds')
))])
In addition to request_status
, we offer the following functions for advanced uses:
aioapcaccess.request_raw_status
for getting raw (unparsed) status inbytes
.aioapcaccess.parse_raw_status
for parsing thebytes
to the dict shown above.aioapcaccess.split_unit
for splitting the supported unit suffix from the value strings, returning a tuple(value, unit)
. You can checkaioapcaccess.UNITS
for the set of supported units. Note that units are also in the forms of strings (e.g., "Seconds", "Volts"). If no valid units are found in the value strings,unit
will beNone
.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file aioapcaccess-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: aioapcaccess-0.3.0-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7bc5be0a0166e137f151c8e25c8ff810b74ee86907dfad846cf9d33cf3ac093c |
|
MD5 | 00f18aa426ddccf7f503858565649422 |
|
BLAKE2b-256 | 5b1e3ee51c1ddf2e783ba01719eee24d1339e4d955a7ed6aa6ec471f41626e14 |