From cbf2f91d967a3c5dc8ff62377de6be28117d305b Mon Sep 17 00:00:00 2001 From: Arjen Bos <1064589+arjenbos@users.noreply.github.com> Date: Sun, 29 Oct 2023 10:59:58 +0100 Subject: [PATCH] Add tests for the API and default responses --- tests/fixtures/gateway_api_allmodules.json | 222 ++++++++++++++++ tests/fixtures/gateway_api_dbmodules.json | 280 +++++++++++++++++++++ tests/test_api.py | 24 ++ 3 files changed, 526 insertions(+) create mode 100644 tests/fixtures/gateway_api_allmodules.json create mode 100644 tests/fixtures/gateway_api_dbmodules.json create mode 100644 tests/test_api.py diff --git a/tests/fixtures/gateway_api_allmodules.json b/tests/fixtures/gateway_api_allmodules.json new file mode 100644 index 0000000..b32e41e --- /dev/null +++ b/tests/fixtures/gateway_api_allmodules.json @@ -0,0 +1,222 @@ +{ + "success": true, + "message": "", + "loginRejected": false, + "modules": { + "count": "21", + "rooms": { + "1": { + "name": "Room 1", + "minTemperature": 18, + "maxTemperature": 28, + "modules": { + "00020DB7C9C5804": { + "id": "00020DB7C9C5804", + "status": 0, + "type": "sensor", + "number": 0, + "batteryStatus": 76, + "moduleInstance": "0" + }, + "03050DB7C9C5812": { + "id": "03050DB7C9C5812", + "status": 0, + "type": "floor", + "number": 2, + "batteryStatus": 127, + "moduleInstance": "3" + }, + "04050DB7C9C5812": { + "id": "04050DB7C9C5812", + "status": 0, + "type": "floor", + "number": 3, + "batteryStatus": 127, + "moduleInstance": "4" + } + } + }, + "2": { + "name": "Room 2", + "minTemperature": 18, + "maxTemperature": 28, + "modules": { + "00020DB7C9C5807": { + "id": "00020DB7C9C5807", + "status": 0, + "type": "sensor", + "number": 0, + "batteryStatus": 100, + "moduleInstance": "0" + }, + "01050DB7C9C580A": { + "id": "01050DB7C9C580A", + "status": 0, + "type": "floor", + "number": 1, + "batteryStatus": 127, + "moduleInstance": "1" + }, + "02050DB7C9C580A": { + "id": "02050DB7C9C580A", + "status": 0, + "type": "floor", + "number": 2, + "batteryStatus": 127, + "moduleInstance": "2" + }, + "03050DB7C9C580A": { + "id": "03050DB7C9C580A", + "status": 0, + "type": "floor", + "number": 3, + "batteryStatus": 127, + "moduleInstance": "3" + }, + "04050DB7C9C580A": { + "id": "04050DB7C9C580A", + "status": 0, + "type": "floor", + "number": 4, + "batteryStatus": 127, + "moduleInstance": "4" + } + } + }, + "3": { + "name": "Room 3", + "minTemperature": 18, + "maxTemperature": 28, + "modules": { + "00020DB7C9C5806": { + "id": "00020DB7C9C5806", + "status": 0, + "type": "sensor", + "number": 0, + "batteryStatus": 66, + "moduleInstance": "0" + }, + "01050DB7C9C580C": { + "id": "01050DB7C9C580C", + "status": 0, + "type": "floor", + "number": 1, + "batteryStatus": 127, + "moduleInstance": "1" + }, + "02050DB7C9C580C": { + "id": "02050DB7C9C580C", + "status": 0, + "type": "floor", + "number": 2, + "batteryStatus": 127, + "moduleInstance": "2" + } + } + }, + "4": { + "name": "Room 4", + "minTemperature": 18, + "maxTemperature": 28, + "modules": { + "00020DB7C9C580F": { + "id": "00020DB7C9C580F", + "status": 2, + "type": "sensor", + "number": 0, + "batteryStatus": 126, + "moduleInstance": "0" + }, + "04050DB7C9C580C": { + "id": "04050DB7C9C580C", + "status": 0, + "type": "floor", + "number": 1, + "batteryStatus": 127, + "moduleInstance": "4" + }, + "05050DB7C9C580C": { + "id": "05050DB7C9C580C", + "status": 0, + "type": "floor", + "number": 2, + "batteryStatus": 127, + "moduleInstance": "5" + } + } + }, + "5": { + "name": "Room 5", + "minTemperature": 18, + "maxTemperature": 28, + "modules": { + "00020DB7C9C5805": { + "id": "00020DB7C9C5805", + "status": 0, + "type": "sensor", + "number": 0, + "batteryStatus": 68, + "moduleInstance": "0" + }, + "03050DB7C9C580C": { + "id": "03050DB7C9C580C", + "status": 0, + "type": "floor", + "number": 1, + "batteryStatus": 127, + "moduleInstance": "3" + } + } + }, + "6": { + "name": "Room 6", + "minTemperature": 18, + "maxTemperature": 28, + "modules": { + "00020DB7C9C580D": { + "id": "00020DB7C9C580D", + "status": 0, + "type": "sensor", + "number": 0, + "batteryStatus": 74, + "moduleInstance": "0" + }, + "02050DB7C9C5812": { + "id": "02050DB7C9C5812", + "status": 0, + "type": "floor", + "number": 1, + "batteryStatus": 127, + "moduleInstance": "2" + }, + "05050DB7C9C5812": { + "id": "05050DB7C9C5812", + "status": 0, + "type": "floor", + "number": 2, + "batteryStatus": 127, + "moduleInstance": "5" + }, + "06050DB7C9C5812": { + "id": "06050DB7C9C5812", + "status": 0, + "type": "floor", + "number": 3, + "batteryStatus": 127, + "moduleInstance": "6" + }, + "01050DB7C9C5812": { + "id": "01050DB7C9C5812", + "status": 0, + "type": "floor", + "number": 4, + "batteryStatus": 127, + "moduleInstance": "1" + } + } + } + } + }, + "language": "en", + "performance": 0.75 +} \ No newline at end of file diff --git a/tests/fixtures/gateway_api_dbmodules.json b/tests/fixtures/gateway_api_dbmodules.json new file mode 100644 index 0000000..2a52b43 --- /dev/null +++ b/tests/fixtures/gateway_api_dbmodules.json @@ -0,0 +1,280 @@ +{ + "success": true, + "message": "", + "loginRejected": false, + "modules": { + "00020DB7C9C5804": { + "id": 3, + "deviceid": "00020DB7C9C5804", + "nodeid": "4", + "name": "Room 1", + "room": "Room 1", + "currentTemperature": 21.1, + "battery": 76, + "isFailed": false, + "lastResponse": 1698499773000, + "interviewDone": true, + "vendorId": 380, + "productId": 2, + "type": "sensor" + }, + "00020DB7C9C5805": { + "id": 4, + "deviceid": "00020DB7C9C5805", + "nodeid": "5", + "name": "Room 5", + "room": "Room 5", + "currentTemperature": 21.9, + "battery": 68, + "isFailed": false, + "lastResponse": 1698499513000, + "interviewDone": true, + "vendorId": 380, + "productId": 2, + "type": "sensor" + }, + "00020DB7C9C5806": { + "id": 5, + "deviceid": "00020DB7C9C5806", + "nodeid": "6", + "name": "Room 3", + "room": "Room 3", + "currentTemperature": 21.9, + "battery": 66, + "isFailed": false, + "lastResponse": 1698496669000, + "interviewDone": true, + "vendorId": 380, + "productId": 2, + "type": "sensor" + }, + "00020DB7C9C5807": { + "id": 6, + "deviceid": "00020DB7C9C5807", + "nodeid": "7", + "name": "Room 2", + "room": "Room 2", + "currentTemperature": 22.7, + "battery": 100, + "isFailed": false, + "lastResponse": 1698499739000, + "interviewDone": true, + "vendorId": 380, + "productId": 2, + "type": "sensor" + }, + "00050DB7C9C580A": { + "id": 9, + "deviceid": "00050DB7C9C580A", + "nodeid": "10", + "name": "Verdeler 1e", + "room": "", + "currentTemperature": "off", + "battery": "off", + "binarySwitch": false, + "isFailed": false, + "lastResponse": 1698499638000, + "interviewDone": true, + "vendorId": 380, + "productId": 3, + "type": "floor", + "instances": [ + { + "instance": "1", + "room": 0, + "status": false + }, + { + "instance": "2", + "room": 0, + "status": false + }, + { + "instance": "3", + "room": 0, + "status": false + }, + { + "instance": "4", + "room": 0, + "status": false + }, + { + "instance": "5", + "room": 0, + "status": false + }, + { + "instance": "6", + "room": 0, + "status": false + }, + { + "instance": "7", + "room": 0, + "status": false + }, + { + "instance": "8", + "room": 0, + "status": false + } + ] + }, + "00050DB7C9C580C": { + "id": 12, + "deviceid": "00050DB7C9C580C", + "nodeid": "12", + "name": "Verdeler 2e", + "room": "", + "currentTemperature": "off", + "battery": "off", + "binarySwitch": false, + "isFailed": false, + "lastResponse": 1698499592000, + "interviewDone": true, + "vendorId": 380, + "productId": 3, + "type": "floor", + "instances": [ + { + "instance": "1", + "room": 0, + "status": false + }, + { + "instance": "2", + "room": 0, + "status": false + }, + { + "instance": "3", + "room": 0, + "status": true + }, + { + "instance": "4", + "room": 0, + "status": true + }, + { + "instance": "5", + "room": 0, + "status": true + }, + { + "instance": "6", + "room": 0, + "status": false + }, + { + "instance": "7", + "room": 0, + "status": false + }, + { + "instance": "8", + "room": 0, + "status": false + } + ] + }, + "00020DB7C9C580D": { + "id": 14, + "deviceid": "00020DB7C9C580D", + "nodeid": "13", + "name": "Room 6", + "room": "Room 6", + "currentTemperature": 22, + "battery": 74, + "isFailed": false, + "lastResponse": 1698499411000, + "interviewDone": true, + "vendorId": 380, + "productId": 2, + "type": "sensor" + }, + "00020DB7C9C580F": { + "id": 16, + "deviceid": "00020DB7C9C580F", + "nodeid": "15", + "name": "Room 4", + "room": "Room 4", + "currentTemperature": "unknown", + "battery": "unknown", + "isFailed": false, + "lastResponse": 1698412444000, + "interviewDone": true, + "vendorId": 380, + "productId": 2, + "type": "sensor" + }, + "00050DB7C9C5812": { + "id": 19, + "deviceid": "00050DB7C9C5812", + "nodeid": "18", + "name": "Verdeler BG", + "room": "", + "currentTemperature": "off", + "battery": "off", + "binarySwitch": false, + "isFailed": false, + "lastResponse": 1698499603000, + "interviewDone": true, + "vendorId": 380, + "productId": 3, + "type": "floor", + "instances": [ + { + "instance": "1", + "room": 0, + "status": false + }, + { + "instance": "2", + "room": 0, + "status": false + }, + { + "instance": "3", + "room": 0, + "status": false + }, + { + "instance": "4", + "room": 0, + "status": false + }, + { + "instance": "5", + "room": 0, + "status": false + }, + { + "instance": "6", + "room": 0, + "status": false + }, + { + "instance": "7", + "room": 0, + "status": true + }, + { + "instance": "8", + "room": 0, + "status": true + } + ] + } + }, + "currentTime": 1698499793476, + "controllerState": "zway_controller_state_idle", + "reorganization": { + "startTime": 1698499755300, + "running": true, + "duration": 2700000 + }, + "language": "en", + "performance": 0.138 +} \ No newline at end of file diff --git a/tests/test_api.py b/tests/test_api.py new file mode 100644 index 0000000..cb2bfed --- /dev/null +++ b/tests/test_api.py @@ -0,0 +1,24 @@ +from custom_components.alpha_innotec.api import BaseAPI +from . import VALID_CONFIG + + +def test_encode_signature(): + api = BaseAPI( + VALID_CONFIG["controller_ip"], + VALID_CONFIG["controller_username"], + VALID_CONFIG["controller_password"] + ) + + assert api.encode_signature("test", + "test3") == b'^\x0cm\xb4\xbf`E\xf5\xbd\x83\xf9q\xc9\x80\x80\xee\xf1O<\xab\x83\x04\xca\xd6\x9d\x92\xec\x1d\xb3\xea\x1a\x8b\x85\xb7x\xb51\xea\x86%\x021\xc4G\xba\x05y\xd0\xb9\n\xf6\xb9\xc3$y\x16Hn\xeeR\x16\xb1j\x9d' + + +def test_decrypt2(): + api = BaseAPI( + VALID_CONFIG["controller_ip"], + VALID_CONFIG["controller_username"], + VALID_CONFIG["controller_password"] + ) + + assert api.decrypt2("W9UIefCF9T7jQGmagrhsJPEldxM5iher+CSAIvbas84=", + "verysafepassword") == "df0f44b7163b034b91710724938af864"