Skip to content
Merged
32 changes: 32 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Python package

on: [push]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
3 changes: 1 addition & 2 deletions PyViCare/PyViCare.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ def wrapper(*args, **kwargs):
# DEPRECATED
class ViCareSession(GazBoiler):
def dummy(self):
print("done")

print("done")
5 changes: 2 additions & 3 deletions PyViCare/PyViCareCachedService.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from datetime import datetime
import threading
from PyViCare.PyViCareService import apiURLBase, ViCareService
from PyViCare.PyViCareService import apiURLBase, ViCareService, readFeature

class ViCareCachedService(ViCareService):

Expand All @@ -25,5 +25,4 @@ def getProperty(self,property_name):
self.lock.release()

entities = self.cache["entities"]
feature = next((f for f in entities if f["class"][0] == property_name and f["class"][1] == "feature"), {})
return feature
return readFeature(entities, property_name)
6 changes: 4 additions & 2 deletions PyViCare/PyViCareDevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Device:
"""

# TODO cirtcuit management should move at method level
def __init__(self, username, password,token_file=None,circuit=0,cacheDuration=0):
def __init__(self, username, password,token_file=None,circuit=0,cacheDuration=0,customService=None):
"""Init function. Create the necessary oAuth2 sessions
Parameters
----------
Expand All @@ -45,7 +45,9 @@ def __init__(self, username, password,token_file=None,circuit=0,cacheDuration=0)
-------
"""

if cacheDuration == 0:
if customService is not None:
self.service = customService
elif cacheDuration == 0:
self.service = ViCareService(username, password, token_file, circuit)
else:
self.service = ViCareCachedService(username, password, cacheDuration, token_file, circuit)
Expand Down
7 changes: 7 additions & 0 deletions PyViCare/PyViCareService.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
logger = logging.getLogger('ViCare')
logger.addHandler(logging.NullHandler())


def readFeature(entities, property_name):
feature = next((f for f in entities if f["class"][0] == property_name and f["class"][1] == "feature"), {})
return feature

# https://api.viessmann-platform.io/general-management/v1/installations/DDDDD gives the type like VitoconnectOptolink
# entities / "deviceType": "heating"
# entities are connected devices
Expand Down Expand Up @@ -240,3 +245,5 @@ def getProperty(self,property_name):
def setProperty(self,property_name,action,data):
url = apiURLBase + '/operational-data/v1/installations/' + str(self.id) + '/gateways/' + str(self.serial) + '/devices/0/features/' + property_name +"/"+action
return self.__post(url,data)


32 changes: 32 additions & 0 deletions tests/ViCareServiceForTesting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import simplejson as json
import os
from PyViCare.PyViCareService import ViCareService, readFeature

class ViCareServiceForTesting(ViCareService):

def __init__(self, filename, circuit, rawInput = None):
if rawInput is None:
test_filename = os.path.join(os.path.dirname(__file__), filename)
try:
json_file = open(test_filename, mode='rb')
testData = json.load(json_file)
finally:
json_file.close()
self.testData = testData
else:
self.testData = rawInput

self.circuit = circuit
self.setPropertyData = []

def getProperty(self, property_name):
entities = self.testData["entities"]
return readFeature(entities, property_name)

def setProperty(self, property_name, action, data):
self.setPropertyData.append({
"property_name": property_name,
"action" : action,
"data" : data
})

4 changes: 4 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import unittest

if __name__ == '__main__':
unittest.main()
Loading