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.
Usage
The primary API for getting the status from APCUPS is aioapcaccess.request_status
.
It returns a collections.OrderedDict
from field name (e.g., "SERIALNO") to a tuple
(value, unit)
or (value, None)
if the value for a field does not have a unit
(e.g., "HOSTNAME"). Note:
-
Units are split from the raw string returned from APCUPSD, so they are also in the forms of strings (e.g., "Seconds", "Volts"). Check
aioapcaccess.UNITS
for the set of supported units. -
What fields are available will depend on the model of your APC UPS, see APCUPSD manual for details.
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', None)),
...,
('BATTV', ('13.7', 'Volts')),
('CUMONBATT', ('0', 'Seconds')
))])
In addition, we also offer the following functions:
aioapcaccess.request_raw_status
for getting raw (unparsed) status inbytes
.aioapcaccess.parse_raw_status
for parsing thebytes
to the dict shown above.
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
Hashes for aioapcaccess-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f48bf2ab2c26c1a947b12405e44af4901ae55a985aa2b3d5d85a629e676411a6 |
|
MD5 | a18cfd2f4f7eb735fb334b759daf0585 |
|
BLAKE2b-256 | 9bbf2c3f30972540c68a28db93461098a3a448c3b3450506a2ffeb00281aec65 |