From 3be14521b4605da3389f5c04792f07e494a0ed5c Mon Sep 17 00:00:00 2001 From: dgreif Date: Sat, 22 Jun 2024 13:02:49 -0400 Subject: [PATCH] Handle some alarm push notifications --- packages/ring-client-api/api.ts | 15 ++++++++++++--- packages/ring-client-api/ring-camera.ts | 3 +-- packages/ring-client-api/ring-intercom.ts | 4 ++-- packages/ring-client-api/ring-types.ts | 12 +++++++++++- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/packages/ring-client-api/api.ts b/packages/ring-client-api/api.ts index 1e0c7fe2..dc02827d 100644 --- a/packages/ring-client-api/api.ts +++ b/packages/ring-client-api/api.ts @@ -16,6 +16,7 @@ import { ProfileResponse, PushNotification, PushNotificationAction, + PushNotificationDingV2, RingDeviceType, ThirdPartyGarageDoorOpener, UnknownDevice, @@ -244,7 +245,7 @@ export class RingApi extends Subscribed { debug: false, }), devicesById: { [id: number]: RingCamera | RingIntercom | undefined } = {}, - sendToDevice = (id: number, notification: PushNotification) => { + sendToDevice = (id: number, notification: PushNotificationDingV2) => { devicesById[id]?.processPushNotification(notification) }, onPushNotificationToken = new Subject() @@ -324,8 +325,16 @@ export class RingApi extends Subscribed { } } - const notification = messageData as PushNotification, - deviceId = notification.data?.device?.id + 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 (deviceId) { sendToDevice(deviceId, notification) diff --git a/packages/ring-client-api/ring-camera.ts b/packages/ring-client-api/ring-camera.ts index 8ce3f05a..0fda8768 100644 --- a/packages/ring-client-api/ring-camera.ts +++ b/packages/ring-client-api/ring-camera.ts @@ -9,7 +9,6 @@ import { SocketTicketResponse, PeriodicFootageResponse, PushNotificationAction, - PushNotification, PushNotificationDingV2, RingCameraModel, VideoSearchResponse, @@ -419,7 +418,7 @@ export class RingCamera extends Subscribed { this.onActiveNotifications.next(otherDings) } - processPushNotification(notification: PushNotification) { + processPushNotification(notification: PushNotificationDingV2) { if (!('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 299e774f..fb76ef0b 100644 --- a/packages/ring-client-api/ring-intercom.ts +++ b/packages/ring-client-api/ring-intercom.ts @@ -1,7 +1,7 @@ import { IntercomHandsetAudioData, - PushNotification, PushNotificationAction, + PushNotificationDingV2, } from './ring-types' import { clientApi, commandsApi, RingRestClient } from './rest-client' import { BehaviorSubject, Subject } from 'rxjs' @@ -103,7 +103,7 @@ export class RingIntercom { }) } - processPushNotification(notification: PushNotification) { + processPushNotification(notification: PushNotificationDingV2) { if (notification.android_config.category === PushNotificationAction.Ding) { this.onDing.next() } else if ( diff --git a/packages/ring-client-api/ring-types.ts b/packages/ring-client-api/ring-types.ts index 39e08526..532bf496 100644 --- a/packages/ring-client-api/ring-types.ts +++ b/packages/ring-client-api/ring-types.ts @@ -1010,6 +1010,10 @@ export enum PushNotificationAction { Ding = 'com.ring.pn.live-event.ding', Motion = 'com.ring.pn.live-event.motion', IntercomUnlock = 'com.ring.pn.intercom.virtual.unlock', + AlarmModeNone = 'com.ring.push.HANDLE_NEW_SECURITY_PANEL_MODE_NONE_NOTICE', + AlarmModeSome = 'com.ring.push.HANDLE_NEW_SECURITY_PANEL_MODE_SOME_NOTICE', + AlarmSoundSiren = 'com.ring.push.HANDLE_NEW_USER_SOUND_SIREN', + AlarmSilenceSiren = 'com.ring.push.HANDLE_NEW_NON_ALARM_SIREN_SILENCED', } export interface PushNotificationDingV2 { @@ -1074,7 +1078,13 @@ export interface PushNotificationAlarm { } } -export type PushNotification = PushNotificationDingV2 +export interface PushNotificationAlarmV2 { + data: { + gcmData: PushNotificationAlarm + } +} + +export type PushNotification = PushNotificationDingV2 | PushNotificationAlarmV2 export interface SocketTicketResponse { ticket: string