2 Commits a6cbf556be ... e7ad3c8740

Author SHA1 Message Date
  J. Nick Koston e7ad3c8740 Bump version to 0.49.0 (#255) 1 day ago
  J. Nick Koston f9c57b8848 Add basic support for the Meter Pro (#254) 1 day ago
4 changed files with 67 additions and 1 deletions
  1. 1 1
      setup.py
  2. 6 0
      switchbot/adv_parser.py
  3. 1 0
      switchbot/const.py
  4. 59 0
      tests/test_adv_parser.py

+ 1 - 1
setup.py

@@ -10,7 +10,7 @@ setup(
         "cryptography>=39.0.0",
         "pyOpenSSL>=23.0.0",
     ],
-    version="0.48.2",
+    version="0.49.0",
     description="A library to communicate with Switchbot",
     author="Daniel Hjelseth Hoyer",
     url="https://github.com/Danielhiversen/pySwitchbot/",

+ 6 - 0
switchbot/adv_parser.py

@@ -101,6 +101,12 @@ SUPPORTED_TYPES: dict[str, SwitchbotSupportedType] = {
         "func": process_wosensorth,
         "manufacturer_id": 2409,
     },
+    "4": {
+        "modelName": SwitchbotModel.METER_PRO,
+        "modelFriendlyName": "Meter",
+        "func": process_wosensorth,
+        "manufacturer_id": 2409,
+    },
     "v": {
         "modelName": SwitchbotModel.HUB2,
         "modelFriendlyName": "Hub 2",

+ 1 - 0
switchbot/const.py

@@ -42,6 +42,7 @@ class SwitchbotModel(StrEnum):
     CONTACT_SENSOR = "WoContact"
     LIGHT_STRIP = "WoStrip"
     METER = "WoSensorTH"
+    METER_PRO = "WoSensorTHP"
     IO_METER = "WoIOSensorTH"
     MOTION_SENSOR = "WoPresence"
     COLOR_BULB = "WoBulb"

+ 59 - 0
tests/test_adv_parser.py

@@ -1560,3 +1560,62 @@ def test_parsing_lock_passive_old_firmware():
         rssi=-67,
         active=False,
     )
+
+
+def test_meter_pro_active() -> None:
+    ble_device = generate_ble_device("aa:bb:cc:dd:ee:ff", "any")
+    adv_data = generate_advertisement_data(
+        manufacturer_data={2409: b"\xb0\xe9\xfeR\xdd\x84\x06d\x08\x97,\x00\x05"},
+        service_data={"0000fd3d-0000-1000-8000-00805f9b34fb": b"4\x00d"},
+        rssi=-67,
+    )
+    result = parse_advertisement_data(ble_device, adv_data)
+    assert result == SwitchBotAdvertisement(
+        address="aa:bb:cc:dd:ee:ff",
+        data={
+            "data": {
+                "battery": 100,
+                "fahrenheit": False,
+                "humidity": 44,
+                "temp": {"c": 23.8, "f": 74.84},
+                "temperature": 23.8,
+            },
+            "isEncrypted": False,
+            "model": "4",
+            "modelFriendlyName": "Meter",
+            "modelName": SwitchbotModel.METER_PRO,
+            "rawAdvData": b"4\x00d",
+        },
+        device=ble_device,
+        rssi=-67,
+        active=True,
+    )
+
+
+def test_meter_pro_passive() -> None:
+    ble_device = generate_ble_device("aa:bb:cc:dd:ee:ff", "any")
+    adv_data = generate_advertisement_data(
+        manufacturer_data={2409: b"\xb0\xe9\xfeR\xdd\x84\x06d\x08\x97,\x00\x05"},
+        rssi=-67,
+    )
+    result = parse_advertisement_data(ble_device, adv_data, SwitchbotModel.METER_PRO)
+    assert result == SwitchBotAdvertisement(
+        address="aa:bb:cc:dd:ee:ff",
+        data={
+            "data": {
+                "battery": None,
+                "fahrenheit": False,
+                "humidity": 44,
+                "temp": {"c": 23.8, "f": 74.84},
+                "temperature": 23.8,
+            },
+            "isEncrypted": False,
+            "model": "4",
+            "modelFriendlyName": "Meter",
+            "modelName": SwitchbotModel.METER_PRO,
+            "rawAdvData": None,
+        },
+        device=ble_device,
+        rssi=-67,
+        active=False,
+    )