1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
|
import unittest
from unittest.mock import Mock
from PyViCare.PyViCareDeviceConfig import PyViCareDeviceConfig
from PyViCare.PyViCareService import hasRoles
def has_roles(roles):
return lambda requested_roles: hasRoles(requested_roles, roles)
class PyViCareDeviceConfigTest(unittest.TestCase):
def setUp(self) -> None:
self.service = Mock()
self.service.hasRoles = has_roles([])
def test_autoDetect_Vitodens_asGazBoiler(self):
c = PyViCareDeviceConfig(
self.service, "0", "E3_Vitodens_200_xxxx/E3_Dictionary", "Online")
device_type = c.asAutoDetectDevice()
self.assertEqual("GazBoiler", type(device_type).__name__)
def test_autoDetect_Unknown_asGeneric(self):
c = PyViCareDeviceConfig(self.service, "0", "myRobot", "Online")
device_type = c.asAutoDetectDevice()
self.assertEqual("HeatingDevice", type(device_type).__name__)
def test_autoDetect_VScot_asGazBoiler(self):
c = PyViCareDeviceConfig(self.service, "0", "VScotHO1_200", "Online")
device_type = c.asAutoDetectDevice()
self.assertEqual("GazBoiler", type(device_type).__name__)
def test_autoDetect_RoleBoiler_asGazBoiler(self):
self.service.hasRoles = has_roles(["type:boiler"])
c = PyViCareDeviceConfig(self.service, "0", "Unknown", "Online")
device_type = c.asAutoDetectDevice()
self.assertEqual("GazBoiler", type(device_type).__name__)
def test_autoDetect_RoleHeatpump_asHeatpump(self):
self.service.hasRoles = has_roles(["type:heatpump"])
c = PyViCareDeviceConfig(self.service, "0", "Unknown", "Online")
device_type = c.asAutoDetectDevice()
self.assertEqual("HeatPump", type(device_type).__name__)
def test_autoDetect_RoleRadiator_asRadiatorActuator(self):
self.service.hasRoles = has_roles(["type:radiator"])
c = PyViCareDeviceConfig(self.service, "0", "Unknown", "Online")
device_type = c.asAutoDetectDevice()
self.assertEqual("RadiatorActuator", type(device_type).__name__)
def test_autoDetect_RoleClimateSensor_asRoomSensor(self):
self.service.hasRoles = has_roles(["type:climateSensor"])
c = PyViCareDeviceConfig(self.service, "0", "Unknown", "Online")
device_type = c.asAutoDetectDevice()
self.assertEqual("RoomSensor", type(device_type).__name__)
def test_autoDetect_RoleVentilation_asVentilation(self):
self.service.hasRoles = has_roles(["type:ventilation"])
c = PyViCareDeviceConfig(self.service, "0", "Unknown", "Online")
device_type = c.asAutoDetectDevice()
self.assertEqual("VentilationDevice", type(device_type).__name__)
def test_autoDetect_RoleVentilationCentral_asVentilation(self):
self.service.hasRoles = has_roles(["type:ventilation;central"])
c = PyViCareDeviceConfig(self.service, "0", "Unknown", "Online")
device_type = c.asAutoDetectDevice()
self.assertEqual("VentilationDevice", type(device_type).__name__)
def test_autoDetect_Vitoair_FS_300F_asVentilation(self):
c = PyViCareDeviceConfig(self.service, "0", "E3_ViAir_300F", "Online")
device_type = c.asAutoDetectDevice()
self.assertEqual("VentilationDevice", type(device_type).__name__)
def test_autoDetect_RoleVentilationPurifier_asVentilation(self):
self.service.hasRoles = has_roles(["type:ventilation;purifier"])
c = PyViCareDeviceConfig(self.service, "0", "Unknown", "Online")
device_type = c.asAutoDetectDevice()
self.assertEqual("VentilationDevice", type(device_type).__name__)
def test_autoDetect_Vitopure_350_asVentilation(self):
c = PyViCareDeviceConfig(self.service, "0", "E3_VitoPure", "Online")
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()
self.assertEqual("Gateway", type(device_type).__name__)
def test_autoDetect_VitoconnectOpto2_asGateway(self):
c = PyViCareDeviceConfig(self.service, "0", "Heatbox2_SRC", "Online")
device_type = c.asAutoDetectDevice()
self.assertEqual("Gateway", type(device_type).__name__)
def test_autoDetect_TCU100_asGateway(self):
c = PyViCareDeviceConfig(self.service, "0", "E3_TCU41_x04", "Online")
device_type = c.asAutoDetectDevice()
self.assertEqual("Gateway", type(device_type).__name__)
def test_autoDetect_TCU200_asGateway(self):
c = PyViCareDeviceConfig(self.service, "0", "E3_TCU19_x05", "Online")
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_Ecotronic_asPelletsBoiler(self):
self.service.hasRoles = has_roles(["type:boiler"])
c = PyViCareDeviceConfig(self.service, "0", "Ecotronic", "Online")
device_type = c.asAutoDetectDevice()
self.assertEqual("PelletsBoiler", type(device_type).__name__)
def test_autoDetect_Vitoladens_asOilBoiler(self):
self.service.hasRoles = has_roles(["type:boiler"])
c = PyViCareDeviceConfig(self.service, "0", "Vitoladens", "Online")
device_type = c.asAutoDetectDevice()
self.assertEqual("OilBoiler", 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_vc_opto2(self):
self.service.hasRoles = has_roles(["type:gateway;VitoconnectOpto2/OT2"])
c = PyViCareDeviceConfig(self.service, "0", "Unknown", "Online")
device_type = c.asAutoDetectDevice()
self.assertEqual("Gateway", type(device_type).__name__)
def test_autoDetect_RoleGateway_asGateway_TCU100(self):
self.service.hasRoles = has_roles(["type:gateway;TCU100"])
c = PyViCareDeviceConfig(self.service, "0", "Unknown", "Online")
device_type = c.asAutoDetectDevice()
self.assertEqual("Gateway", type(device_type).__name__)
def test_autoDetect_RoleGateway_asGateway_TCU200(self):
self.service.hasRoles = has_roles(["type:gateway;TCU200"])
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__)
def test_legacy_device(self):
self.service.hasRoles = has_roles(["type:legacy"])
c = PyViCareDeviceConfig(self.service, "0", "Unknown", "Online")
device = c.asAutoDetectDevice()
self.assertEqual(device.isLegacyDevice(), True)
self.assertEqual(device.isE3Device(), False)
def test_e3_device(self):
self.service.hasRoles = has_roles(["type:E3"])
c = PyViCareDeviceConfig(self.service, "0", "Unknown", "Online")
device = c.asAutoDetectDevice()
self.assertEqual(device.isLegacyDevice(), False)
self.assertEqual(device.isE3Device(), True)
def test_getDeviceType_heating(self):
c = PyViCareDeviceConfig(self.service, "0", "Vitocal", "Online", "heating")
self.assertEqual(c.getDeviceType(), "heating")
def test_getDeviceType_vitoconnect(self):
c = PyViCareDeviceConfig(self.service, "0", "Heatbox1", "Online", "vitoconnect")
self.assertEqual(c.getDeviceType(), "vitoconnect")
def test_getDeviceType_none_when_not_provided(self):
c = PyViCareDeviceConfig(self.service, "0", "Vitocal", "Online")
self.assertIsNone(c.getDeviceType())
def test_getRoles(self):
roles = ["type:heatpump", "type:E3"]
c = PyViCareDeviceConfig(self.service, "0", "Vitocal", "Online", "heating", roles)
self.assertEqual(c.getRoles(), roles)
def test_getRoles_empty_when_not_provided(self):
c = PyViCareDeviceConfig(self.service, "0", "Vitocal", "Online")
self.assertEqual(c.getRoles(), [])
def test_isGateway_true_for_gateway_role(self):
self.service._isGateway = Mock(return_value=True) # pylint: disable=protected-access
c = PyViCareDeviceConfig(self.service, "0", "Heatbox1", "Online", "vitoconnect")
self.assertTrue(c.isGateway())
def test_isGateway_false_for_non_gateway_role(self):
self.service._isGateway = Mock(return_value=False) # pylint: disable=protected-access
c = PyViCareDeviceConfig(self.service, "0", "Vitocal", "Online", "heating")
self.assertFalse(c.isGateway())
|