Skip to content

Commit a1f53e4

Browse files
authored
feat: expose device_type on PyViCareDeviceConfig (#698)
1 parent 10328d4 commit a1f53e4

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

PyViCare/PyViCare.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def __extract_devices(self):
6161

6262
logger.info("Device found: %s", device.modelId)
6363

64-
yield PyViCareDeviceConfig(service, device.id, device.modelId, device.status)
64+
yield PyViCareDeviceConfig(service, device.id, device.modelId, device.status, device.deviceType)
6565

6666

6767
class DictWrap(object):

PyViCare/PyViCareDeviceConfig.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222

2323

2424
class PyViCareDeviceConfig:
25-
def __init__(self, service, device_id, device_model, status):
25+
# pylint: disable=too-many-arguments,too-many-positional-arguments
26+
def __init__(self, service, device_id, device_model, status, device_type=None):
2627
self.service = service
2728
self.device_id = device_id
2829
self.device_model = device_model
2930
self.status = status
31+
self.device_type = device_type
3032

3133
def asGeneric(self):
3234
return HeatingDevice(self.service)
@@ -85,6 +87,12 @@ def getModel(self):
8587
def isOnline(self):
8688
return self.status == "Online"
8789

90+
def getDeviceType(self):
91+
return self.device_type
92+
93+
def isGateway(self):
94+
return self.service._isGateway() # pylint: disable=protected-access
95+
8896
# see: https://vitodata300.viessmann.com/vd300/ApplicationHelp/VD300/1031_de_DE/Ger%C3%A4teliste.html
8997
def asAutoDetectDevice(self):
9098
device_types = [

tests/test_PyViCareDeviceConfig.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,25 @@ def test_e3_device(self):
174174
device = c.asAutoDetectDevice()
175175
self.assertEqual(device.isLegacyDevice(), False)
176176
self.assertEqual(device.isE3Device(), True)
177+
178+
def test_getDeviceType_heating(self):
179+
c = PyViCareDeviceConfig(self.service, "0", "Vitocal", "Online", "heating")
180+
self.assertEqual(c.getDeviceType(), "heating")
181+
182+
def test_getDeviceType_vitoconnect(self):
183+
c = PyViCareDeviceConfig(self.service, "0", "Heatbox1", "Online", "vitoconnect")
184+
self.assertEqual(c.getDeviceType(), "vitoconnect")
185+
186+
def test_getDeviceType_none_when_not_provided(self):
187+
c = PyViCareDeviceConfig(self.service, "0", "Vitocal", "Online")
188+
self.assertIsNone(c.getDeviceType())
189+
190+
def test_isGateway_true_for_gateway_role(self):
191+
self.service._isGateway = Mock(return_value=True) # pylint: disable=protected-access
192+
c = PyViCareDeviceConfig(self.service, "0", "Heatbox1", "Online", "vitoconnect")
193+
self.assertTrue(c.isGateway())
194+
195+
def test_isGateway_false_for_non_gateway_role(self):
196+
self.service._isGateway = Mock(return_value=False) # pylint: disable=protected-access
197+
c = PyViCareDeviceConfig(self.service, "0", "Vitocal", "Online", "heating")
198+
self.assertFalse(c.isGateway())

0 commit comments

Comments
 (0)