File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change 44
55def process_wocontact (data : bytes , mfr_data : bytes | None ) -> dict [str , bool | int ]:
66 """Process woContact Sensor services data."""
7- contact_timeout = data [3 ] & 0b00000110 == 0b00000110
7+ contact_timeout = data [3 ] & 0b00000100 == 0b00000100
88 contact_open = data [3 ] & 0b00000010 == 0b00000010
99 return {
1010 "tested" : bool (data [1 ] & 0b10000000 ),
Original file line number Diff line number Diff line change @@ -56,6 +56,38 @@ def test_parse_advertisement_data_curtain():
5656 )
5757
5858
59+ def test_parse_advertisement_data_contact ():
60+ """Test parse_advertisement_data for the contact sensor."""
61+ ble_device = BLEDevice ("aa:bb:cc:dd:ee:ff" , "any" )
62+ adv_data = generate_advertisement_data (
63+ manufacturer_data = {2409 : b"\xe7 \xab F\xac \x8f \x92 |\x0f \x00 \x11 \x04 " },
64+ service_data = {"0000fd3d-0000-1000-8000-00805f9b34fb" : b'd@d\x05 \x00 u\x00 \xf8 \x12 ' },
65+ rssi = - 80 ,
66+ )
67+ result = parse_advertisement_data (ble_device , adv_data )
68+ assert result == SwitchBotAdvertisement (
69+ address = "aa:bb:cc:dd:ee:ff" ,
70+ data = {
71+ "rawAdvData" : b'd@d\x05 \x00 u\x00 \xf8 \x12 ' ,
72+ "data" : {
73+ "button_count" : 2 ,
74+ 'contact_open' : True ,
75+ 'contact_timeout' : True ,
76+ "is_light" : True ,
77+ "battery" : 100 ,
78+ 'motion_detected' : True ,
79+ "tested" : False
80+ },
81+ "isEncrypted" : False ,
82+ "model" : "d" ,
83+ "modelFriendlyName" : 'Contact Sensor' ,
84+ "modelName" : SwitchbotModel .CONTACT_SENSOR ,
85+ },
86+ device = ble_device ,
87+ rssi = - 80 ,
88+ )
89+
90+
5991def test_parse_advertisement_data_empty ():
6092 """Test parse_advertisement_data with empty data does not blow up."""
6193 ble_device = BLEDevice ("aa:bb:cc:dd:ee:ff" , "any" )
You can’t perform that action at this time.
0 commit comments