Skip to content

Commit

Permalink
fix: Remove HEMS an EEBus devices and change TCU handling to gateway (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
Nibot1 authored Apr 2, 2024
1 parent a5edfa3 commit f8d1b44
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 19 deletions.
16 changes: 2 additions & 14 deletions PyViCare/PyViCare.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions PyViCare/PyViCareDeviceConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
]
Expand Down
2 changes: 1 addition & 1 deletion PyViCare/PyViCareService.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
107 changes: 107 additions & 0 deletions tests/response/TCU300_ethernet.json
Original file line number Diff line number Diff line change
@@ -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": {}
}
]
}
19 changes: 19 additions & 0 deletions tests/test_E3_TCU300_ethernet.py
Original file line number Diff line number Diff line change
@@ -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()
11 changes: 11 additions & 0 deletions tests/test_PyViCareDeviceConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

0 comments on commit f8d1b44

Please sign in to comment.