From 60b0337acd908fc1a95bb32f311698dcd99b7c00 Mon Sep 17 00:00:00 2001 From: Christopher Fenner <9592452+CFenner@users.noreply.github.com> Date: Wed, 20 Nov 2024 07:39:37 +0100 Subject: [PATCH] feat: Expose error messages (#448) * 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 --- PyViCare/PyViCareDevice.py | 6 ++++ tests/response/deviceerrors/F.1100.json | 38 +++++++++++++++++++++++++ tests/test_device_error.py | 16 +++++++++++ 3 files changed, 60 insertions(+) create mode 100644 tests/response/deviceerrors/F.1100.json create mode 100644 tests/test_device_error.py diff --git a/PyViCare/PyViCareDevice.py b/PyViCare/PyViCareDevice.py index 4e67c530..e9085a9e 100644 --- a/PyViCare/PyViCareDevice.py +++ b/PyViCare/PyViCareDevice.py @@ -1,3 +1,5 @@ +from typing import Any + from PyViCare.PyViCareService import ViCareService from PyViCare.PyViCareUtils import PyViCareNotSupportedFeatureError, handleNotSupported @@ -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"]) diff --git a/tests/response/deviceerrors/F.1100.json b/tests/response/deviceerrors/F.1100.json new file mode 100644 index 00000000..9491ac45 --- /dev/null +++ b/tests/response/deviceerrors/F.1100.json @@ -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" + } + ] +} diff --git a/tests/test_device_error.py b/tests/test_device_error.py new file mode 100644 index 00000000..cb22e218 --- /dev/null +++ b/tests/test_device_error.py @@ -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")