|
@@ -3,6 +3,7 @@ from bleak.backends.scanner import AdvertisementData
|
|
from bleak.backends.device import BLEDevice
|
|
from bleak.backends.device import BLEDevice
|
|
|
|
|
|
from switchbot.models import SwitchBotAdvertisement
|
|
from switchbot.models import SwitchBotAdvertisement
|
|
|
|
+from switchbot import SwitchbotModel
|
|
|
|
|
|
|
|
|
|
def test_parse_advertisement_data_curtain():
|
|
def test_parse_advertisement_data_curtain():
|
|
@@ -16,7 +17,6 @@ def test_parse_advertisement_data_curtain():
|
|
assert result == SwitchBotAdvertisement(
|
|
assert result == SwitchBotAdvertisement(
|
|
address="aa:bb:cc:dd:ee:ff",
|
|
address="aa:bb:cc:dd:ee:ff",
|
|
data={
|
|
data={
|
|
- "address": "aa:bb:cc:dd:ee:ff",
|
|
|
|
"rawAdvData": b"c\xc0X\x00\x11\x04",
|
|
"rawAdvData": b"c\xc0X\x00\x11\x04",
|
|
"data": {
|
|
"data": {
|
|
"calibration": True,
|
|
"calibration": True,
|
|
@@ -25,12 +25,11 @@ def test_parse_advertisement_data_curtain():
|
|
"position": 100,
|
|
"position": 100,
|
|
"lightLevel": 1,
|
|
"lightLevel": 1,
|
|
"deviceChain": 1,
|
|
"deviceChain": 1,
|
|
- "rssi": 0,
|
|
|
|
},
|
|
},
|
|
"isEncrypted": False,
|
|
"isEncrypted": False,
|
|
"model": "c",
|
|
"model": "c",
|
|
"modelFriendlyName": "Curtain",
|
|
"modelFriendlyName": "Curtain",
|
|
- "modelName": "WoCurtain",
|
|
+ "modelName": SwitchbotModel.CURTAIN,
|
|
},
|
|
},
|
|
device=ble_device,
|
|
device=ble_device,
|
|
)
|
|
)
|
|
@@ -44,4 +43,27 @@ def test_parse_advertisement_data_empty():
|
|
service_data={"0000fd3d-0000-1000-8000-00805f9b34fb": b""},
|
|
service_data={"0000fd3d-0000-1000-8000-00805f9b34fb": b""},
|
|
)
|
|
)
|
|
result = parse_advertisement_data(ble_device, adv_data)
|
|
result = parse_advertisement_data(ble_device, adv_data)
|
|
- assert result is None
|
|
+ assert result is None
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def test_new_bot_firmware():
|
|
|
|
+ """Test parsing adv data from new bot firmware."""
|
|
|
|
+ ble_device = BLEDevice("aa:bb:cc:dd:ee:ff", "any")
|
|
|
|
+ adv_data = AdvertisementData(
|
|
|
|
+ manufacturer_data={89: b"\xd8.\xad\xcd\r\x85"},
|
|
|
|
+ service_data={"00000d00-0000-1000-8000-00805f9b34fb": b"H\x10\xe1"},
|
|
|
|
+ service_uuids=["CBA20D00-224D-11E6-9FB8-0002A5D5C51B"],
|
|
|
|
+ )
|
|
|
|
+ result = parse_advertisement_data(ble_device, adv_data)
|
|
|
|
+ assert result == SwitchBotAdvertisement(
|
|
|
|
+ address="aa:bb:cc:dd:ee:ff",
|
|
|
|
+ data={
|
|
|
|
+ "rawAdvData": b"H\x10\xe1",
|
|
|
|
+ "data": {"switchMode": False, "isOn": False, "battery": 97},
|
|
|
|
+ "model": "H",
|
|
|
|
+ "isEncrypted": False,
|
|
|
|
+ "modelFriendlyName": "Bot",
|
|
|
|
+ "modelName": SwitchbotModel.BOT,
|
|
|
|
+ },
|
|
|
|
+ device=ble_device,
|
|
|
|
+ )
|