From f8d1b446d3b74fb73d55552461c6e26b450923af Mon Sep 17 00:00:00 2001 From: Tobin Rosenau Date: Tue, 2 Apr 2024 21:39:41 +0200 Subject: [PATCH] fix: Remove HEMS an EEBus devices and change TCU handling to gateway (#364) * change E3_TCU autodetect-handler to gateway * remove hems and eebus devices and fix tcu handling * remove empty lines * add TCU300 from VX3 with Ethernet response * remove unnecessary if statement * add test * fix comment * add AutoDetect test * remove empty line * fix pylint error --- PyViCare/PyViCare.py | 16 +---- PyViCare/PyViCareDeviceConfig.py | 6 +- PyViCare/PyViCareService.py | 2 +- tests/response/TCU300_ethernet.json | 107 ++++++++++++++++++++++++++++ tests/test_E3_TCU300_ethernet.py | 19 +++++ tests/test_PyViCareDeviceConfig.py | 11 +++ 6 files changed, 142 insertions(+), 19 deletions(-) create mode 100644 tests/response/TCU300_ethernet.json create mode 100644 tests/test_E3_TCU300_ethernet.py diff --git a/PyViCare/PyViCare.py b/PyViCare/PyViCare.py index c21f5122..c4191f89 100644 --- a/PyViCare/PyViCare.py +++ b/PyViCare/PyViCare.py @@ -52,20 +52,8 @@ def __extract_devices(self): for installation in self.installations: for gateway in installation.gateways: for device in gateway.devices: - if device.deviceType not in ["heating", "zigbee", "vitoconnect", "electricityStorage", "EEBus", "hems", "tcu", "ventilation"]: - continue # we are only interested in heating, photovoltaic, electricityStorage, hems and ventilation devices - - if device.id == "gateway" and device.deviceType == "vitoconnect": - device.id = "0" # vitoconnect has no device id, so we use 0 - - if device.id == "gateway" and device.deviceType == "tcu": - device.id = "0" # tcu has no device id, so we use 0 - - if device.id == "HEMS" and device.deviceType == "hems": - device.id = "0" # hems has no device id, so we use 0 - - if device.id == "EEBUS" and device.deviceType == "EEBus": - device.id = "0" # EEBus has no device id, + if device.deviceType not in ["heating", "zigbee", "vitoconnect", "electricityStorage", "tcu", "ventilation"]: + continue # we are only interested in heating, photovoltaic, electricityStorage, and ventilation devices accessor = ViCareDeviceAccessor( installation.id, gateway.serial, device.id) diff --git a/PyViCare/PyViCareDeviceConfig.py b/PyViCare/PyViCareDeviceConfig.py index 8a376efa..8039d783 100644 --- a/PyViCare/PyViCareDeviceConfig.py +++ b/PyViCare/PyViCareDeviceConfig.py @@ -84,10 +84,8 @@ def asAutoDetectDevice(self): (self.asPelletsBoiler, r"Vitoligno|Ecotronic|VBC550P", []), (self.asRadiatorActuator, r"E3_RadiatorActuator", ["type:radiator"]), (self.asRoomSensor, r"E3_RoomSensor", ["type:climateSensor"]), - (self.asElectricalEnergySystem, r"E3_HEMS", ["type:hems"]), - (self.asElectricalEnergySystem, r"E3_TCU10_x07", ["type:tcu"]), - (self.asElectricalEnergySystem, r"E3_EEBus", ["type:eebus"]), - (self.asElectricalEnergySystem, r"E3_VitoCharge_03", ["type:energy_storage"]), + (self.asGateway, r"E3_TCU10_x07", ["type:gateway;TCU300"]), + (self.asElectricalEnergySystem, r"E3_VitoCharge_03", ["type:ees"]), (self.asVentilation, r"E3_ViAir", ["type:ventilation"]), (self.asGateway, r"Heatbox1", ["type:gateway;VitoconnectOpto1"]) ] diff --git a/PyViCare/PyViCareService.py b/PyViCare/PyViCareService.py index 8f3e086e..78a2348b 100644 --- a/PyViCare/PyViCareService.py +++ b/PyViCare/PyViCareService.py @@ -54,7 +54,7 @@ def hasRoles(self, requested_roles) -> bool: return hasRoles(requested_roles, self.roles) def _isGateway(self) -> bool: - return self.hasRoles(["type:gateway;VitoconnectOpto1"]) + return self.hasRoles(["type:gateway;VitoconnectOpto1"]) or self.hasRoles(["type:gateway;TCU300"]) def setProperty(self, property_name: str, action: str, data: Any) -> Any: url = buildSetPropertyUrl( diff --git a/tests/response/TCU300_ethernet.json b/tests/response/TCU300_ethernet.json new file mode 100644 index 00000000..53954d09 --- /dev/null +++ b/tests/response/TCU300_ethernet.json @@ -0,0 +1,107 @@ +{ + "data": [ + { + "feature": "gateway.devices", + "gatewayId": "################", + "timestamp": "2024-03-17T18:55:46.182Z", + "isEnabled": true, + "isReady": true, + "apiVersion": 1, + "uri": "https://api.viessmann.com/iot/v1/features/installations/252756/gateways/################/features/gateway.devices", + "properties": { + "devices": { + "type": "DeviceList", + "value": [ + { + "id": "gateway", + "fingerprint": "####", + "modelId": "E3_TCU10_x07", + "modelVersion": "####", + "name": "TCU", + "type": "tcu", + "roles": [ + "capability:hems", + "capability:zigbeeCoordinator", + "type:E3", + "type:gateway;TCU300" + ], + "status": "online" + }, + { + "id": "HEMS", + "fingerprint": "###", + "modelId": "E3_HEMS", + "modelVersion": "###", + "name": "Home Energy Management System", + "type": "hems", + "roles": [ + "type:E3", + "type:virtual;hems" + ], + "status": "online" + }, + { + "id": "RoomControl-1", + "fingerprint": "###", + "modelId": "E3_RoomControl_One_525", + "modelVersion": "####", + "name": "E3_RoomControl_One_525", + "type": "roomControl", + "roles": [ + "capability:monetization;FTDC", + "capability:monetization;OWD", + "capability:zigbeeCoordinator", + "type:E3", + "type:virtual;smartRoomControl" + ], + "status": "online" + }, + { + "id": "EEBUS", + "fingerprint": "#####", + "modelId": "E3_EEBus", + "modelVersion": "#####", + "name": "accessories", + "type": "EEBus", + "roles": [ + "type:E3", + "type:accessory;eeBus" + ], + "status": "online" + }, + { + "id": "0", + "fingerprint": "ecu;#####", + "modelId": "E3_VitoCharge_03", + "modelVersion": "####", + "name": "E3 device", + "type": "electricityStorage", + "roles": [ + "capability:hems", + "type:E3", + "type:ess", + "type:photovoltaic;Internal", + "type:product;Vitocharge" + ], + "status": "online" + }, + { + "id": "eebus-1", + "fingerprint": "eebus:wallbox;########", + "modelId": "E3_HEMS_VCS", + "modelVersion": "####", + "name": "Home Energy Management System", + "type": "vehicleChargingStation", + "roles": [ + "type:E3", + "type:accessory;vehicleChargingStation" + ], + "status": "online" + } + ] + } + }, + "commands": {} + } + ] +} \ No newline at end of file diff --git a/tests/test_E3_TCU300_ethernet.py b/tests/test_E3_TCU300_ethernet.py new file mode 100644 index 00000000..b3125c10 --- /dev/null +++ b/tests/test_E3_TCU300_ethernet.py @@ -0,0 +1,19 @@ +import unittest + +from PyViCare.PyViCareGateway import Gateway +from PyViCare.PyViCareUtils import PyViCareNotSupportedFeatureError +from tests.ViCareServiceMock import ViCareServiceMock + + +class TCU300_ethernet(unittest.TestCase): + def setUp(self): + self.service = ViCareServiceMock('response/TCU300_ethernet.json') + self.device = Gateway(self.service) + + def test_getSerial(self): + self.assertEqual( + self.device.getSerial(), "################") + + def test_getWifiSignalStrength(self): + with self.assertRaises(PyViCareNotSupportedFeatureError): + self.device.getWifiSignalStrength() diff --git a/tests/test_PyViCareDeviceConfig.py b/tests/test_PyViCareDeviceConfig.py index c95cc3ed..7acd5906 100644 --- a/tests/test_PyViCareDeviceConfig.py +++ b/tests/test_PyViCareDeviceConfig.py @@ -72,8 +72,19 @@ def test_autoDetect_VitoconnectOpto1_asGateway(self): device_type = c.asAutoDetectDevice() self.assertEqual("Gateway", type(device_type).__name__) + def test_autoDetect_TCU300_asGateway(self): + c = PyViCareDeviceConfig(self.service, "0", "E3_TCU10_x07", "Online") + device_type = c.asAutoDetectDevice() + self.assertEqual("Gateway", type(device_type).__name__) + def test_autoDetect_RoleGateway_asGateway(self): self.service.hasRoles = has_roles(["type:gateway;VitoconnectOpto1"]) c = PyViCareDeviceConfig(self.service, "0", "Unknown", "Online") device_type = c.asAutoDetectDevice() self.assertEqual("Gateway", type(device_type).__name__) + + def test_autoDetect_RoleGateway_asGateway_TCU300(self): + self.service.hasRoles = has_roles(["type:gateway;TCU300"]) + c = PyViCareDeviceConfig(self.service, "0", "Unknown", "Online") + device_type = c.asAutoDetectDevice() + self.assertEqual("Gateway", type(device_type).__name__)