|
1 | 1 | from typing import Any |
2 | | -from switchbot.adv_parser import parse_advertisement_data |
3 | | -from bleak.backends.scanner import AdvertisementData |
| 2 | + |
4 | 3 | from bleak.backends.device import BLEDevice |
| 4 | +from bleak.backends.scanner import AdvertisementData |
5 | 5 |
|
6 | | -from switchbot.models import SwitchBotAdvertisement |
7 | 6 | from switchbot import SwitchbotModel |
| 7 | +from switchbot.adv_parser import parse_advertisement_data |
| 8 | +from switchbot.models import SwitchBotAdvertisement |
8 | 9 |
|
9 | 10 | ADVERTISEMENT_DATA_DEFAULTS = { |
10 | 11 | "local_name": "", |
@@ -93,6 +94,92 @@ def test_parse_advertisement_data_curtain_position_zero(): |
93 | 94 | ) |
94 | 95 |
|
95 | 96 |
|
| 97 | +def test_parse_advertisement_data_curtain_firmware_six_position_100(): |
| 98 | + """Test parse_advertisement_data with firmware six for curtain position 100.""" |
| 99 | + ble_device = BLEDevice("aa:bb:cc:dd:ee:ff", "any") |
| 100 | + adv_data = generate_advertisement_data( |
| 101 | + local_name="WoCurtain", |
| 102 | + manufacturer_data={ |
| 103 | + 89: b"\xf5\x98\x94\x08\xa0\xe7", |
| 104 | + 2409: b'\xf5\x98\x94\x08\xa0\xe7\x9b\x0f\x00"\x04', |
| 105 | + }, |
| 106 | + service_data={ |
| 107 | + "00000d00-0000-1000-8000-00805f9b34fb": b"c\xd0H\x00\x12\x04", |
| 108 | + "0000fd3d-0000-1000-8000-00805f9b34fb": b'c\xc0G\x00"\x04', |
| 109 | + }, |
| 110 | + service_uuids=[ |
| 111 | + "00001800-0000-1000-8000-00805f9b34fb", |
| 112 | + "00001801-0000-1000-8000-00805f9b34fb", |
| 113 | + "cba20d00-224d-11e6-9fb8-0002a5d5c51b", |
| 114 | + ], |
| 115 | + rssi=-62, |
| 116 | + ) |
| 117 | + result = parse_advertisement_data(ble_device, adv_data) |
| 118 | + assert result == SwitchBotAdvertisement( |
| 119 | + address="aa:bb:cc:dd:ee:ff", |
| 120 | + data={ |
| 121 | + "rawAdvData": b"c\xd0H\x00\x12\x04", |
| 122 | + "data": { |
| 123 | + "calibration": True, |
| 124 | + "battery": 72, |
| 125 | + "inMotion": False, |
| 126 | + "position": 100, |
| 127 | + "lightLevel": 1, |
| 128 | + "deviceChain": 2, |
| 129 | + }, |
| 130 | + "isEncrypted": False, |
| 131 | + "model": "c", |
| 132 | + "modelFriendlyName": "Curtain", |
| 133 | + "modelName": SwitchbotModel.CURTAIN, |
| 134 | + }, |
| 135 | + device=ble_device, |
| 136 | + rssi=-62, |
| 137 | + ) |
| 138 | + |
| 139 | + |
| 140 | +def test_parse_advertisement_data_curtain_firmware_six_position_100_other_rssi(): |
| 141 | + """Test parse_advertisement_data with firmware six for curtain position 100 other rssi.""" |
| 142 | + ble_device = BLEDevice("aa:bb:cc:dd:ee:ff", "any") |
| 143 | + adv_data = generate_advertisement_data( |
| 144 | + local_name="WoCurtain", |
| 145 | + manufacturer_data={ |
| 146 | + 89: b"\xf5\x98\x94\x08\xa0\xe7", |
| 147 | + 2409: b'\xf5\x98\x94\x08\xa0\xe7\xa5\x0fc"\x04', |
| 148 | + }, |
| 149 | + service_data={ |
| 150 | + "00000d00-0000-1000-8000-00805f9b34fb": b"c\xd0H\x00\x12\x04", |
| 151 | + "0000fd3d-0000-1000-8000-00805f9b34fb": b'c\xc0Gc"\x04', |
| 152 | + }, |
| 153 | + service_uuids=[ |
| 154 | + "00001800-0000-1000-8000-00805f9b34fb", |
| 155 | + "00001801-0000-1000-8000-00805f9b34fb", |
| 156 | + "cba20d00-224d-11e6-9fb8-0002a5d5c51b", |
| 157 | + ], |
| 158 | + rssi=-67, |
| 159 | + ) |
| 160 | + result = parse_advertisement_data(ble_device, adv_data) |
| 161 | + assert result == SwitchBotAdvertisement( |
| 162 | + address="aa:bb:cc:dd:ee:ff", |
| 163 | + data={ |
| 164 | + "rawAdvData": b"c\xd0H\x00\x12\x04", |
| 165 | + "data": { |
| 166 | + "calibration": True, |
| 167 | + "battery": 72, |
| 168 | + "inMotion": False, |
| 169 | + "position": 100, |
| 170 | + "lightLevel": 1, |
| 171 | + "deviceChain": 2, |
| 172 | + }, |
| 173 | + "isEncrypted": False, |
| 174 | + "model": "c", |
| 175 | + "modelFriendlyName": "Curtain", |
| 176 | + "modelName": SwitchbotModel.CURTAIN, |
| 177 | + }, |
| 178 | + device=ble_device, |
| 179 | + rssi=-67, |
| 180 | + ) |
| 181 | + |
| 182 | + |
96 | 183 | def test_parse_advertisement_data_contact(): |
97 | 184 | """Test parse_advertisement_data for the contact sensor.""" |
98 | 185 | ble_device = BLEDevice("aa:bb:cc:dd:ee:ff", "any") |
|
0 commit comments