ensured ci passes
This commit is contained in:
1 parent
079f353dbf
commit
e7b88fc6f6
4 files changed
+4
-23
No files matched your search
@@ -8,7 +8,7 @@ router = APIRouter()
|
||||
|
||||
@router.websocket("/api/websocket")
|
||||
async def websocket_endpoint(websocket: WebSocket):
|
||||
async def on_message(ws: WSRedirector, msg: str):
|
||||
async def on_message(msg: str):
|
||||
await websocket.send_text(msg)
|
||||
|
||||
conn = WSRedirector(
|
||||
|
||||
@@ -2,10 +2,8 @@ import json
|
||||
import websockets
|
||||
|
||||
from typing import Callable, Coroutine, Optional
|
||||
from http import HTTPStatus
|
||||
|
||||
from websockets.client import ClientConnection
|
||||
from fastapi.exceptions import HTTPException
|
||||
|
||||
from src.logger import logger
|
||||
from src.env import HASSIO_TOKEN, HASSIO_WS
|
||||
@@ -13,16 +11,6 @@ from src.env import HASSIO_TOKEN, HASSIO_WS
|
||||
OnMessage = Callable[[dict], Coroutine]
|
||||
|
||||
|
||||
class WSRedirectorError(HTTPException):
|
||||
def __init__(self, status_code: int) -> None:
|
||||
super().__init__(status_code, detail={"message": str(self.__class__.__name__)})
|
||||
|
||||
|
||||
class WSDisconnectedMessage(WSRedirectorError):
|
||||
def __init__(self) -> None:
|
||||
super().__init__(status_code=HTTPStatus.FAILED_DEPENDENCY)
|
||||
|
||||
|
||||
class WSRedirector:
|
||||
def __init__(
|
||||
self,
|
||||
@@ -33,7 +21,6 @@ class WSRedirector:
|
||||
self._host = host
|
||||
self._token = token
|
||||
self._on_message = on_message
|
||||
self._authenticated = False
|
||||
self._client: Optional[ClientConnection] = None
|
||||
self._close: bool = False
|
||||
|
||||
@@ -41,15 +28,9 @@ class WSRedirector:
|
||||
def is_closed(self):
|
||||
return self._close
|
||||
|
||||
@property
|
||||
def is_authenticated(self):
|
||||
return self._authenticated
|
||||
|
||||
async def send(self, msg: str):
|
||||
if self._client:
|
||||
return await self._client.send(msg)
|
||||
# else:
|
||||
# raise WSDisconnectedMessage()
|
||||
|
||||
async def start(self):
|
||||
async with websockets.connect(self._host) as websocket:
|
||||
@@ -61,7 +42,7 @@ class WSRedirector:
|
||||
await self.process_message(msg)
|
||||
|
||||
async def process_message(self, msg: str):
|
||||
await self._on_message(self, msg)
|
||||
await self._on_message(msg)
|
||||
|
||||
def close(self):
|
||||
self._close = True
|
||||
|
||||
Reference in new issue
Block a user