-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from twrecked/alpha-02
Alpha 02
- Loading branch information
Showing
11 changed files
with
787 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
0.1.0a2: | ||
add example docker | ||
0.1.0a1: | ||
Initial commit. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
{ | ||
"domain": "pwrstat", | ||
"name": "Cyberpower/pwrstat-api UPS Support", | ||
"name": "pwrstat (Cyberpower cli) Support", | ||
"codeowners": [ | ||
"@twrecked" | ||
], | ||
"config_flow": true, | ||
"dependencies": [ | ||
], | ||
"documentation": "https://github.com/twrecked/hass-aarlo/blob/master/README.md", | ||
"documentation": "https://github.com/twrecked/hass-pwrstat/blob/main/README.md", | ||
"iot_class": "local_polling", | ||
"issue_tracker": "https://github.com/twrecked/hass-aarlo/issues", | ||
"issue_tracker": "https://github.com/twrecked/hass-pwrstat/issues", | ||
"requirements": [ | ||
], | ||
"version": "0.1.0a1" | ||
"version": "0.1.0a2" | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# PowerPanel (pwrstat) API | ||
|
||
This is a very simple REST API that wraps the PowerPanel pwrstat application for CyberPower battery backups. Only basic GET support for a single JSON object response for all parameters of the UPS are implemented. | ||
|
||
# Usage | ||
|
||
- Clone GitHub repo to local computer. | ||
- Must have Linux PowerPanel application from CyberPower already downloaded (https://www.cyberpowersystems.com/product/software/powerpanel-for-linux/) | ||
- Place powerpanel_ver_amd64.deb OR PPL-*-64bit.deb (newer) file downloaded from above address in the folder containing this README, on your local computer. | ||
- Run Docker build, or use included Docker-Compose example. | ||
- Note that you cannot use this GitHub repo as a Docker-Compose build context, due to needing to download a local copy of the CyberPower binary. | ||
- Access JSON response at http://<docker host IP>:5002/pwrstat | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# The file I use. | ||
# HOME_NAME comes from the command line or .env | ||
# All the Cyberpower utilities are linked in from the outside. | ||
version: '2.1' | ||
services: | ||
ups-status: | ||
container_name: ${HOME_NAME}-ups-status | ||
image: ups-status | ||
network_mode: host | ||
restart: always | ||
volumes: | ||
- /etc/localtime:/etc/localtime:ro | ||
- /usr/sbin/pwrstat:/usr/sbin/pwrstat:ro | ||
- /var/pwrstatd.ipc:/var/pwrstatd.ipc:ro | ||
- /var/pwrstatd.dev:/var/pwrstatd.dev:ro | ||
build: | ||
context: . | ||
dockerfile: dockerfile | ||
logging: | ||
options: | ||
max-size: 5m | ||
max-file: "3" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM python:3 | ||
|
||
VOLUME /src | ||
COPY pwrstat-api.py requirements.txt init.sh /src/ | ||
WORKDIR /src | ||
RUN chmod +x /src/init.sh | ||
RUN chmod +x /src/pwrstat-api.py | ||
RUN pip install --trusted-host pypi.python.org -r requirements.txt | ||
ENTRYPOINT "/src/init.sh" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
/src/pwrstat-api.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from flask import Flask, request | ||
from flask_restful import Resource, Api | ||
from json import dumps | ||
from flask_jsonpify import jsonify | ||
import subprocess | ||
|
||
app = Flask(__name__) | ||
api = Api(app) | ||
|
||
class pwrstat(Resource): | ||
def get(self): | ||
status = subprocess.Popen(['pwrstat', '-status'], stdout=subprocess.PIPE).communicate()[0].decode('utf-8') | ||
statusArr=[] | ||
statusDict={} | ||
|
||
for line in status.splitlines(): | ||
line = line.lstrip() | ||
line = line.replace(". ",";") | ||
line = line.replace(".","") | ||
line = line.split(";") | ||
if len(line) > 1: | ||
statusArr.append(line) | ||
|
||
statusDict = {k[0]: k[1] for k in statusArr} | ||
|
||
return jsonify(statusDict) | ||
|
||
api.add_resource(pwrstat, '/pwrstat') # return all parameters | ||
|
||
if __name__ == '__main__': | ||
app.run(port=5002, host='0.0.0.0') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
flask | ||
flask_restful | ||
flask-jsonpify |