add token for token auth

This commit is contained in:
Chris Oloff 2025-12-15 07:34:30 +02:00
parent 3b3b8f1ac1
commit 7347636311

View file

@ -8,7 +8,7 @@ from websockets.asyncio.client import connect
logger = logging.getLogger(__name__)
def attach_w42_state(rx_var: panel.rx, system_id: str):
def attach_w42_state(rx_var: panel.rx, system_id: str, token: str):
WS_URL = "ws://localhost:8000/ws/systems" # TODO: make configurable
@ -23,11 +23,16 @@ def attach_w42_state(rx_var: panel.rx, system_id: str):
logger.info(f"Connected to {WS_URL}")
send_response = await websocket.send(json.dumps({
"action": "subscribe",
"system_id": system_id
"system_id": system_id,
"token": token
}))
logger.info(f"Subscribed to system {system_id}, waiting for messages..., send_response={send_response}")
async for message in websocket:
as_json = json.loads(message)
if as_json.get('error'):
logger.error(f"Error from websocket: {as_json['error']}")
rx_var.rx.value = as_json
else:
rx_var.rx.value = as_json['change']['state']
except ConnectionClosed:
if must_reconnect: