add token for token auth
This commit is contained in:
parent
3b3b8f1ac1
commit
7347636311
1 changed files with 8 additions and 3 deletions
|
|
@ -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,12 +23,17 @@ 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)
|
||||
rx_var.rx.value = as_json['change']['state']
|
||||
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:
|
||||
logger.info("connection closed, retrying...")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue