36 lines
1015 B
Python
Executable File
36 lines
1015 B
Python
Executable File
import asyncio
|
|
import aiohttp
|
|
from matter_server.client import MatterClient
|
|
|
|
async def main():
|
|
# Crée une session HTTP asynchrone
|
|
async with aiohttp.ClientSession() as session:
|
|
client = MatterClient(
|
|
aiohttp_session=session,
|
|
ws_server_url="ws://localhost:5580/ws"
|
|
)
|
|
|
|
ready_event = asyncio.Event()
|
|
await client.connect()
|
|
|
|
@client.on("ready")
|
|
async def on_ready():
|
|
print("✅ PMS est prêt.")
|
|
ready_event.set()
|
|
|
|
@client.on("node_added")
|
|
async def on_node_added(node):
|
|
print(f"🆕 Node ajouté : {node.node_id}, {node.product_name}")
|
|
|
|
# await client.connect()
|
|
await ready_event.wait()
|
|
|
|
print("📦 Nœuds déjà connus :")
|
|
for node in client.nodes:
|
|
print(f" - ID: {node.node_id}, Produit: {node.product_name}")
|
|
|
|
await asyncio.sleep(5) # Attendre pour voir les nouveaux events
|
|
await client.disconnect()
|
|
|
|
asyncio.run(main())
|