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__)
|
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
|
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}")
|
logger.info(f"Connected to {WS_URL}")
|
||||||
send_response = await websocket.send(json.dumps({
|
send_response = await websocket.send(json.dumps({
|
||||||
"action": "subscribe",
|
"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}")
|
logger.info(f"Subscribed to system {system_id}, waiting for messages..., send_response={send_response}")
|
||||||
async for message in websocket:
|
async for message in websocket:
|
||||||
as_json = json.loads(message)
|
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']
|
rx_var.rx.value = as_json['change']['state']
|
||||||
except ConnectionClosed:
|
except ConnectionClosed:
|
||||||
if must_reconnect:
|
if must_reconnect:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue