From 5b7d086770af3f187539f5b156bee0f1c11f72ef Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mika=C3=ABl=20Dallaire=20C=C3=B4t=C3=A9?=
 <110583667+0mdc@users.noreply.github.com>
Date: Wed, 1 May 2024 21:25:54 -0700
Subject: [PATCH] Add mock connection parameter config for testing purposes.
 (#1930)

---
 .../_internal/networking/networking_process.py   | 16 ++++++++++++++++
 .../habitat_hitl/config/hitl_defaults.yaml       |  3 +++
 2 files changed, 19 insertions(+)

diff --git a/habitat-hitl/habitat_hitl/_internal/networking/networking_process.py b/habitat-hitl/habitat_hitl/_internal/networking/networking_process.py
index 57c4208ed8..93a2a83f4e 100644
--- a/habitat-hitl/habitat_hitl/_internal/networking/networking_process.py
+++ b/habitat-hitl/habitat_hitl/_internal/networking/networking_process.py
@@ -29,6 +29,7 @@
     get_empty_keyframe,
     update_consolidated_keyframe,
 )
+from habitat_hitl.core.hydra_utils import ConfigObject
 from habitat_hitl.core.types import (
     ClientState,
     ConnectionRecord,
@@ -282,6 +283,21 @@ async def handle_connection(self, websocket: ClientConnection) -> None:
                 )
             print("Client is ready!")
             connection_record["connectionId"] = connection_id
+
+            # Copy test connection parameters from "mock_connection_params_dict".
+            if "mock_connection_params_dict" in self._networking_config:
+                mock_connection_params_dict = (
+                    self._networking_config.mock_connection_params_dict
+                )
+                if mock_connection_params_dict is not None and isinstance(
+                    mock_connection_params_dict, ConfigObject
+                ):
+                    for (
+                        key,
+                        value,
+                    ) in mock_connection_params_dict.__dict__.items():
+                        connection_record[key] = value
+
             self._interprocess_record.send_connection_record_to_main_thread(
                 connection_record
             )
diff --git a/habitat-hitl/habitat_hitl/config/hitl_defaults.yaml b/habitat-hitl/habitat_hitl/config/hitl_defaults.yaml
index 01b4882619..98f3df12a6 100644
--- a/habitat-hitl/habitat_hitl/config/hitl_defaults.yaml
+++ b/habitat-hitl/habitat_hitl/config/hitl_defaults.yaml
@@ -37,6 +37,9 @@ habitat_hitl:
     # Optionally kick an idle client after n seconds.
     client_max_idle_duration: ~
 
+    # Override incoming client connection parameters for testing purposes.
+    mock_connection_params_dict: None
+
     client_sync:
       # If enabled, the server main camera transform will be sent to the client. Disable if the client should control its own camera (e.g. VR), or if clients must use different camera transforms (e.g. multiplayer).
       server_camera: True