From b21dd3a26bba961afdfe390c9d3e056588317508 Mon Sep 17 00:00:00 2001
From: jkerdreux-imt <jerome.kerdreux@imt-atlantique.fr>
Date: Mon, 30 Dec 2024 16:28:56 +0100
Subject: [PATCH] Remove remote-console

Oups
---
 libs/lib/xaal/lib/aioengine.py | 21 +++++++++++++--------
 libs/lib/xaal/lib/core.py      |  4 ++--
 2 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/libs/lib/xaal/lib/aioengine.py b/libs/lib/xaal/lib/aioengine.py
index 888359df..721ba0bf 100644
--- a/libs/lib/xaal/lib/aioengine.py
+++ b/libs/lib/xaal/lib/aioengine.py
@@ -36,7 +36,7 @@ class HookType(Enum):
 class Hook(object):
     __slots__ = ['type', 'func', 'args', 'kwargs']
 
-    def __init__(self, type_:HookType, func: core.FuncT, *args, **kwargs):
+    def __init__(self, type_: HookType, func: core.FuncT, *args, **kwargs):
         # func has to be a callable, but it can be a coroutine or a function
         self.type = type_
         self.func = func
@@ -58,7 +58,8 @@ class AsyncEngine(core.EngineMixin):
     ]
 
     def __init__(
-        self, address: str = config.address, port: int = config.port, hops: int = config.hops, key: bytes = config.key):
+        self, address: str = config.address, port: int = config.port, hops: int = config.hops, key: bytes = config.key
+    ):
         core.EngineMixin.__init__(self, address, port, hops, key)
 
         self.__txFifo = asyncio.Queue()  # tx msg fifo
@@ -167,7 +168,7 @@ class AsyncEngine(core.EngineMixin):
 
     async def handle_action_request(self, msg: 'Message', target: 'Device'):
         if msg.action is None:
-            return # should not happen, but pyright need this check
+            return  # should not happen, but pyright need this check
 
         try:
             result = await run_action(msg, target)
@@ -250,7 +251,8 @@ class AsyncEngine(core.EngineMixin):
         self.new_task(self.receive_task(), name='RecvQ')
         self.new_task(self.send_task(), name='SendQ')
         self.new_task(self.timer_task(), name='Timers')
-        self.new_task(console(locals()), name='Console')
+        if config.remote_console:
+            self.new_task(console(locals()), name='Console')
 
     def setup_alives_timer(self):
         # needed on stop-start sequence
@@ -259,7 +261,7 @@ class AsyncEngine(core.EngineMixin):
         # process alives every 10 seconds
         self.add_timer(self.process_alives, 10)
 
-    async def stop(self): # pyright: ignore
+    async def stop(self):  # pyright: ignore
         logger.info("Stopping engine")
         await self.run_hooks(HookType.stop)
         self.running_event.clear()
@@ -340,7 +342,7 @@ class AsyncEngine(core.EngineMixin):
         self.dump_hooks()
 
     def get_device(self, uuid: UUID) -> Optional['Device']:
-        # TODO:Check if this method is usefull 
+        # TODO:Check if this method is usefull
         for dev in self.devices:
             if dev.address == uuid:
                 return dev
@@ -391,7 +393,8 @@ async def console(locals=locals(), port: Optional[int] = None):
         # let's find a free port if not specified
         def find_free_port():
             import socketserver
-            with socketserver.TCPServer(('localhost', 0), None) as s: # pyright: ignore pyright reject the None here
+
+            with socketserver.TCPServer(('localhost', 0), None) as s:  # pyright: ignore pyright reject the None here
                 return s.server_address[1]
 
         port = find_free_port()
@@ -407,6 +410,8 @@ async def console(locals=locals(), port: Optional[int] = None):
     # start the console
     try:
         # debian with ipv6 disabled still state that localhost is ::1, which broke aioconsole
-        await aioconsole.start_interactive_server(host="127.0.0.1", port=port, factory=factory, banner=banner) # pyright: ignore
+        await aioconsole.start_interactive_server(
+            host="127.0.0.1", port=port, factory=factory, banner=banner
+        )  # pyright: ignore
     except OSError:
         logger.warning("Unable to run console")
diff --git a/libs/lib/xaal/lib/core.py b/libs/lib/xaal/lib/core.py
index bcfb4993..43735410 100644
--- a/libs/lib/xaal/lib/core.py
+++ b/libs/lib/xaal/lib/core.py
@@ -56,7 +56,7 @@ class EngineMixin(object):
     __slots__ = ['devices', 'timers', 'subscribers', 'msg_filter', '_attributesChange', 'network', 'msg_factory']
 
     def __init__(self, address: str, port: int, hops: int, key: bytes):
-        self.devices:list[Device] = []  # list of devices / use (un)register_devices()
+        self.devices: list[Device] = []  # list of devices / use (un)register_devices()
         self.timers: list[Timer] = []  # functions to call periodic
         self.subscribers: list[SubFuncT] = []  # message receive workflow
         self.msg_filter = None  # message filter
@@ -134,7 +134,7 @@ class EngineMixin(object):
         self.queue_msg(msg)
         dev.update_alive()
 
-    def send_is_alive(self, dev: 'Device', targets: list = [ALIVE_ADDR,], dev_types: list = ["any.any", ] ):
+    def send_is_alive(self, dev: 'Device', targets: list = [ALIVE_ADDR], dev_types: list = ["any.any"]):
         """Send a is_alive message, w/ dev_types filtering"""
         body = {'dev_types': dev_types}
         self.send_request(dev, targets, MessageAction.IS_ALIVE.value, body)
-- 
GitLab