Spaces:
Running
Running
| # modules/remote_control.py | |
| from typing import Dict, Any | |
| class RemoteControl: | |
| # Klassen-Attribut verhindert den Verlust der Geräteliste bei Neu-Instanziierung | |
| _connected_devices: Dict[str, Dict[str, str]] = {} | |
| def __init__(self): | |
| print("RemoteControl geladen") | |
| def connected_devices(self) -> Dict[str, Dict[str, str]]: | |
| return RemoteControl._connected_devices | |
| def connect_device(self, device_id: str, device_type: str) -> Dict[str, str]: | |
| self.connected_devices[device_id] = { | |
| "type": device_type, | |
| "status": "connected" | |
| } | |
| return { | |
| "device_id": device_id, | |
| "status": "connected" | |
| } | |
| def disconnect_device(self, device_id: str) -> Dict[str, str]: | |
| if device_id in self.connected_devices: | |
| self.connected_devices[device_id]["status"] = "disconnected" | |
| return { | |
| "device_id": device_id, | |
| "status": "disconnected" | |
| } | |
| return { | |
| "error": "Gerät nicht gefunden" | |
| } | |
| def send_command(self, device_id: str, command: str) -> Dict[str, Any]: | |
| if device_id not in self.connected_devices: | |
| return { | |
| "error": "Gerät nicht verbunden" | |
| } | |
| # Falls ein Gerät den Status 'disconnected' hat, wird das Senden blockiert | |
| if self.connected_devices[device_id].get("status") != "connected": | |
| return { | |
| "error": "Gerät ist offline" | |
| } | |
| return { | |
| "device_id": device_id, | |
| "command": command, | |
| "status": "sent" | |
| } | |
| def list_devices(self) -> Dict[str, Dict[str, str]]: | |
| return self.connected_devices | |