diff --git a/.changeset/sour-mirrors-know.md b/.changeset/sour-mirrors-know.md new file mode 100644 index 00000000..4e8ac920 --- /dev/null +++ b/.changeset/sour-mirrors-know.md @@ -0,0 +1,6 @@ +--- +'homebridge-ring': patch +'ring-client-api': patch +--- + +Better handling of general push notifications. This avoids extraneous logs for events we don't know about or don't care about. diff --git a/packages/ring-client-api/api.ts b/packages/ring-client-api/api.ts index d57f196d..88a4ceb6 100644 --- a/packages/ring-client-api/api.ts +++ b/packages/ring-client-api/api.ts @@ -16,7 +16,6 @@ import { ProfileResponse, PushNotification, PushNotificationAction, - PushNotificationDingV2, RingDeviceType, ThirdPartyGarageDoorOpener, UnknownDevice, @@ -31,7 +30,7 @@ import { switchMap, throttleTime, } from 'rxjs/operators' -import { clearTimeouts, enableDebug, logError, logInfo } from './util' +import { clearTimeouts, enableDebug, logDebug, logError, logInfo } from './util' import { setFfmpegPath } from './ffmpeg' import { Subscribed } from './subscribed' import PushReceiver from '@eneris/push-receiver' @@ -246,7 +245,7 @@ export class RingApi extends Subscribed { debug: false, }), devicesById: { [id: number]: RingCamera | RingIntercom | undefined } = {}, - sendToDevice = (id: number, notification: PushNotificationDingV2) => { + sendToDevice = (id: number, notification: PushNotification) => { devicesById[id]?.processPushNotification(notification) }, onPushNotificationToken = new Subject() @@ -328,31 +327,41 @@ export class RingApi extends Subscribed { const notification = messageData as PushNotification - if (!('android_config' in notification)) { - // This is not a v2 ding style notification, so we can't process it - logInfo('Received push notification in unknown format') - logInfo(JSON.stringify(message)) - return - } - - const deviceId = notification.data?.device?.id + if ('android_config' in notification) { + const deviceId = notification.data?.device?.id - if (deviceId) { - sendToDevice(deviceId, notification) - } + if (deviceId) { + sendToDevice(deviceId, notification) + } - const eventCategory = notification.android_config.category + const eventCategory = notification.android_config.category - if ( - eventCategory !== PushNotificationAction.Ding && - eventCategory !== PushNotificationAction.Motion && - eventCategory !== PushNotificationAction.IntercomDing + if ( + eventCategory !== PushNotificationAction.Ding && + eventCategory !== PushNotificationAction.Motion && + eventCategory !== PushNotificationAction.IntercomDing + ) { + logDebug( + 'Received v2 push notification with unknown category: ' + + eventCategory, + ) + logDebug(JSON.stringify(message)) + } + } else if ( + 'data' in notification && + 'gcmData' in notification.data && + 'alarm_meta' in notification.data.gcmData ) { - logInfo( - 'Received push notification with unknown category: ' + - eventCategory, - ) - logInfo(JSON.stringify(message)) + const deviceId = notification.data.gcmData.alarm_meta.device_zid + + if (deviceId) { + sendToDevice(deviceId, notification) + } + } else { + // This is not a v1 or v2 style notification, so we can't process it + logDebug('Received push notification in unknown format') + logDebug(JSON.stringify(message)) + return } } catch (e) { logError(e) diff --git a/packages/ring-client-api/ring-camera.ts b/packages/ring-client-api/ring-camera.ts index eda9d070..6a9d4c6d 100644 --- a/packages/ring-client-api/ring-camera.ts +++ b/packages/ring-client-api/ring-camera.ts @@ -14,6 +14,7 @@ import { VideoSearchResponse, OnvifCameraData, RingCameraKind, + PushNotification, } from './ring-types' import { appApi, clientApi, deviceApi, RingRestClient } from './rest-client' import { BehaviorSubject, firstValueFrom, ReplaySubject, Subject } from 'rxjs' @@ -422,8 +423,12 @@ export class RingCamera extends Subscribed { this.onActiveNotifications.next(otherDings) } - processPushNotification(notification: PushNotificationDingV2) { - if (!('ding' in notification.data?.event)) { + processPushNotification(notification: PushNotification) { + if ( + !('android_config' in notification) || + !('event' in notification.data) || + !('ding' in notification.data?.event) + ) { // only process ding/motion notifications return } diff --git a/packages/ring-client-api/ring-intercom.ts b/packages/ring-client-api/ring-intercom.ts index 173f27cc..bfa64458 100644 --- a/packages/ring-client-api/ring-intercom.ts +++ b/packages/ring-client-api/ring-intercom.ts @@ -1,8 +1,7 @@ import { IntercomHandsetAudioData, + PushNotification, PushNotificationAction, - PushNotificationDingV2, - PushNotificationIntercomUnlockV2, } from './ring-types' import { clientApi, commandsApi, RingRestClient } from './rest-client' import { BehaviorSubject, Subject } from 'rxjs' @@ -104,9 +103,7 @@ export class RingIntercom { }) } - processPushNotification( - notification: PushNotificationDingV2 | PushNotificationIntercomUnlockV2, - ) { + processPushNotification(notification: PushNotification) { if ( 'android_config' in notification && notification.android_config.category ===