@@ -149,3 +149,50 @@ def _save_event(hap_event):
149
149
b"EVENT/1.0 200 OK\r \n Content-Type: application/hap+json\r \n Content-Length: 87\r \n \r \n "
150
150
b'{"characteristics":[{"aid":2,"iid":33,"value":false},{"aid":3,"iid":33,"value":false}]}'
151
151
]
152
+
153
+
154
+ @pytest .mark .asyncio
155
+ async def test_push_event_overwrites_old_pending_events (driver ):
156
+ """Test push event overwrites old events in the event queue.
157
+
158
+ iOS 15 had a breaking change where events are no longer processed
159
+ in order. We want to make sure when we send an event message we
160
+ only send the latest state and overwrite all the previous states
161
+ for the same AID/IID that are in the queue when the state changes
162
+ before the event is sent.
163
+ """
164
+ addr_info = ("1.2.3.4" , 1234 )
165
+ server = hap_server .HAPServer (("127.0.01" , 5555 ), driver )
166
+ server .loop = asyncio .get_event_loop ()
167
+ hap_events = []
168
+
169
+ def _save_event (hap_event ):
170
+ hap_events .append (hap_event )
171
+
172
+ hap_server_protocol = HAPServerProtocol (
173
+ server .loop , server .connections , server .accessory_handler
174
+ )
175
+ hap_server_protocol .write = _save_event
176
+ hap_server_protocol .peername = addr_info
177
+ server .accessory_handler .topics ["1.33" ] = {addr_info }
178
+ server .accessory_handler .topics ["2.33" ] = {addr_info }
179
+ server .connections [addr_info ] = hap_server_protocol
180
+
181
+ assert (
182
+ server .push_event ({"aid" : 1 , "iid" : 33 , "value" : False }, addr_info , True )
183
+ is True
184
+ )
185
+ assert (
186
+ server .push_event ({"aid" : 1 , "iid" : 33 , "value" : True }, addr_info , True ) is True
187
+ )
188
+ assert (
189
+ server .push_event ({"aid" : 2 , "iid" : 33 , "value" : False }, addr_info , True )
190
+ is True
191
+ )
192
+
193
+ await asyncio .sleep (0 )
194
+ assert hap_events == [
195
+ b"EVENT/1.0 200 OK\r \n Content-Type: application/hap+json\r \n Content-Length: 86\r \n \r \n "
196
+ b'{"characteristics":[{"aid":1,"iid":33,"value":true},'
197
+ b'{"aid":2,"iid":33,"value":false}]}'
198
+ ]
0 commit comments