29 lines
832 B
Python
29 lines
832 B
Python
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)
|