dkilgore90 / google-sdm-api

Apache License 2.0
69 stars 22 forks source link

Handle linked event threads for different event types #85

Closed dkilgore90 closed 1 year ago

dkilgore90 commented 2 years ago

Reported from Hubitat forum

The presence/person event state never cleared, because the ENDED event from Google only referenced motion.

2022-07-06 00:22:29 Mud Room    { "eventId": "f60beea0-adb4-4c23-8d01-8a81d48c1d0d", "timestamp": "2022-07-06T04:22:06.872Z", "resourceUpdate": { "name": "enterprises/9883dbf4-bc06-451a-ba28-874afe641383/devices/AVPHwEs227k4g-UQCUgIEbxaHnT0tdDYEJEC3T-ms6qsLLU65bkfBz_yjw7OVQW7dZMs_aktxnJzBaHDSZ_9WCp89p078A", "events": { "sdm.devices.events.CameraMotion.Motion": { "eventSessionId": "1638056321", "eventId": "401079826", "zones": [""] } } }, "userId": "AVPHwEukOR65xe1nGj1X2_J96lpb_qu2gH1vHEP4ictp", "eventThreadId": "dc54477c-cfda-4760-9ce6-606c43f62a9d", "resourceGroup": ["enterprises/9883dbf4-bc06-451a-ba28-874afe641383/devices/AVPHwEs227k4g-UQCUgIEbxaHnT0tdDYEJEC3T-ms6qsLLU65bkfBz_yjw7OVQW7dZMs_aktxnJzBaHDSZ_9WCp89p078A"], "eventThreadState": "ENDED"}
2022-07-06 00:22:09 Mud Room    { "eventId": "f60beea0-adb4-4c23-8d01-8a81d48c1d0d", "timestamp": "2022-07-06T04:22:06.872Z", "resourceUpdate": { "name": "enterprises/9883dbf4-bc06-451a-ba28-874afe641383/devices/AVPHwEs227k4g-UQCUgIEbxaHnT0tdDYEJEC3T-ms6qsLLU65bkfBz_yjw7OVQW7dZMs_aktxnJzBaHDSZ_9WCp89p078A", "events": { "sdm.devices.events.CameraMotion.Motion": { "eventSessionId": "1638056321", "eventId": "401079826", "zones": [""] } } }, "userId": "AVPHwEukOR65xe1nGj1X2_J96lpb_qu2gH1vHEP4ictp", "eventThreadId": "dc54477c-cfda-4760-9ce6-606c43f62a9d", "resourceGroup": ["enterprises/9883dbf4-bc06-451a-ba28-874afe641383/devices/AVPHwEs227k4g-UQCUgIEbxaHnT0tdDYEJEC3T-ms6qsLLU65bkfBz_yjw7OVQW7dZMs_aktxnJzBaHDSZ_9WCp89p078A"], "eventThreadState": "STARTED"}
2022-07-06 00:22:08 Mud Room    { "eventId": "3a38fed2-0a85-49b5-99f1-179151c9b6fb", "timestamp": "2022-07-06T04:22:06.872Z", "resourceUpdate": { "name": "enterprises/9883dbf4-bc06-451a-ba28-874afe641383/devices/AVPHwEs227k4g-UQCUgIEbxaHnT0tdDYEJEC3T-ms6qsLLU65bkfBz_yjw7OVQW7dZMs_aktxnJzBaHDSZ_9WCp89p078A", "events": { "sdm.devices.events.CameraPerson.Person": { "eventSessionId": "1638056321", "eventId": "991316265", "zones": [""] } } }, "userId": "AVPHwEukOR65xe1nGj1X2_J96lpb_qu2gH1vHEP4ictp", "eventThreadId": "dc54477c-cfda-4760-9ce6-606c43f62a9d", "resourceGroup": ["enterprises/9883dbf4-bc06-451a-ba28-874afe641383/devices/AVPHwEs227k4g-UQCUgIEbxaHnT0tdDYEJEC3T-ms6qsLLU65bkfBz_yjw7OVQW7dZMs_aktxnJzBaHDSZ_9WCp89p078A"], "eventThreadState": "UPDATED"}

Must correlate by eventThreadId in order to guarantee that the state is properly cleared.