matter/lister.py
2025-05-27 16:58:58 +02:00

43 lines
1.4 KiB
Python
Executable File

#!python
import aiohttp
import asyncio
from matter_server.client import MatterClient
from matter_server.client.models.node import MatterNode
async def list_devices(ws_server_url):
# Créer une session aiohttp
async with aiohttp.ClientSession() as session:
# Initialiser le client Matter avec la session aiohttp
async with MatterClient(ws_server_url, session) as client:
client.logger.setLevel("DEBUG")
await client.connect()
print(f"Fabric ID ---> {client.server_info}")
# print(f"---------------> {}")
print("✅ Connecté à PMS. Attente de synchronisation des nœuds...")
# Boucle d'attente simple pendant 5 secondes max
# for i in range(30):
# print(f"... {i}")
# if client.get_nodes():
# break
# await asyncio.sleep(1)
try:
# fabrics:list[MatterFabricData] = client.get_matter_fabrics(node_id=)
# for fabric in fabrics:
# print(f"Fabric ID: {fabric.fabric_id()}")
nodes:list[MatterNode] = client.get_nodes()
for node in nodes:
print(f"Device ID: {node.node_id()}, Name: {node.name()}")
except Exception as e:
print(f"Erreur lors de la récupération des appareils: {e}")
# Remplacez par l'adresse IP de votre python-matter-server
ws_server_url = "ws://localhost:5580/ws"
# Exécuter la fonction asynchrone
asyncio.run(list_devices(ws_server_url))