text: """Unit test for KNX/IP ConnectResponses."""
  import pytest
  from xknx import XKNX
  from xknx.exceptions import CouldNotParseKNXIP
  from xknx.knxip import HPAI, ConnectRequestType, ConnectResponse, ErrorCode, KNXIPFrame
  
  
  class TestKNXIPConnectResponse:
      """Test class for KNX/IP ConnectResponses."""
  
      def test_connect_response(self):
          """Test parsing and streaming connection response KNX/IP packet."""
          raw = (
              0x06,
              0x10,
              0x02,
              0x06,
              0x00,
              0x14,
              0x01,
              0x00,
              0x08,
              0x01,
              0xC0,
              0xA8,
              0x2A,
              0x0A,
              0x0E,
              0x57,
              0x04,
              0x04,
              0x11,
              0xFF,
          )
          xknx = XKNX()
          knxipframe = KNXIPFrame(xknx)
          knxipframe.from_knx(raw)
          assert isinstance(knxipframe.body, ConnectResponse)
          assert knxipframe.body.communication_channel == 1
          assert knxipframe.body.status_code == ErrorCode.E_NO_ERROR
          assert knxipframe.body.data_endpoint == HPAI(ip_addr="192.168.42.10", port=3671)
          assert knxipframe.body.request_type == ConnectRequestType.TUNNEL_CONNECTION
          assert knxipframe.body.identifier == 4607
  
          connect_response = ConnectResponse(
              xknx,
              communication_channel=1,
              status_code=ErrorCode.E_NO_ERROR,
              request_type=ConnectRequestType.TUNNEL_CONNECTION,
              data_endpoint=HPAI(ip_addr="192.168.42.10", port=3671),
              identifier=4607,
          )
          knxipframe2 = KNXIPFrame.init_from_body(connect_response)
  
          assert knxipframe2.to_knx() == list(raw)
  
      def test_from_knx_wrong_crd(self):
          """Test parsing and streaming wrong ConnectRequest (wrong CRD length byte)."""
          raw = (
              0x06,
              0x10,
              0x02,
              0x06,
              0x00,
              0x14,
              0x01,
              0x00,
              0x08,
              0x01,
              0xC0,
              0xA8,
              0x2A,
              0x0A,
              0x0E,
              0x57,
              0x03,
              0x04,
              0x11,
              0xFF,
          )
          xknx = XKNX()
          knxipframe = KNXIPFrame(xknx)
          with pytest.raises(CouldNotParseKNXIP):
              knxipframe.from_knx(raw)
  
      def test_from_knx_wrong_crd2(self):
          """Test parsing and streaming wrong ConnectRequest (wrong CRD length)."""
          raw = (
              0x06,
              0x10,
              0x02,
              0x06,
              0x00,
              0x14,
              0x01,
              0x00,
              0x08,
              0x01,
              0xC0,
              0xA8,
              0x2A,
              0x0A,
              0x0E,
              0x57,
              0x04,
              0x04,
          )
          xknx = XKNX()
          knxipframe = KNXIPFrame(xknx)
          with pytest.raises(CouldNotParseKNXIP):
              knxipframe.from_knx(raw)
  
      def test_connect_response_connection_error_gira(self):
          """
          Test parsing and streaming connection response KNX/IP packet with error e_no_more_connections.
          HPAI and CRD normal. This was received from Gira devices (2020).
          """
          raw = (
              0x06,
              0x10,
              0x02,
              0x06,
              0x00,
              0x14,
              0xC0,
              0x24,
              0x08,
              0x01,
              0x0A,
              0x01,
              0x00,
              0x29,
              0x0E,
              0x57,
              0x04,
              0x04,
              0x00,
              0x00,
          )
          xknx = XKNX()
          knxipframe = KNXIPFrame(xknx)
          knxipframe.from_knx(raw)
          assert isinstance(knxipframe.body, ConnectResponse)
          assert knxipframe.body.status_code == ErrorCode.E_NO_MORE_CONNECTIONS
          assert knxipframe.body.communication_channel == 192
  
          connect_response = ConnectResponse(
              xknx,
              communication_channel=192,
              status_code=ErrorCode.E_NO_MORE_CONNECTIONS,
              request_type=ConnectRequestType.TUNNEL_CONNECTION,
              data_endpoint=HPAI(ip_addr="10.1.0.41", port=3671),
              identifier=0,
          )
          knxipframe2 = KNXIPFrame.init_from_body(connect_response)
  
          assert knxipframe2.to_knx() == list(raw)
  
      def test_connect_response_connection_error_lox(self):
          """
          Test parsing and streaming connection response KNX/IP packet with error e_no_more_connections.
          HPAI given, CRD all zero. This was received from Loxone device (2020).
          """
          raw = (
              0x06,
              0x10,
              0x02,
              0x06,
              0x00,
              0x14,
              0x00,
              0x24,
              0x08,
              0x01,
              0xC0,
              0xA8,
              0x01,
              0x01,
              0x0E,
              0x57,
              0x00,
              0x00,
              0x00,
              0x00,
          )
          xknx = XKNX()
          knxipframe = KNXIPFrame(xknx)
          knxipframe.from_knx(raw)
          assert isinstance(knxipframe.body, ConnectResponse)
          assert knxipframe.body.status_code == ErrorCode.E_NO_MORE_CONNECTIONS
          assert knxipframe.body.communication_channel == 0
  
          # no further tests: the current API can't (and shouldn't) create such odd packets
  
      def test_connect_response_connection_error_mdt(self):
          """
          Test parsing and streaming connection response KNX/IP packet with error e_no_more_connections.
          HPAI and CRD all zero. This was received from MDT device (2020).
          """
          raw = (
              0x06,
              0x10,
              0x02,
              0x06,
              0x00,
              0x08,
              0x00,
              0x24,
              0x00,
              0x00,
              0x00,
              0x00,
              0x00,
              0x00,
              0x00,
              0x00,
              0x00,
              0x00,
          )
          xknx = XKNX()
          knxipframe = KNXIPFrame(xknx)
          knxipframe.from_knx(raw)
          assert isinstance(knxipframe.body, ConnectResponse)
          assert knxipframe.body.status_code == ErrorCode.E_NO_MORE_CONNECTIONS
          assert knxipframe.body.communication_channel == 0
  
          # no further tests: the current API can't (and shouldn't) create such odd packets
  