From d3454c8dfa579b527c6845d9a3e0b0299a775fef Mon Sep 17 00:00:00 2001
From: jkerdreux-imt <jerome.kerdreux@imt-atlantique.fr>
Date: Fri, 31 Jan 2025 02:01:30 +0100
Subject: [PATCH] Initial nodes found ;)

---
 devices/protocols/ZwaveJS/xaal/zwavejs/gw.py | 24 +++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/devices/protocols/ZwaveJS/xaal/zwavejs/gw.py b/devices/protocols/ZwaveJS/xaal/zwavejs/gw.py
index 829265e6..82fb319c 100644
--- a/devices/protocols/ZwaveJS/xaal/zwavejs/gw.py
+++ b/devices/protocols/ZwaveJS/xaal/zwavejs/gw.py
@@ -1,10 +1,14 @@
 # from xaal.lib import tools
 
+import asyncio
 import pdb
 import logging
 from zwave_js_server.client import Client as ZwaveClient
 from aiohttp.client import ClientSession
 
+from xaal.lib import AsyncEngine, Device
+from xaal.schemas import devices
+
 
 PACKAGE_NAME = 'xaal.zwavejs'
 logger = logging.getLogger(__name__)
@@ -13,17 +17,31 @@ URL = "ws://10.77.3.143:3000"
 
 
 class GW:
-    def __init__(self, engine):
+    def __init__(self, engine: AsyncEngine):
         self.engine = engine
         logger.debug("ZwaveJS gateway initialized")
         engine.on_start(self.start)
+        gw = devices.gateway()
+        gw.new_attribute("gw", self)
+        engine.add_device(gw)
 
     async def start(self):
         sess = ClientSession()
         self.client = ZwaveClient(URL, sess)
         await self.client.connect()
-        await self.client.initialize()
-        await self.client.receive_until_closed()
+        self.ready = asyncio.Event()
+        self.engine.new_task(self.client.listen(self.ready))
+        # await self.client.listen(ready)
+        logger.warning("Done")
+        await self.run()
+
+    async def run(self):
+        await self.ready.wait()
+        # logger.warning(self.client.controller.nodes)
+        logger.warning("ZwaveJS ready")
+        nodes = self.client.driver.controller.nodes
+        for node in nodes:
+            logger.warning(node)
 
 
 def setup(eng):
-- 
GitLab