From a3e8982c2cf914c2d8372913b7170cdb58c7214f Mon Sep 17 00:00:00 2001 From: Christopher Fenner Date: Wed, 18 Dec 2024 20:31:17 +0100 Subject: [PATCH 1/2] support ESS systems (vitocharge05) --- PyViCare/PyViCareDeviceConfig.py | 3 +- tests/response/Vitocharge05.json | 295 +++++++++++++++++++++++++++++ tests/test_PyViCareDeviceConfig.py | 11 ++ tests/test_Vitocharge05.py | 97 ++++++++++ 4 files changed, 405 insertions(+), 1 deletion(-) create mode 100644 tests/response/Vitocharge05.json create mode 100644 tests/test_Vitocharge05.py diff --git a/PyViCare/PyViCareDeviceConfig.py b/PyViCare/PyViCareDeviceConfig.py index 63e91f76..b49efe6d 100644 --- a/PyViCare/PyViCareDeviceConfig.py +++ b/PyViCare/PyViCareDeviceConfig.py @@ -82,7 +82,8 @@ def asAutoDetectDevice(self): (self.asHeatPump, r"Vitocal|VBC70|V200WO1A|CU401B", ["type:heatpump"]), (self.asOilBoiler, r"Vitoladens|Vitoradial|Vitorondens|VPlusH|V200KW2_6", []), (self.asPelletsBoiler, r"Vitoligno|Ecotronic|VBC550P", []), - (self.asElectricalEnergySystem, r"E3_VitoCharge_03", ["type:ees"]), + (self.asElectricalEnergySystem, r"E3_VitoCharge_03", ["type:ees"]), # ees, it this a typo? + (self.asElectricalEnergySystem, r"E3_VitoCharge_05", ["type:ess"]), (self.asVentilation, r"E3_ViAir", ["type:ventilation"]), (self.asVentilation, r"E3_ViAir", ["type:ventilation;central"]), (self.asVentilation, r"E3_VitoPure", ["type:ventilation;purifier"]), diff --git a/tests/response/Vitocharge05.json b/tests/response/Vitocharge05.json new file mode 100644 index 00000000..37a47e21 --- /dev/null +++ b/tests/response/Vitocharge05.json @@ -0,0 +1,295 @@ +{ + "data": [ + { + "apiVersion": 1, + "commands": {}, + "deviceId": "################", + "feature": "device.productIdentification", + "gatewayId": "################", + "isEnabled": true, + "isReady": true, + "properties": { + "product": { + "type": "object", + "value": { + "busAddress": 72, + "busType": "CanExternal", + "productFamily": "B_00012_VCH200", + "viessmannIdentificationNumber": "################" + } + } + }, + "timestamp": "2024-12-14T19:52:37.544Z", + "uri": "https://api.viessmann.com/iot/v1/features/installations/#######/gateways/################/devices/################/features/device.productIdentification" + }, + { + "apiVersion": 1, + "commands": {}, + "deviceId": "################", + "feature": "ess.operationState", + "gatewayId": "################", + "isEnabled": true, + "isReady": true, + "properties": { + "value": { + "type": "string", + "value": "standby" + } + }, + "timestamp": "2024-12-18T15:13:53.165Z", + "uri": "https://api.viessmann.com/iot/v1/features/installations/#######/gateways/################/devices/################/features/ess.operationState" + }, + { + "apiVersion": 1, + "commands": {}, + "deviceId": "################", + "feature": "ess.power", + "gatewayId": "################", + "isEnabled": true, + "isReady": true, + "properties": { + "value": { + "type": "number", + "unit": "watt", + "value": 0 + } + }, + "timestamp": "2024-12-18T15:13:54.657Z", + "uri": "https://api.viessmann.com/iot/v1/features/installations/#######/gateways/################/devices/################/features/ess.power" + }, + { + "apiVersion": 1, + "commands": {}, + "deviceId": "################", + "feature": "ess.stateOfCharge", + "gatewayId": "################", + "isEnabled": true, + "isReady": true, + "properties": { + "value": { + "type": "number", + "unit": "percent", + "value": 0 + } + }, + "timestamp": "2024-12-18T13:41:08.478Z", + "uri": "https://api.viessmann.com/iot/v1/features/installations/#######/gateways/################/devices/################/features/ess.stateOfCharge" + }, + { + "apiVersion": 1, + "commands": {}, + "deviceId": "################", + "feature": "ess.transfer.discharge.cumulated", + "gatewayId": "################", + "isEnabled": true, + "isReady": true, + "properties": { + "currentDay": { + "type": "number", + "unit": "wattHour", + "value": 1245 + }, + "currentMonth": { + "type": "number", + "unit": "wattHour", + "value": 3982 + }, + "currentWeek": { + "type": "number", + "unit": "wattHour", + "value": 3232 + }, + "currentYear": { + "type": "number", + "unit": "wattHour", + "value": 3982 + }, + "lifeCycle": { + "type": "number", + "unit": "wattHour", + "value": 3982 + } + }, + "timestamp": "2024-12-18T15:13:56.163Z", + "uri": "https://api.viessmann.com/iot/v1/features/installations/#######/gateways/################/devices/################/features/ess.transfer.discharge.cumulated" + }, + { + "apiVersion": 1, + "commands": {}, + "deviceId": "################", + "feature": "pcc.transfer.consumption.total", + "gatewayId": "################", + "isEnabled": true, + "isReady": true, + "properties": { + "value": { + "type": "number", + "unit": "wattHour", + "value": 3258900 + } + }, + "timestamp": "2024-12-18T16:54:33.546Z", + "uri": "https://api.viessmann.com/iot/v1/features/installations/#######/gateways/################/devices/################/features/pcc.transfer.consumption.total" + }, + { + "apiVersion": 1, + "commands": {}, + "deviceId": "################", + "feature": "pcc.transfer.feedIn.total", + "gatewayId": "################", + "isEnabled": true, + "isReady": true, + "properties": { + "value": { + "type": "number", + "unit": "wattHour", + "value": 29200 + } + }, + "timestamp": "2024-12-18T10:00:34.783Z", + "uri": "https://api.viessmann.com/iot/v1/features/installations/#######/gateways/################/devices/################/features/pcc.transfer.feedIn.total" + }, + { + "apiVersion": 1, + "commands": {}, + "deviceId": "################", + "feature": "photovoltaic.production.cumulated", + "gatewayId": "################", + "isEnabled": true, + "isReady": true, + "properties": { + "currentDay": { + "type": "number", + "unit": "wattHour", + "value": 4534 + }, + "currentMonth": { + "type": "number", + "unit": "wattHour", + "value": 23498 + }, + "currentWeek": { + "type": "number", + "unit": "wattHour", + "value": 12483 + }, + "currentYear": { + "type": "number", + "unit": "wattHour", + "value": 23498 + }, + "lifeCycle": { + "type": "number", + "unit": "wattHour", + "value": 23498 + } + }, + "timestamp": "2024-12-18T15:13:18.692Z", + "uri": "https://api.viessmann.com/iot/v1/features/installations/#######/gateways/################/devices/################/features/photovoltaic.production.cumulated" + }, + { + "apiVersion": 1, + "commands": {}, + "deviceId": "################", + "feature": "photovoltaic.production.current", + "gatewayId": "################", + "isEnabled": true, + "isReady": true, + "properties": { + "value": { + "type": "number", + "unit": "kilowatt", + "value": 0 + } + }, + "timestamp": "2024-12-18T15:01:39.005Z", + "uri": "https://api.viessmann.com/iot/v1/features/installations/#######/gateways/################/devices/################/features/photovoltaic.production.current" + }, + { + "apiVersion": 1, + "commands": {}, + "deviceId": "################", + "feature": "photovoltaic.status", + "gatewayId": "################", + "isEnabled": true, + "isReady": true, + "properties": { + "status": { + "type": "string", + "value": "ready" + } + }, + "timestamp": "2024-12-18T14:55:21.555Z", + "uri": "https://api.viessmann.com/iot/v1/features/installations/#######/gateways/################/devices/################/features/photovoltaic.status" + }, + { + "apiVersion": 1, + "commands": {}, + "deviceId": "################", + "feature": "device.messages.errors.raw", + "gatewayId": "################", + "isEnabled": true, + "isReady": true, + "properties": { + "entries": { + "type": "array", + "value": [] + } + }, + "timestamp": "2024-12-14T19:52:37.544Z", + "uri": "https://api.viessmann.com/iot/v1/features/installations/#######/gateways/################/devices/################/features/device.messages.errors.raw" + }, + { + "apiVersion": 1, + "commands": {}, + "deviceId": "################", + "feature": "device.serial", + "gatewayId": "################", + "isEnabled": true, + "isReady": true, + "properties": { + "value": { + "type": "string", + "value": "################" + } + }, + "timestamp": "2024-12-14T19:52:37.544Z", + "uri": "https://api.viessmann.com/iot/v1/features/installations/#######/gateways/################/devices/################/features/device.serial" + }, + { + "apiVersion": 1, + "commands": {}, + "deviceId": "################", + "feature": "heating.boiler.serial", + "gatewayId": "################", + "isEnabled": true, + "isReady": true, + "properties": { + "value": { + "type": "string", + "value": "################" + } + }, + "timestamp": "2024-12-14T19:52:37.544Z", + "uri": "https://api.viessmann.com/iot/v1/features/installations/#######/gateways/################/devices/################/features/heating.boiler.serial" + }, + { + "apiVersion": 1, + "commands": {}, + "deviceId": "################", + "feature": "pcc.transfer.power.exchange", + "gatewayId": "################", + "isEnabled": true, + "isReady": true, + "properties": { + "value": { + "type": "number", + "unit": "watt", + "value": 6624 + } + }, + "timestamp": "2024-12-18T16:54:38.941Z", + "uri": "https://api.viessmann.com/iot/v1/features/installations/#######/gateways/################/devices/################/features/pcc.transfer.power.exchange" + } + ] +} diff --git a/tests/test_PyViCareDeviceConfig.py b/tests/test_PyViCareDeviceConfig.py index 580280e0..92ad9796 100644 --- a/tests/test_PyViCareDeviceConfig.py +++ b/tests/test_PyViCareDeviceConfig.py @@ -83,6 +83,17 @@ def test_autoDetect_Vitopure_350_asVentilation(self): device_type = c.asAutoDetectDevice() self.assertEqual("VentilationDevice", type(device_type).__name__) + def test_autoDetect_RoleESS_asElectricalEnergySystem(self): + self.service.hasRoles = has_roles(["type:ess"]) + c = PyViCareDeviceConfig(self.service, "0", "Unknown", "Online") + device_type = c.asAutoDetectDevice() + self.assertEqual("ElectricalEnergySystem", type(device_type).__name__) + + def test_autoDetect_Vitocharge05_asElectricalEnergySystem(self): + c = PyViCareDeviceConfig(self.service, "0", "E3_VitoCharge_05", "Online") + device_type = c.asAutoDetectDevice() + self.assertEqual("ElectricalEnergySystem", type(device_type).__name__) + def test_autoDetect_VitoconnectOpto1_asGateway(self): c = PyViCareDeviceConfig(self.service, "0", "Heatbox1", "Online") device_type = c.asAutoDetectDevice() diff --git a/tests/test_Vitocharge05.py b/tests/test_Vitocharge05.py new file mode 100644 index 00000000..4c2b0450 --- /dev/null +++ b/tests/test_Vitocharge05.py @@ -0,0 +1,97 @@ +import unittest + +from PyViCare.PyViCareElectricalEnergySystem import ElectricalEnergySystem +from tests.ViCareServiceMock import ViCareServiceMock + + +class Vitocharge05(unittest.TestCase): + def setUp(self): + self.service = ViCareServiceMock('response/Vitocharge05.json') + self.device = ElectricalEnergySystem(self.service) + + def test_isDomesticHotWaterDevice(self): + self.assertEqual(self.device.isDomesticHotWaterDevice(), False) + + def test_isSolarThermalDevice(self): + self.assertEqual(self.device.isSolarThermalDevice(), False) + + def test_isVentilationDevice(self): + self.assertEqual(self.device.isVentilationDevice(), False) + + def test_getSerial(self): + self.assertEqual(self.device.getSerial(), '################') + + def test_getPointOfCommonCouplingTransferPowerExchange(self): + self.assertEqual(self.device.getPointOfCommonCouplingTransferPowerExchange(), 6624) + + def test_getPhotovoltaicProductionCumulatedUnit(self): + self.assertEqual(self.device.getPhotovoltaicProductionCumulatedUnit(), "wattHour") + + def test_getPhotovoltaicProductionCumulatedCurrentDay(self): + self.assertEqual(self.device.getPhotovoltaicProductionCumulatedCurrentDay(), 4534) + + def test_getPhotovoltaicProductionCumulatedCurrentWeek(self): + self.assertEqual(self.device.getPhotovoltaicProductionCumulatedCurrentWeek(), 12483) + + def test_getPhotovoltaicProductionCumulatedCurrentMonth(self): + self.assertEqual(self.device.getPhotovoltaicProductionCumulatedCurrentMonth(), 23498) + + def test_getPhotovoltaicProductionCumulatedCurrentYear(self): + self.assertEqual(self.device.getPhotovoltaicProductionCumulatedCurrentYear(), 23498) + + def test_getPhotovoltaicProductionCumulatedLifeCycle(self): + self.assertEqual(self.device.getPhotovoltaicProductionCumulatedLifeCycle(), 23498) + + def test_getPhotovoltaicStatus(self): + self.assertEqual(self.device.getPhotovoltaicStatus(), "ready") + + def test_getPhotovoltaicProductionCurrent(self): + self.assertEqual(self.device.getPhotovoltaicProductionCurrent(), 0) + + def test_getPhotovoltaicProductionCurrentUnit(self): + self.assertEqual(self.device.getPhotovoltaicProductionCurrentUnit(), "kilowatt") + + def test_getPointOfCommonCouplingTransferConsumptionTotal(self): + self.assertEqual(self.device.getPointOfCommonCouplingTransferConsumptionTotal(), 3258900) + + def test_getPointOfCommonCouplingTransferConsumptionTotalUnit(self): + self.assertEqual(self.device.getPointOfCommonCouplingTransferConsumptionTotalUnit(), "wattHour") + + def test_getPointOfCommonCouplingTransferFeedInTotal(self): + self.assertEqual(self.device.getPointOfCommonCouplingTransferFeedInTotal(), 29200) + + def test_getPointOfCommonCouplingTransferFeedInTotalUnit(self): + self.assertEqual(self.device.getPointOfCommonCouplingTransferFeedInTotalUnit(), "wattHour") + + def test_getElectricalEnergySystemTransferDischargeCumulatedUnit(self): + self.assertEqual(self.device.getElectricalEnergySystemTransferDischargeCumulatedUnit(), "wattHour") + + def test_getElectricalEnergySystemTransferDischargeCumulatedCurrentDay(self): + self.assertEqual(self.device.getElectricalEnergySystemTransferDischargeCumulatedCurrentDay(), 1245) + + def test_getElectricalEnergySystemTransferDischargeCumulatedCurrentWeek(self): + self.assertEqual(self.device.getElectricalEnergySystemTransferDischargeCumulatedCurrentWeek(), 3232) + + def test_getElectricalEnergySystemTransferDischargeCumulatedCurrentMonth(self): + self.assertEqual(self.device.getElectricalEnergySystemTransferDischargeCumulatedCurrentMonth(), 3982) + + def test_getElectricalEnergySystemTransferDischargeCumulatedCurrentYear(self): + self.assertEqual(self.device.getElectricalEnergySystemTransferDischargeCumulatedCurrentYear(), 3982) + + def test_getElectricalEnergySystemTransferDischargeCumulatedLifeCycle(self): + self.assertEqual(self.device.getElectricalEnergySystemTransferDischargeCumulatedLifeCycle(), 3982) + + def test_getElectricalEnergySystemSOC(self): + self.assertEqual(self.device.getElectricalEnergySystemSOC(), 0) + + def test_getElectricalEnergySystemSOCUnit(self): + self.assertEqual(self.device.getElectricalEnergySystemSOCUnit(), "percent") + + def test_getElectricalEnergySystemPower(self): + self.assertEqual(self.device.getElectricalEnergySystemPower(), 0) + + def test_getElectricalEnergySystemPowerUnit(self): + self.assertEqual(self.device.getElectricalEnergySystemPowerUnit(), "watt") + + def test_getElectricalEnergySystemOperationState(self): + self.assertEqual(self.device.getElectricalEnergySystemOperationState(), "standby") From 3e5f4525c538e3e060e4e781640ae8d1d451f9a4 Mon Sep 17 00:00:00 2001 From: Christopher Fenner Date: Wed, 18 Dec 2024 20:34:42 +0100 Subject: [PATCH 2/2] sort data --- tests/response/Vitocharge05.json | 138 +++++++++++++++---------------- 1 file changed, 69 insertions(+), 69 deletions(-) diff --git a/tests/response/Vitocharge05.json b/tests/response/Vitocharge05.json index 37a47e21..bb1857f9 100644 --- a/tests/response/Vitocharge05.json +++ b/tests/response/Vitocharge05.json @@ -1,5 +1,22 @@ { "data": [ + { + "apiVersion": 1, + "commands": {}, + "deviceId": "################", + "feature": "device.messages.errors.raw", + "gatewayId": "################", + "isEnabled": true, + "isReady": true, + "properties": { + "entries": { + "type": "array", + "value": [] + } + }, + "timestamp": "2024-12-14T19:52:37.544Z", + "uri": "https://api.viessmann.com/iot/v1/features/installations/#######/gateways/################/devices/################/features/device.messages.errors.raw" + }, { "apiVersion": 1, "commands": {}, @@ -22,6 +39,23 @@ "timestamp": "2024-12-14T19:52:37.544Z", "uri": "https://api.viessmann.com/iot/v1/features/installations/#######/gateways/################/devices/################/features/device.productIdentification" }, + { + "apiVersion": 1, + "commands": {}, + "deviceId": "################", + "feature": "device.serial", + "gatewayId": "################", + "isEnabled": true, + "isReady": true, + "properties": { + "value": { + "type": "string", + "value": "################" + } + }, + "timestamp": "2024-12-14T19:52:37.544Z", + "uri": "https://api.viessmann.com/iot/v1/features/installations/#######/gateways/################/devices/################/features/device.serial" + }, { "apiVersion": 1, "commands": {}, @@ -113,6 +147,23 @@ "timestamp": "2024-12-18T15:13:56.163Z", "uri": "https://api.viessmann.com/iot/v1/features/installations/#######/gateways/################/devices/################/features/ess.transfer.discharge.cumulated" }, + { + "apiVersion": 1, + "commands": {}, + "deviceId": "################", + "feature": "heating.boiler.serial", + "gatewayId": "################", + "isEnabled": true, + "isReady": true, + "properties": { + "value": { + "type": "string", + "value": "################" + } + }, + "timestamp": "2024-12-14T19:52:37.544Z", + "uri": "https://api.viessmann.com/iot/v1/features/installations/#######/gateways/################/devices/################/features/heating.boiler.serial" + }, { "apiVersion": 1, "commands": {}, @@ -149,6 +200,24 @@ "timestamp": "2024-12-18T10:00:34.783Z", "uri": "https://api.viessmann.com/iot/v1/features/installations/#######/gateways/################/devices/################/features/pcc.transfer.feedIn.total" }, + { + "apiVersion": 1, + "commands": {}, + "deviceId": "################", + "feature": "pcc.transfer.power.exchange", + "gatewayId": "################", + "isEnabled": true, + "isReady": true, + "properties": { + "value": { + "type": "number", + "unit": "watt", + "value": 6624 + } + }, + "timestamp": "2024-12-18T16:54:38.941Z", + "uri": "https://api.viessmann.com/iot/v1/features/installations/#######/gateways/################/devices/################/features/pcc.transfer.power.exchange" + }, { "apiVersion": 1, "commands": {}, @@ -221,75 +290,6 @@ }, "timestamp": "2024-12-18T14:55:21.555Z", "uri": "https://api.viessmann.com/iot/v1/features/installations/#######/gateways/################/devices/################/features/photovoltaic.status" - }, - { - "apiVersion": 1, - "commands": {}, - "deviceId": "################", - "feature": "device.messages.errors.raw", - "gatewayId": "################", - "isEnabled": true, - "isReady": true, - "properties": { - "entries": { - "type": "array", - "value": [] - } - }, - "timestamp": "2024-12-14T19:52:37.544Z", - "uri": "https://api.viessmann.com/iot/v1/features/installations/#######/gateways/################/devices/################/features/device.messages.errors.raw" - }, - { - "apiVersion": 1, - "commands": {}, - "deviceId": "################", - "feature": "device.serial", - "gatewayId": "################", - "isEnabled": true, - "isReady": true, - "properties": { - "value": { - "type": "string", - "value": "################" - } - }, - "timestamp": "2024-12-14T19:52:37.544Z", - "uri": "https://api.viessmann.com/iot/v1/features/installations/#######/gateways/################/devices/################/features/device.serial" - }, - { - "apiVersion": 1, - "commands": {}, - "deviceId": "################", - "feature": "heating.boiler.serial", - "gatewayId": "################", - "isEnabled": true, - "isReady": true, - "properties": { - "value": { - "type": "string", - "value": "################" - } - }, - "timestamp": "2024-12-14T19:52:37.544Z", - "uri": "https://api.viessmann.com/iot/v1/features/installations/#######/gateways/################/devices/################/features/heating.boiler.serial" - }, - { - "apiVersion": 1, - "commands": {}, - "deviceId": "################", - "feature": "pcc.transfer.power.exchange", - "gatewayId": "################", - "isEnabled": true, - "isReady": true, - "properties": { - "value": { - "type": "number", - "unit": "watt", - "value": 6624 - } - }, - "timestamp": "2024-12-18T16:54:38.941Z", - "uri": "https://api.viessmann.com/iot/v1/features/installations/#######/gateways/################/devices/################/features/pcc.transfer.power.exchange" } ] }