Skip to content

Commit

Permalink
routers.client: add disconnect action in api_post_client
Browse files Browse the repository at this point in the history
This makes it easy to reproduce the problem in Willow where the WAS
WebSocket client sometimes does not reconnect after the WebSocket has
been closed.
  • Loading branch information
stintel committed Jan 17, 2024
1 parent eeee7cc commit e119c76
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion app/routers/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async def api_get_client(request: Request):


class PostClient(BaseModel):
action: Literal['restart', 'update', 'config', 'identify', 'notify'] = Field(
action: Literal['restart', 'update', 'config', 'identify', 'notify', 'disconnect'] = Field(
Query(..., description='Client action')
)

Expand Down Expand Up @@ -92,6 +92,14 @@ async def api_post_client(request: Request, device: PostClient = Depends()):
with open(STORAGE_USER_CLIENT_CONFIG, "w") as devices_file:
json.dump(devices, devices_file)
devices_file.close()
elif device.action == "disconnect":
try:
ws = request.app.connmgr.get_client_by_hostname(data["hostname"])
await ws.close(reason="disconnected via WAS API")
except Exception as e:
log.error(f"failed to disconnect client: ({e})")
finally:
return
elif device.action == 'notify':
log.debug(f"received notify command on API: {data}")
warm_tts(data["data"])
Expand Down

0 comments on commit e119c76

Please sign in to comment.