Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doorbell Notifications Control Ring Intercom #1589

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions packages/homebridge-ring/intercom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,46 @@ export class Intercom extends BaseDataAccessory<RingIntercom> {
})
}

// Notification Switch Service
const notificationService = this.getService(Service.Switch) ||
this.accessory.addService(Service.Switch, 'Ring Notifications', 'notifications'); // Added unique subtype

// Set this service as a linked service rather than primary
lockService.addLinkedService(notificationService);

this.registerCharacteristic({
characteristicType: Characteristic.On,
serviceType: notificationService,
getValue: () => {
return this.accessory.context.notificationsEnabled !== false;
},
setValue: async (state) => {
this.accessory.context.notificationsEnabled = state;

if (state) {
await device.subscribeToDingEvents().catch((e) => {
(0, util_1.logError)('Failed to subscribe to ding events: ' + e);
});
} else {
await device.unsubscribeFromDingEvents().catch((e) => {
(0, util_1.logError)('Failed to unsubscribe from ding events: ' + e);
});
}
},
});

// Make sure the notification service has its own identity
notificationService
.setCharacteristic(Characteristic.Name, 'Ring Notifications')
.setCharacteristic(Characteristic.ConfiguredName, 'Ring Notifications');

// Update the notification subscription on startup based on stored state
if (this.accessory.context.notificationsEnabled !== false) {
device.subscribeToDingEvents().catch((e) => {
(0, util_1.logError)('Failed to subscribe to ding events on startup: ' + e);
});
}

// Accessory Information Service
this.registerCharacteristic({
characteristicType: Characteristic.Manufacturer,
Expand Down