Skip to content

Commit

Permalink
feat: Expose error messages (#448)
Browse files Browse the repository at this point in the history
* Update PyViCareDevice.py

* Create device_error.json

* Create test_device_error.py

* Update PyViCareDevice.py

* Update test_device_error.py

* Update PyViCareDevice.py

* Rename tests/response/device_error.json to tests/response/deviceerrors/F.1100.json

* Update test_device_error.py
  • Loading branch information
CFenner authored Nov 20, 2024
1 parent af4154c commit 60b0337
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
6 changes: 6 additions & 0 deletions PyViCare/PyViCareDevice.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Any

from PyViCare.PyViCareService import ViCareService
from PyViCare.PyViCareUtils import PyViCareNotSupportedFeatureError, handleNotSupported

Expand All @@ -16,6 +18,10 @@ def __init__(self, service: ViCareService) -> None:
def getSerial(self):
return self.service.getProperty("device.serial")["properties"]["value"]["value"]

@handleNotSupported
def getDeviceErrors(self) -> list[Any]:
return list[Any](self.service.getProperty("device.messages.errors.raw")["properties"]["entries"]["value"])

def isLegacyDevice(self) -> bool:
return self.service.hasRoles(["type:legacy"])

Expand Down
38 changes: 38 additions & 0 deletions tests/response/deviceerrors/F.1100.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"data": [
{
"apiVersion": 1,
"commands": {},
"deviceId": "0",
"feature": "device.messages.errors.raw",
"gatewayId": "################",
"isEnabled": true,
"isReady": true,
"properties": {
"entries": {
"type": "array",
"value": [
{
"accessLevel": "customer",
"audiences": [
"IS-SUPPLIER",
"IS-DEVELOPMENT",
"IS-MANUFACTURING",
"IS-AFTERSALES",
"IS-AFTERMARKET",
"IS-DEVELOPER-VEG",
"IS-BIG-DATA",
"IS-MANUFACTURING-VEG"
],
"errorCode": "F.1100",
"priority": "criticalError",
"timestamp": "2000-07-22T20:37:44.000Z"
}
]
}
},
"timestamp": "2024-10-30T08:53:23.913Z",
"uri": "https://api.viessmann.com/iot/v1/features/installations/#######/gateways/################/devices/0/features/device.messages.errors.raw"
}
]
}
16 changes: 16 additions & 0 deletions tests/test_device_error.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import unittest

from PyViCare.PyViCareDevice import Device
from tests.ViCareServiceMock import ViCareServiceMock


class DeviceErrorTest(unittest.TestCase):
def setUp(self):
self.service = ViCareServiceMock('response/deviceerrors/F.1100.json')
self.device = Device(self.service)

def test_deviceErrors(self):
errors = self.device.getDeviceErrors()
self.assertEqual(len(errors), 1)
self.assertEqual(errors[0]["errorCode"], "F.1100")
self.assertEqual(errors[0]["priority"], "criticalError")

0 comments on commit 60b0337

Please sign in to comment.