From 4b1b90fd3a6a1d633bc7946e6132d36794f82c33 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Mon, 2 Sep 2024 11:24:54 +0200 Subject: [PATCH] Add option to disable server interaction Add a new CLI option to disable server interactions. This is useful for testing, to isolate if enabled server interaction might cause unexpected device behavior. --- matter_server/server/__main__.py | 6 ++++++ matter_server/server/server.py | 7 ++++--- matter_server/server/stack.py | 5 ++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/matter_server/server/__main__.py b/matter_server/server/__main__.py index f12bdd44..171f1047 100644 --- a/matter_server/server/__main__.py +++ b/matter_server/server/__main__.py @@ -122,6 +122,11 @@ default=None, help="Directory where OTA Provider stores software updates and configuration.", ) +parser.add_argument( + "--disable-server-interactions", + action="store_false", + help="Controls disabling server cluster interactions on a controller. This in turn disables advertisement of active controller operational identities.", +) args = parser.parse_args() @@ -223,6 +228,7 @@ def main() -> None: args.enable_test_net_dcl, args.bluetooth_adapter, args.ota_provider_dir, + args.disable_server_interactions, ) async def handle_stop(loop: asyncio.AbstractEventLoop) -> None: diff --git a/matter_server/server/server.py b/matter_server/server/server.py index 0bccdb14..68b78f00 100644 --- a/matter_server/server/server.py +++ b/matter_server/server/server.py @@ -95,12 +95,12 @@ async def _handle_shutdown(app: web.Application) -> None: class MatterServer: """Serve Matter stack over WebSockets.""" - # pylint: disable=too-many-instance-attributes,too-many-arguments + # pylint: disable=too-many-instance-attributes _runner: web.AppRunner | None = None _http: MultiHostTCPSite | None = None - def __init__( + def __init__( # noqa: PLR0913, pylint: disable=too-many-arguments self, storage_path: str, vendor_id: int, @@ -112,6 +112,7 @@ def __init__( enable_test_net_dcl: bool = False, bluetooth_adapter_id: int | None = None, ota_provider_dir: Path | None = None, + enable_server_interactions: bool = True, ) -> None: """Initialize the Matter Server.""" self.storage_path = storage_path @@ -134,7 +135,7 @@ def __init__( self.app = web.Application() self.loop: asyncio.AbstractEventLoop | None = None # Instantiate the Matter Stack using the SDK using the given storage path - self.stack = MatterStack(self, bluetooth_adapter_id) + self.stack = MatterStack(self, bluetooth_adapter_id, enable_server_interactions) self.storage = StorageController(self) self.vendor_info = VendorInfo(self) # we dynamically register command handlers diff --git a/matter_server/server/stack.py b/matter_server/server/stack.py index 5c822454..2393bead 100644 --- a/matter_server/server/stack.py +++ b/matter_server/server/stack.py @@ -90,6 +90,7 @@ def __init__( self, server: "MatterServer", bluetooth_adapter_id: int | None = None, + enable_server_interactions: bool = True, ) -> None: """Initialize Matter Stack.""" self.logger = logging.getLogger(__name__) @@ -114,9 +115,11 @@ def __init__( # Handle log level selection on SDK level chip.logging.SetLogFilter(_category_num) + if not enable_server_interactions: + self.logger.warning("Initializing stack with server interactions disabled!") self._chip_stack = ChipStack( persistentStoragePath=storage_file, - enableServerInteractions=True, + enableServerInteractions=enable_server_interactions, ) # Initialize Certificate Authority Manager