api: implement Server-Sent-Events on top of mqtt parameters
All checks were successful
Build Container / Build Container (push) Successful in 1m47s
All checks were successful
Build Container / Build Container (push) Successful in 1m47s
This commit is contained in:
parent
4103c0ca5f
commit
7ac0a4106c
2 changed files with 36 additions and 13 deletions
|
|
@ -1,10 +1,11 @@
|
|||
from typing import Optional, List
|
||||
from typing import Optional, List, AsyncIterable
|
||||
import logging
|
||||
import secrets
|
||||
import sys
|
||||
from datetime import datetime, UTC
|
||||
from fastapi import FastAPI, Request, Response, status
|
||||
from fastapi.responses import RedirectResponse
|
||||
from fastapi.sse import EventSourceResponse
|
||||
from contextlib import asynccontextmanager
|
||||
from simple_openid_connect.client import OpenidClient
|
||||
from simple_openid_connect.data import TokenSuccessResponse, RpInitiatedLogoutRequest
|
||||
|
|
@ -241,6 +242,18 @@ async def list_locks(ccujack: deps.CCUJackClient) -> List[models.Lock]:
|
|||
return result
|
||||
|
||||
|
||||
@app.get(
|
||||
"/api/locks/stream",
|
||||
tags=["locks"],
|
||||
responses={status.HTTP_401_UNAUTHORIZED: {"model": models.HttpProblemDetail}},
|
||||
response_class=EventSourceResponse,
|
||||
)
|
||||
async def watch_locks(ccujack: deps.CCUJackClient) -> AsyncIterable[List[models.Lock]]:
|
||||
while True:
|
||||
yield await list_locks(ccujack)
|
||||
await ccujack.data_updated.wait()
|
||||
|
||||
|
||||
@app.patch(
|
||||
"/api/locks/{lock_id}",
|
||||
tags=["locks"],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue