초기 커밋
This commit is contained in:
28
app/communication/socketio/namespaces/device_ns.py
Normal file
28
app/communication/socketio/namespaces/device_ns.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import structlog
|
||||
|
||||
from app.communication.socketio.server import sio
|
||||
|
||||
logger = structlog.get_logger("socketio.device")
|
||||
|
||||
|
||||
@sio.on("connect", namespace="/device")
|
||||
async def device_connect(sid: str, environ: dict) -> None:
|
||||
logger.info("device_ns_connected", sid=sid)
|
||||
|
||||
|
||||
@sio.on("disconnect", namespace="/device")
|
||||
async def device_disconnect(sid: str) -> None:
|
||||
logger.info("device_ns_disconnected", sid=sid)
|
||||
|
||||
|
||||
@sio.on("send_command", namespace="/device")
|
||||
async def send_command(sid: str, data: dict) -> None:
|
||||
device_uid = data.get("device_uid")
|
||||
command = data.get("command")
|
||||
if device_uid and command:
|
||||
from app.communication.mqtt.publisher import publish_command
|
||||
|
||||
await publish_command(device_uid, command)
|
||||
logger.info("command_sent", device_uid=device_uid)
|
||||
Reference in New Issue
Block a user