-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
30 additions
and
0 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
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) |
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 @@ | ||
from .UponorJnap import UponorJnap |