11import json
22from collections .abc import Awaitable , Callable
3- from typing import Any
3+ from typing import Any , cast
44
55import pytest
66
77from roborock .data .b01_q10 .b01_q10_code_mappings import YXCleanType , YXFanLevel
88from roborock .devices .traits .b01 .q10 import Q10PropertiesApi
9+ from roborock .devices .traits .b01 .q10 .status import StatusTrait
910from roborock .devices .traits .b01 .q10 .vacuum import VacuumTrait
11+ from roborock .roborock_message import RoborockMessage , RoborockMessageProtocol
1012from tests .fixtures .channel_fixtures import FakeChannel
1113
1214
@@ -52,3 +54,41 @@ async def test_vacuum_commands(
5254 assert message .payload
5355 payload_data = json .loads (message .payload .decode ())
5456 assert payload_data == {"dps" : expected_payload }
57+
58+ def test_q10_api_has_status_trait (q10_api : Q10PropertiesApi ) -> None :
59+ """Test that Q10PropertiesApi exposes StatusTrait."""
60+ assert hasattr (q10_api , "status" )
61+ assert isinstance (q10_api .status , StatusTrait )
62+
63+
64+ def test_q10_api_has_vacuum_trait (q10_api : Q10PropertiesApi ) -> None :
65+ """Test that Q10PropertiesApi exposes VacuumTrait."""
66+ assert hasattr (q10_api , "vacuum" )
67+ assert isinstance (q10_api .vacuum , VacuumTrait )
68+
69+
70+ async def test_q10_api_status_refresh (q10_api : Q10PropertiesApi , fake_channel : FakeChannel ) -> None :
71+ """Test that status trait can be refreshed via Q10PropertiesApi."""
72+
73+ def build_q10_response (dps : dict [str , Any ]) -> RoborockMessage :
74+ """Build a Q10 MQTT response message."""
75+ payload = {"dps" : dps }
76+ return RoborockMessage (
77+ protocol = cast (RoborockMessageProtocol , 11 ),
78+ payload = json .dumps (payload ).encode (),
79+ seq = 0 ,
80+ version = b"B01" ,
81+ )
82+
83+ # Queue a response with status and battery
84+ fake_channel .response_queue .append (build_q10_response ({"121" : 5 , "122" : 100 }))
85+
86+ result = await q10_api .status .refresh ()
87+
88+ # Verify that refresh returned data
89+ assert result is not None
90+ assert len (result ) > 0
91+
92+ # Verify that properties are accessible
93+ assert q10_api .status .battery == 100
94+ assert q10_api .status .state is not None
0 commit comments