Skip to content

Commit

Permalink
Initial library
Browse files Browse the repository at this point in the history
  • Loading branch information
asev committed May 3, 2020
1 parent 421c400 commit 16e9203
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
29 changes: 29 additions & 0 deletions UponorJnap/UponorJnap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import requests


class UponorJnap:
def __init__(self, host):
self.url = "http://" + host + "/JNAP/"

def get_data(self):
r = requests.post(url=self.url, headers={"x-jnap-action": "http://phyn.com/jnap/uponorsky/GetAttributes"},
data='{}')
data = r.json()

variables = {}
for var in data['output']['vars']:
variables[var['waspVarName']] = var['waspVarValue']
return variables

def send_data(self, data):
items = []
for k, v in data.items():
items.append('{"waspVarName": "' + k + '","waspVarValue": "' + str(v) + '"}')
payload = '{"vars": [' + ','.join(items) + ']}'

r = requests.post(url=self.url, headers={"x-jnap-action": "http://phyn.com/jnap/uponorsky/SetAttributes"},
data=payload)
r_json = r.json()

if 'result' in r_json and not r_json['result'] == 'OK':
raise ValueError(r_json)
1 change: 1 addition & 0 deletions UponorJnap/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .UponorJnap import UponorJnap

0 comments on commit 16e9203

Please sign in to comment.