Skip to main content

Async version of apcaccess library implemented in python.

Project description

aioapcaccess

build codecov PyPI black GitHub

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 in bytes.
  • aioapcaccess.parse_raw_status for parsing the bytes 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 check aioapcaccess.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 be None.

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

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

aioapcaccess-0.4.1-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file aioapcaccess-0.4.1-py3-none-any.whl.

File metadata

File hashes

Hashes for aioapcaccess-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4b0f22d18389beadae8483050a4b6b14d34de5da2b8694a225d06e5b28d90ec8
MD5 36ca6cbac3b362b5140ea0ac8c303d84
BLAKE2b-256 1e4b10bdb3b66562bee9bd9d526fc342e637a377c88231b77e2c8553aa3eef27

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page