@@ -104,6 +104,19 @@ def _process_wosensorth(data: bytes) -> dict[str, object]:
104104 return _wosensorth_data
105105
106106
107+ def _process_wocontact (data : bytes ) -> dict [str , bool | int ]:
108+ """Process woContact Sensor services data."""
109+ return {
110+ "tested" : bool (data [1 ] & 0b10000000 ),
111+ "motion_detected" : bool (data [1 ] & 0b01000000 ),
112+ "battery" : data [2 ] & 0b01111111 ,
113+ "contact_open" : data [3 ] & 0b00000010 == 0b00000010 ,
114+ "contact_timeout" : data [3 ] & 0b00000110 == 0b00000110 ,
115+ "is_light" : bool (data [3 ] & 0b00000001 ),
116+ "button_count" : (data [7 ] & 0b11110000 ) >> 4 ,
117+ }
118+
119+
107120@dataclass
108121class SwitchBotAdvertisement :
109122 """Switchbot advertisement."""
@@ -124,9 +137,11 @@ def parse_advertisement_data(
124137 _model = chr (_service_data [0 ] & 0b01111111 )
125138
126139 supported_types : dict [str , dict [str , Any ]] = {
140+ "d" : {"modelName" : "WoContact" , "func" : _process_wocontact },
127141 "H" : {"modelName" : "WoHand" , "func" : _process_wohand },
128142 "c" : {"modelName" : "WoCurtain" , "func" : _process_wocurtain },
129143 "T" : {"modelName" : "WoSensorTH" , "func" : _process_wosensorth },
144+ "i" : {"modelName" : "WoSensorTH" , "func" : _process_wosensorth },
130145 }
131146
132147 data = {
@@ -228,7 +243,13 @@ async def get_bots(self) -> dict[str, SwitchBotAdvertisement]:
228243
229244 async def get_tempsensors (self ) -> dict [str , SwitchBotAdvertisement ]:
230245 """Return all WoSensorTH/Temp sensor devices with services data."""
231- return await self ._get_devices_by_model ("T" )
246+ base_meters = await self ._get_devices_by_model ("T" )
247+ plus_meters = await self ._get_devices_by_model ("i" )
248+ return {** base_meters , ** plus_meters }
249+
250+ async def get_contactsensors (self ) -> dict [str , SwitchBotAdvertisement ]:
251+ """Return all WoContact/Contact sensor devices with services data."""
252+ return await self ._get_devices_by_model ("d" )
232253
233254 async def get_device_data (
234255 self , address : str
0 commit comments