Skip to content

dashboard

DashboardNamespace #

Bases: AsyncNamespace

Handle all SocketIO events related to Beacon dashboard.

Source code in cogip/tools/server_beacon/namespaces/dashboard.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
class DashboardNamespace(socketio.AsyncNamespace):
    """
    Handle all SocketIO events related to Beacon dashboard.
    """

    def __init__(self, cogip_server: "server.Server"):
        super().__init__("/dashboard")
        self.cogip_server = cogip_server

    def on_connect(self, sid, environ):
        pass

    async def on_connected(self, sid):
        logger.info("Dashboard connected.")
        for robot_id, robot in self.cogip_server.robots.items():
            if robot.sio.connected:
                await self.cogip_server.sio.emit("add_robot", robot_id, namespace="/dashboard")
        await self.emit(
            "tool_menu",
            menu.model_dump(),
            namespace="/dashboard",
        )

    def on_disconnect(self, sid):
        logger.info("Dashboard disconnected.")

    async def on_tool_cmd(self, sid, cmd: str):
        match cmd:
            case "choose_camp":
                await self.cogip_server.choose_camp()
            case "choose_table":
                await self.cogip_server.choose_table()
            case "reset":
                await self.cogip_server.reset_robots()
            case "start":
                for _, robot in self.cogip_server.robots.items():
                    if robot.sio.connected:
                        await robot.sio.emit("command", "play", namespace="/beacon")
            case _:
                logger.warning(f"Unknown command: {cmd}")

    async def on_wizard(self, sid, data: dict[str, Any]):
        """
        Callback on wizard message.
        """
        for _, robot in self.cogip_server.robots.items():
            if robot.sio.connected:
                await robot.sio.emit("wizard", data, namespace="/beacon")
        await self.cogip_server.sio.emit("close_wizard", namespace="/dashboard")

        match data.get("name"):
            case "Choose Camp":
                self.cogip_server.camp = Camp.Colors[data["value"]]
            case "Choose Table":
                self.cogip_server.table = TableEnum[data["value"]]

on_wizard(sid, data) async #

Callback on wizard message.

Source code in cogip/tools/server_beacon/namespaces/dashboard.py
52
53
54
55
56
57
58
59
60
61
62
63
64
65
async def on_wizard(self, sid, data: dict[str, Any]):
    """
    Callback on wizard message.
    """
    for _, robot in self.cogip_server.robots.items():
        if robot.sio.connected:
            await robot.sio.emit("wizard", data, namespace="/beacon")
    await self.cogip_server.sio.emit("close_wizard", namespace="/dashboard")

    match data.get("name"):
        case "Choose Camp":
            self.cogip_server.camp = Camp.Colors[data["value"]]
        case "Choose Table":
            self.cogip_server.table = TableEnum[data["value"]]