Browse Source

Add K11+ for switchbot (#399)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Retha Runolfsson 1 month ago
parent
commit
e3943c0785
4 changed files with 52 additions and 1 deletions
  1. 6 0
      switchbot/adv_parser.py
  2. 1 0
      switchbot/const/__init__.py
  3. 38 0
      tests/test_adv_parser.py
  4. 7 1
      tests/test_vacuum.py

+ 6 - 0
switchbot/adv_parser.py

@@ -364,6 +364,12 @@ SUPPORTED_TYPES: dict[str | bytes, SwitchbotSupportedType] = {
         "func": process_rgbic_light,
         "manufacturer_id": 2409,
     },
+    b"\x00\x10\xfb\xa8": {
+        "modelName": SwitchbotModel.K11_VACUUM,
+        "modelFriendlyName": "K11+ Vacuum",
+        "func": process_vacuum,
+        "manufacturer_id": 2409,
+    },
 }
 
 _SWITCHBOT_MODEL_TO_CHAR = {

+ 1 - 0
switchbot/const/__init__.py

@@ -96,6 +96,7 @@ class SwitchbotModel(StrEnum):
     PLUG_MINI_EU = "Plug Mini (EU)"
     RGBICWW_STRIP_LIGHT = "RGBICWW Strip Light"
     RGBICWW_FLOOR_LAMP = "RGBICWW Floor Lamp"
+    K11_VACUUM = "K11+ Vacuum"
 
 
 __all__ = [

+ 38 - 0
tests/test_adv_parser.py

@@ -3415,6 +3415,21 @@ def test_humidifer_with_empty_data() -> None:
             "RGBICWW Strip Light",
             SwitchbotModel.RGBICWW_STRIP_LIGHT,
         ),
+        AdvTestCase(
+            b"\xb0\xe9\xfe\xe4\xbf\xd8\x0b\x01\x11f\x00\x16M\x15",
+            b"\x00\x00M\x00\x10\xfb\xa8",
+            {
+                "battery": 77,
+                "mqtt_connected": True,
+                "sequence_number": 11,
+                "soc_version": "1.1.102",
+                "step": 6,
+                "work_status": 21,
+            },
+            b"\x00\x10\xfb\xa8",
+            "K11+ Vacuum",
+            SwitchbotModel.K11_VACUUM,
+        ),
     ],
 )
 def test_adv_active(test_case: AdvTestCase) -> None:
@@ -3614,6 +3629,21 @@ def test_adv_active(test_case: AdvTestCase) -> None:
             "RGBICWW Strip Light",
             SwitchbotModel.RGBICWW_STRIP_LIGHT,
         ),
+        AdvTestCase(
+            b"\xb0\xe9\xfe\xe4\xbf\xd8\x0b\x01\x11f\x00\x16M\x15",
+            None,
+            {
+                "battery": 77,
+                "mqtt_connected": True,
+                "sequence_number": 11,
+                "soc_version": "1.1.102",
+                "step": 6,
+                "work_status": 21,
+            },
+            b"\x00\x10\xfb\xa8",
+            "K11+ Vacuum",
+            SwitchbotModel.K11_VACUUM,
+        ),
     ],
 )
 def test_adv_passive(test_case: AdvTestCase) -> None:
@@ -3771,6 +3801,14 @@ def test_adv_passive(test_case: AdvTestCase) -> None:
             "RGBICWW Strip Light",
             SwitchbotModel.RGBICWW_STRIP_LIGHT,
         ),
+        AdvTestCase(
+            None,
+            b"\x00\x00M\x00\x10\xfb\xa8",
+            {},
+            b"\x00\x10\xfb\xa8",
+            "K11+ Vacuum",
+            SwitchbotModel.K11_VACUUM,
+        ),
     ],
 )
 def test_adv_with_empty_data(test_case: AdvTestCase) -> None:

+ 7 - 1
tests/test_vacuum.py

@@ -15,6 +15,7 @@ common_params = [
     (b"3\x00\x00", ".", 2),
     (b"(\x00", "(", 1),
     (b"}\x00", "(", 1),
+    (b"\x00\x00M\x00\x10\xfb\xa8", b"\x00\x10\xfb\xa8", 2),
 ]
 
 
@@ -82,7 +83,12 @@ def make_advertisement_data(
 @pytest.mark.asyncio
 @pytest.mark.parametrize(
     ("rawAdvData", "model"),
-    [(b".\x00d", "."), (b"z\x00\x00", "z"), (b"3\x00\x00", "3")],
+    [
+        (b".\x00d", "."),
+        (b"z\x00\x00", "z"),
+        (b"3\x00\x00", "3"),
+        (b"\x00\x00M\x00\x10\xfb\xa8", b"\x00\x10\xfb\xa8"),
+    ],
 )
 async def test_status_from_proceess_adv(rawAdvData: bytes, model: str) -> None:
     protocol_version = 2