From 48471a8024e09d81b2d34187006fb5add9004afc Mon Sep 17 00:00:00 2001 From: "Bernd (Hermes)" Date: Thu, 23 Jul 2026 21:47:00 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20DDP=20set=5Fstatus=20auf=20UserPresence:?= =?UTF-8?q?setDefaultStatus=20umgestellt=20=E2=80=94=20falsche=20API-Metho?= =?UTF-8?q?de=20war=20Root=20Cause=20fuer=20unsichtbaren=20Status?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/adapter.py | 4 +- plugin/archivar/tests/test_ddp_room_events.py | 71 +++++++++++++++++++ 2 files changed, 73 insertions(+), 2 deletions(-) diff --git a/plugin/adapter.py b/plugin/adapter.py index 2c335a7..3cefacb 100644 --- a/plugin/adapter.py +++ b/plugin/adapter.py @@ -544,8 +544,8 @@ class DDPClient: def set_status(self, status: str) -> bool: if not self.connected: return False - method = f"UserPresence:{status}" - self._send_json({"msg": "method", "method": method, "params": [], "id": f"st{int(time.time()*1000)}"}) + method = "UserPresence:setDefaultStatus" + self._send_json({"msg": "method", "method": method, "params": [status], "id": f"st{int(time.time()*1000)}"}) return True def disconnect(self): diff --git a/plugin/archivar/tests/test_ddp_room_events.py b/plugin/archivar/tests/test_ddp_room_events.py index 134cc0e..97dc22c 100644 --- a/plugin/archivar/tests/test_ddp_room_events.py +++ b/plugin/archivar/tests/test_ddp_room_events.py @@ -129,3 +129,74 @@ class TestDDPRoomEvents: client._handle_ddp_message(event_data) assert len(received_events) == 0 + + +class TestDDPSetStatus: + """Tests für DDPClient.set_status — P0 Fix: UserPresence:setDefaultStatus.""" + + def test_set_status_online_sends_correct_json(self): + """set_status('online') sendet UserPresence:setDefaultStatus mit params=['online'].""" + from adapter import DDPClient + + client = DDPClient("test.example.com") + client.connected = True + client.sock = MagicMock() + + with patch.object(client, "_send_json") as mock_send: + result = client.set_status("online") + + assert result is True + mock_send.assert_called_once() + call_args = mock_send.call_args[0][0] + assert call_args["msg"] == "method" + assert call_args["method"] == "UserPresence:setDefaultStatus" + assert call_args["params"] == ["online"] + assert call_args["id"].startswith("st") + + def test_set_status_away_sends_correct_json(self): + """set_status('away') sendet UserPresence:setDefaultStatus mit params=['away'].""" + from adapter import DDPClient + + client = DDPClient("test.example.com") + client.connected = True + client.sock = MagicMock() + + with patch.object(client, "_send_json") as mock_send: + result = client.set_status("away") + + assert result is True + mock_send.assert_called_once() + call_args = mock_send.call_args[0][0] + assert call_args["msg"] == "method" + assert call_args["method"] == "UserPresence:setDefaultStatus" + assert call_args["params"] == ["away"] + assert call_args["id"].startswith("st") + + def test_set_status_busy_sends_correct_json(self): + """set_status('busy') sendet UserPresence:setDefaultStatus mit params=['busy'].""" + from adapter import DDPClient + + client = DDPClient("test.example.com") + client.connected = True + client.sock = MagicMock() + + with patch.object(client, "_send_json") as mock_send: + result = client.set_status("busy") + + assert result is True + mock_send.assert_called_once() + call_args = mock_send.call_args[0][0] + assert call_args["msg"] == "method" + assert call_args["method"] == "UserPresence:setDefaultStatus" + assert call_args["params"] == ["busy"] + assert call_args["id"].startswith("st") + + def test_set_status_disconnected_returns_false(self): + """set_status gibt False zurück wenn nicht connected.""" + from adapter import DDPClient + + client = DDPClient("test.example.com") + client.connected = False + + result = client.set_status("online") + assert result is False