def test_search_response(self): """Test string representation of KNX/IP SearchResponse.""" xknx = XKNX(loop=self.loop) search_response = SearchResponse(xknx) search_response.control_endpoint = HPAI(ip_addr='192.168.42.1', port=33941) search_response.dibs.append(DIBGeneric()) search_response.dibs.append(DIBGeneric()) self.assertEqual( str(search_response), '<SearchResponse control_endpoint="<HPAI 192.168.42.1:33941 />" dibs="[\n' '<DIB dtc="None" data="" />,\n' '<DIB dtc="None" data="" />\n' ']" />')
def fake_router_search_response(xknx: XKNX) -> SearchResponse: """Return the SearchResponse of a KNX/IP Router.""" _frame_header = KNXIPHeader(xknx) _frame_header.service_type_ident = KNXIPServiceType.SEARCH_RESPONSE _frame_body = SearchResponse(xknx) _frame_body.control_endpoint = HPAI(ip_addr="192.168.42.10", port=3671) _device_information = DIBDeviceInformation() _device_information.name = "Gira KNX/IP-Router" _device_information.serial_number = "11:22:33:44:55:66" _device_information.individual_address = PhysicalAddress("1.1.0") _device_information.mac_address = "01:02:03:04:05:06" _svc_families = DIBSuppSVCFamilies() _svc_families.families.append( DIBSuppSVCFamilies.Family(name=DIBServiceFamily.CORE, version=1)) _svc_families.families.append( DIBSuppSVCFamilies.Family(name=DIBServiceFamily.DEVICE_MANAGEMENT, version=2)) _svc_families.families.append( DIBSuppSVCFamilies.Family(name=DIBServiceFamily.TUNNELING, version=1)) _svc_families.families.append( DIBSuppSVCFamilies.Family(name=DIBServiceFamily.ROUTING, version=1)) _svc_families.families.append( DIBSuppSVCFamilies.Family(name=DIBServiceFamily.REMOTE_CONFIGURATION_DIAGNOSIS, version=1)) _frame_body.dibs.append(_device_information) _frame_body.dibs.append(_svc_families) _frame_header.set_length(_frame_body) search_response = KNXIPFrame(xknx) search_response.init(KNXIPServiceType.SEARCH_RESPONSE) search_response.header = _frame_header search_response.body = _frame_body search_response.normalize() return search_response
def test_search_response(self): """Test parsing and streaming SearchResponse KNX/IP packet.""" raw = ( 0x06, 0x10, 0x02, 0x02, 0x00, 0x50, 0x08, 0x01, 0xC0, 0xA8, 0x2A, 0x0A, 0x0E, 0x57, 0x36, 0x01, 0x02, 0x00, 0x11, 0x00, 0x00, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0xE0, 0x00, 0x17, 0x0C, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x47, 0x69, 0x72, 0x61, 0x20, 0x4B, 0x4E, 0x58, 0x2F, 0x49, 0x50, 0x2D, 0x52, 0x6F, 0x75, 0x74, 0x65, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x02, 0x02, 0x01, 0x03, 0x02, 0x04, 0x01, 0x05, 0x01, 0x07, 0x01, ) xknx = XKNX() knxipframe = KNXIPFrame(xknx) self.assertEqual(knxipframe.from_knx(raw), 80) self.assertEqual(knxipframe.to_knx(), list(raw)) self.assertTrue(isinstance(knxipframe.body, SearchResponse)) self.assertEqual(knxipframe.body.control_endpoint, HPAI("192.168.42.10", 3671)) self.assertEqual(len(knxipframe.body.dibs), 2) # Specific testing of parsing and serializing of # DIBDeviceInformation and DIBSuppSVCFamilies is # done within knxip_dib_test.py self.assertTrue( isinstance(knxipframe.body.dibs[0], DIBDeviceInformation)) self.assertTrue(isinstance(knxipframe.body.dibs[1], DIBSuppSVCFamilies)) self.assertEqual(knxipframe.body.device_name, "Gira KNX/IP-Router") self.assertTrue(knxipframe.body.dibs[1].supports( DIBServiceFamily.ROUTING)) self.assertTrue(knxipframe.body.dibs[1].supports( DIBServiceFamily.TUNNELING)) self.assertFalse(knxipframe.body.dibs[1].supports( DIBServiceFamily.OBJECT_SERVER)) search_response = SearchResponse(xknx, control_endpoint=HPAI( ip_addr="192.168.42.10", port=3671)) search_response.dibs.append(knxipframe.body.dibs[0]) search_response.dibs.append(knxipframe.body.dibs[1]) knxipframe2 = KNXIPFrame.init_from_body(search_response) self.assertEqual(knxipframe2.to_knx(), list(raw))
def test_unknown_device_name(self): """Test device_name if no DIBDeviceInformation is present.""" xknx = XKNX() search_response = SearchResponse(xknx) self.assertEqual(search_response.device_name, "UNKNOWN")
def test_unknown_device_name(self): """Test device_name if no DIBDeviceInformation is present.""" search_response = SearchResponse() assert search_response.device_name == "UNKNOWN"