Skip to content

Commit

Permalink
Avoid snapshot while recording on doorbell_graham_cracker
Browse files Browse the repository at this point in the history
Closes #1280
Closes #1556
  • Loading branch information
dgreif committed Jan 12, 2025
1 parent 9a9cbeb commit c4daf65
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
6 changes: 6 additions & 0 deletions .changeset/blue-months-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'homebridge-ring': minor
'ring-client-api': minor
---

Avoid snapshots while recording for doorbell_graham_cracker. This should allow notifications to work on these devices in homebridge.
12 changes: 6 additions & 6 deletions packages/homebridge-ring/camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export class Camera extends BaseDataAccessory<RingCamera> {
* followed shortly by a second notification with the image uuid. We need to
* wait for the second notification before we can load the snapshot.
*/
if (this.device.operatingOnBattery && !imageUuid) {
if (!this.cameraSource.canTakeSnapshotWhileRecording && !imageUuid) {
await Promise.race([
firstValueFrom(
this.device.onNewNotification.pipe(
Expand All @@ -233,12 +233,12 @@ export class Camera extends BaseDataAccessory<RingCamera> {
delay(2000),
])
imageUuid = this.device.latestNotificationSnapshotUuid
}

if (this.device.operatingOnBattery && !imageUuid) {
// battery cameras cannot fetch a new snapshot while recording is in progress
logInfo(this.device.name + ' ' + eventDescription)
return characteristicValue
if (!imageUuid) {
// did not receive an image uuid and one can't be taken while recording. Proceed without a snapshot
logInfo(this.device.name + ' ' + eventDescription)
return characteristicValue
}
}

logInfo(
Expand Down
17 changes: 15 additions & 2 deletions packages/ring-client-api/ring-camera.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { SocketTicketResponse, RingCameraKind } from './ring-types.ts'
import { SocketTicketResponse, RingCameraKind } from './ring-types.ts'
import {
type CameraData,
type CameraDeviceSettingsData,
Expand Down Expand Up @@ -123,6 +123,10 @@ export function cleanSnapshotUuid(uuid?: string | null) {
return uuid.replace(/:.*$/, '')
}

const wiredModelsWithNoSnapshotDuringRecording = new Set([
RingCameraKind.doorbell_graham_cracker,
])

export class RingCamera extends Subscribed {
id
deviceType
Expand Down Expand Up @@ -279,6 +283,15 @@ export class RingCamera extends Subscribed {
return this.hasBattery && this.data.settings.power_mode !== 'wired'
}

get canTakeSnapshotWhileRecording() {
return (
!this.operatingOnBattery &&
!wiredModelsWithNoSnapshotDuringRecording.has(
this.data.kind as RingCameraKind,
)
)
}

get isOffline() {
return this.data.alerts.connection === 'offline'
}
Expand Down Expand Up @@ -568,7 +581,7 @@ export class RingCamera extends Subscribed {
},
),
delay(maxSnapshotRefreshSeconds * 1000).then(() => {
const extraMessageForBatteryCam = this.operatingOnBattery
const extraMessageForBatteryCam = !this.canTakeSnapshotWhileRecording
? '. This is normal behavior since this camera is unable to capture snapshots while streaming'
: ''
throw new Error(
Expand Down

0 comments on commit c4daf65

Please sign in to comment.