Skip to content

Commit

Permalink
feat: expose raw data of installations, gatways and devices (openvies…
Browse files Browse the repository at this point in the history
…s#212)

* feat: expose raw data of installations, gatways and devices

* fmt

* extract devices via new properties
  • Loading branch information
woehrl01 authored Oct 7, 2021
1 parent 2ca21b7 commit 85edfd6
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 17 deletions.
46 changes: 29 additions & 17 deletions PyViCare/PyViCare.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from datetime import datetime

from PyViCare.PyViCareAbstractOAuthManager import AbstractViCareOAuthManager
from PyViCare.PyViCareBrowserOAuthManager import ViCareBrowserOAuthManager
Expand Down Expand Up @@ -45,27 +46,38 @@ def __loadInstallations(self):
logger.error("Missing 'data' property when fetching installations")
raise PyViCareInvalidDataError(installations)

self.devices = list(self.__readInstallations(installations["data"]))
data = installations['data']
self.installations = Wrap(data)
self.devices = list(self.__extract_devices())

def __readInstallations(self, data):
for installation in data:
installation_id = installation["id"]

for gateway in installation["gateways"]:
gateway_serial = gateway["serial"]

for device in gateway["devices"]:
if device["deviceType"] != "heating":
def __extract_devices(self):
for installation in self.installations:
for gateway in installation.gateways:
for device in gateway.devices:
if device.deviceType != "heating":
continue # we are not interested in non heating devices

device_id = device["id"]
device_model = device["modelId"]
status = device["status"]

accessor = ViCareDeviceAccessor(
installation_id, gateway_serial, device_id)
installation.id, gateway.serial, device.id)
service = self.__buildService(accessor)

logger.info(f"Device found: {device_model}")
logger.info(f"Device found: {device.modelId}")

yield PyViCareDeviceConfig(service, device.modelId, device.status)


class DictWrap(object):
def __init__(self, d):
for k, v in d.items():
setattr(self, k, Wrap(v))


yield PyViCareDeviceConfig(service, device_model, status)
def Wrap(v):
if isinstance(v, list):
return [Wrap(x) for x in v]
if isinstance(v, dict):
return DictWrap(v)
if isinstance(v, str) and len(v) == 24 and v[23] == 'Z' and v[10] == 'T':
return datetime.strptime(v, '%Y-%m-%dT%H:%M:%S.%f%z')
else:
return v
15 changes: 15 additions & 0 deletions tests/test_Integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,21 @@ def test_PyViCare(self):

print()

for i in vicare.installations:
print(i.id)
print(i.description)
print(i.address.street)
print()
for g in i.gateways:
print(g.producedAt)
print(g.autoUpdate)
print(g.aggregatedStatus)
print(g.registeredAt)
print()
for d in g.devices:
print(d.modelId)
print(d.createdAt)

@unittest.skipIf(not EXEC_INTEGRATION_TEST, "environments needed")
def test_Dump(self):
email = os.getenv('PYVICARE_EMAIL', '')
Expand Down

0 comments on commit 85edfd6

Please sign in to comment.