async def test_serial_not_fixed_relogin(session: ClientSession, connector: Connector, resp: aioresponses) -> None: manager = SystemManager("user", "pass", session, "pymultiMATIC") with open(path("files/responses/zone"), "r") as file: raw_zone = json.loads(file.read()) with open(path("files/responses/facilities"), "r") as file: facilities = json.loads(file.read()) facilities["body"]["facilitiesList"][0]["serialNumber"] = "123" url_zone1 = urls.zone(serial=SERIAL, id="zone") url_zone2 = urls.zone(serial="123", id="zone") url_facilities = urls.facilities_list(serial=SERIAL) resp.get(url_zone1, payload=raw_zone, status=200) resp.get(url_zone2, payload=raw_zone, status=200) resp.get(url_facilities, payload=facilities, status=200) mock_auth(resp) await manager.get_zone("zone") assert manager._serial == SERIAL assert not manager._fixed_serial connector._clear_cookies() await manager.get_zone("zone") assert manager._serial == "123"
def test_map_system_info_specific_serial(self) -> None: with open(path('files/responses/facilities_multiple'), 'r') as file: facilities = json.loads(file.read()) with open(path('files/responses/gateway'), 'r') as file: gateway = json.loads(file.read()) with open(path('files/responses/hvacstate'), 'r') as file: hvac = json.loads(file.read()) sys_info = mapper.map_system_info(facilities, gateway, hvac, '888') self.assertEqual('888', sys_info.serial_number) self.assertEqual('Home2', sys_info.name) self.assertEqual('6.6.6', sys_info.firmware)
def test_hot_water(self) -> None: """Test map hot water.""" with open(path("files/responses/systemcontrol"), "r") as file: raw_system = json.loads(file.read()) with open(path("files/responses/livereport"), "r") as file: raw_livereport = json.loads(file.read()) hot_water = mapper.map_hot_water_from_system(raw_system, raw_livereport) self.assertEqual(44.5, hot_water.temperature) self.assertEqual(51, hot_water.target_high) self.assertEqual(OperatingModes.AUTO, hot_water.operating_mode) self.assertEqual("Control_DHW", hot_water.id) self.assertIsNotNone(hot_water.time_program.days["monday"].settings[0].setting)
def test_hot_water_alone(self) -> None: """Test map hot water.""" with open(path('files/responses/hotwater'), 'r') as file: raw_hotwater = json.loads(file.read()) with open(path('files/responses/livereport'), 'r') as file: raw_livereport = json.loads(file.read()) hotwater = mapper.map_hot_water_alone(raw_hotwater, 'control_dhw', raw_livereport) self.assertEqual('control_dhw', hotwater.id) self.assertEqual(OperatingModes.AUTO, hotwater.operating_mode) self.assertIsNotNone( hotwater.time_program.days['monday'].settings[0].setting)
def test_map_zone_cooling(self) -> None: """Test map zone with cooling.""" with open(path("files/responses/systemcontrol_ventilation"), 'r') as file: system = json.loads(file.read()) zones = mapper.map_zones(system) self.assertIsNotNone(zones)
def test_map_devices(self) -> None: """Test map devices.""" with open(path("files/responses/rooms"), "r") as file: raw_rooms = json.loads(file.read()) rooms = mapper.map_rooms(raw_rooms) self.assertIsNotNone(rooms) self.assertEqual(4, len(rooms)) devices_room0 = rooms[0].devices devices_room1 = rooms[1].devices self.assertIsNotNone(devices_room0) self.assertEqual(1, len(devices_room0)) self.assertIsNotNone(devices_room1) self.assertEqual(2, len(devices_room1)) self.assertEqual("Device 1", devices_room0[0].name) self.assertEqual("R13456789012345678901234", devices_room0[0].sgtin) self.assertEqual("VALVE", devices_room0[0].device_type) self.assertEqual(True, devices_room0[0].radio_out_of_reach) self.assertEqual(True, devices_room0[0].radio_out_of_reach) self.assertEqual("Device 1", devices_room1[0].name) self.assertEqual("R20123456789012345678900", devices_room1[0].sgtin) self.assertEqual("VALVE", devices_room1[0].device_type) self.assertEqual(False, devices_room1[0].radio_out_of_reach) self.assertEqual(False, devices_room1[0].radio_out_of_reach) self.assertEqual("Device 2", devices_room1[1].name) self.assertEqual("R20123456789012345678999", devices_room1[1].sgtin) self.assertEqual("VALVE", devices_room1[1].device_type) self.assertEqual(False, devices_room1[1].radio_out_of_reach) self.assertEqual(False, devices_room1[1].radio_out_of_reach)
def test_map_quick_mode_quick_veto(self) -> None: """Test map quick veto.""" with open(path("files/responses/systemcontrol_quick_veto"), "r") as file: system = json.loads(file.read()) quick_mode = mapper.map_quick_mode_from_system(system) self.assertIsNone(quick_mode)
def test_errors_no_error(self) -> None: """Test map no errors.""" with open(path("files/responses/hvacstate"), "r") as file: raw_hvac = json.loads(file.read()) errors = mapper.map_errors(raw_hvac) self.assertEqual(0, len(errors))
def test_map_zone_no_active_function(self) -> None: """Test map a zone without active function""" with open(path("files/responses/zone_no_active_function"), "r") as file: zone_file = json.loads(file.read()) zone = mapper.map_zone(zone_file) self.assertEqual(ActiveFunction.STANDBY, zone.active_function)
def test_map_system_no_config_rbr(self) -> None: with open(path("files/responses/systemcontrol_zone_no_config_rbr"), "r") as file: raw_system = json.loads(file.read()) zones = mapper.map_zones_from_system(raw_system) self.assertIsNotNone(zones) self.assertIsNotNone(zones[0]) self.assertIsNotNone(zones[1])
def test_map_no_outdoor_temp(self) -> None: """Test map no outdoor temperature.""" with open(path("files/responses/systemcontrol_no_outside_temp"), "r") as file: system = json.loads(file.read()) temp = mapper.map_outdoor_temp_from_system(system) self.assertIsNone(temp)
def test_map_quick_mode_from_system(self) -> None: """Test map quick mode.""" with open(path("files/responses/systemcontrol_hotwater_boost"), "r") as file: system = json.loads(file.read()) quick_mode = mapper.map_quick_mode_from_system(system) self.assertEqual(QuickModes.HOTWATER_BOOST.name, quick_mode.name)
def test_map_no_quick_mode(self) -> None: """Test map no quick mode.""" with open(path('files/responses/systemcontrol'), 'r') as file: system = json.loads(file.read()) quick_mode = mapper.map_quick_mode(system) self.assertIsNone(quick_mode)
def test_map_outdoor_temp(self) -> None: """Test map outdoor temperature.""" with open(path("files/responses/systemcontrol"), "r") as file: system = json.loads(file.read()) temp = mapper.map_outdoor_temp_from_system(system) self.assertEqual(6.3, temp)
def test_map_dhw(self) -> None: with open(path("files/responses/dhws"), "r") as file: raw_dhw = json.loads(file.read()) dhw = mapper.map_dhw(raw_dhw) self.assertIsNotNone(dhw.hotwater) self.assertIsNone(dhw.hotwater.temperature) self.assertIsNotNone(dhw.circulation)
def test_boiler_status_empty(self) -> None: """Test map empty boiler status.""" with open(path("files/responses/hvacstate_empty"), "r") as file: hvac = json.loads(file.read()) hvac_status = mapper.map_hvac_status(hvac) self.assertIsNone(hvac_status.boiler_status)
def test_boiler_status_empty(self) -> None: """Test map empty boiler status.""" with open(path('files/responses/hvacstate_empty'), 'r')\ as file: hvac = json.loads(file.read()) boiler_status = mapper.map_boiler_status(hvac) self.assertIsNone(boiler_status)
async def test_get_room(manager: SystemManager, resp: aioresponses) -> None: with open(path("files/responses/room"), "r") as file: raw_rooms = json.loads(file.read()) resp.get(urls.room(id="1", serial=SERIAL), payload=raw_rooms, status=200) new_room = await manager.get_room("1") assert new_room is not None
def test_map_system_info(self) -> None: with open(path('files/responses/facilities'), 'r') as file: facilities = json.loads(file.read()) with open(path('files/responses/gateway'), 'r') as file: gateway = json.loads(file.read()) with open(path('files/responses/hvacstate'), 'r') as file: hvac = json.loads(file.read()) sys_info = mapper.map_system_info(facilities, gateway, hvac) self.assertEqual('1234567890123456789012345678', sys_info.serial_number) self.assertEqual('Home', sys_info.name) self.assertEqual('01:23:45:67:89:AB', sys_info.mac_ethernet) self.assertEqual('1.2.3', sys_info.firmware) self.assertEqual('VR920', sys_info.gateway) self.assertEqual('ONLINE', sys_info.online) self.assertEqual('UPDATE_NOT_PENDING', sys_info.update)
def test_hot_water_alone_none(self) -> None: """Test map hot water.""" with open(path('files/responses/livereport'), 'r') as file: raw_livereport = json.loads(file.read()) hotwater = mapper.map_hot_water_alone(None, 'control_dhw', raw_livereport) self.assertIsNone(hotwater)
def test_map_system_info_specific_serial(self) -> None: with open(path("files/responses/facilities_multiple"), "r") as file: facilities = json.loads(file.read()) sys_info = mapper.map_facility_detail(facilities, "888") self.assertEqual("888", sys_info.serial_number) self.assertEqual("Home2", sys_info.name) self.assertEqual("6.6.6", sys_info.firmware_version)
def test_map_dhw_empty_timeprogram(self) -> None: with open(path("files/responses/dhws_empty_timprogram"), "r") as file: raw_dhw = json.loads(file.read()) dhw = mapper.map_dhw(raw_dhw) self.assertIsNotNone(dhw.hotwater) self.assertIsNotNone(dhw.circulation) self.assertIsNotNone(dhw.circulation.time_program) self.assertIsNotNone(dhw.hotwater.time_program)
def test_schema_system_validation_error(self) -> None: """Ensure validation fails.""" with open(path("files/responses/systemcontrol_zone_no_config"), "r") as open_f: json_val = json.loads(open_f.read()) try: schemas.SYSTEM.validate(json_val) except SchemaError as err: self.assertIn("Missing key: 'configuration'", err.args[0])
def test_no_hotwater(self) -> None: """Test map no hot water.""" with open(path('files/responses/systemcontrol'), 'r') as file: raw_system = json.loads(file.read()) raw_system['body']['dhw'] = [] hot_water = mapper.map_hot_water(raw_system, {}) self.assertIsNone(hot_water)
async def test_get_hot_water(manager: SystemManager, resp: aioresponses) -> None: with open(path('files/responses/livereport'), 'r') as file: livereport_data = json.loads(file.read()) with open(path('files/responses/hotwater'), 'r') as file: raw_hotwater = json.loads(file.read()) dhw_url = urls.hot_water(id='Control_DHW', serial=SERIAL) resp.get(dhw_url, payload=raw_hotwater, status=200) report_url = urls.live_report(serial=SERIAL) resp.get(report_url, payload=livereport_data, status=200) hot_water = await manager.get_hot_water('Control_DHW') assert hot_water is not None _assert_calls(2, manager, [dhw_url, report_url])
def test_no_hotwater(self) -> None: """Test map no hot water.""" with open(path("files/responses/systemcontrol"), "r") as file: raw_system = json.loads(file.read()) raw_system["body"]["dhw"] = [] hot_water = mapper.map_hot_water_from_system(raw_system, {}) self.assertIsNone(hot_water)
def test_map_facility_detail(self) -> None: with open(path("files/responses/facilities"), "r") as file: facilities = json.loads(file.read()) sys_info = mapper.map_facility_detail(facilities) self.assertEqual("1234567890123456789012345678", sys_info.serial_number) self.assertEqual("Home", sys_info.name) self.assertEqual("01:23:45:67:89:AB", sys_info.ethernet_mac) self.assertEqual("1.2.3", sys_info.firmware_version)
def test_no_circulation(self) -> None: """Test map no circulation.""" with open(path('files/responses/systemcontrol'), 'r') as file: raw_system = json.loads(file.read()) raw_system['body']['dhw'] = [] circulation = mapper.map_circulation(raw_system) self.assertIsNone(circulation)
def test_no_circulation(self) -> None: """Test map no circulation.""" with open(path("files/responses/systemcontrol"), "r") as file: raw_system = json.loads(file.read()) raw_system["body"]["dhw"] = [] circulation = mapper.map_circulation_from_system(raw_system) self.assertIsNone(circulation)
def test_hot_water_alone(self) -> None: """Test map hot water.""" with open(path("files/responses/hotwater"), "r") as file: raw_hotwater = json.loads(file.read()) hotwater = mapper.map_hot_water(raw_hotwater, "control_dhw") self.assertEqual("control_dhw", hotwater.id) self.assertEqual(OperatingModes.AUTO, hotwater.operating_mode) self.assertIsNotNone(hotwater.time_program.days["monday"].settings[0].setting)