From 1552181b47d9f9dba031c3a592591f90369a7970 Mon Sep 17 00:00:00 2001 From: dgreif Date: Sun, 4 Aug 2024 16:24:20 -0400 Subject: [PATCH] Fix panic button naming in HomeKit Relates to #1420 --- .changeset/rich-pets-relax.md | 5 ++++ packages/homebridge-ring/panic-buttons.ts | 35 +++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 .changeset/rich-pets-relax.md diff --git a/.changeset/rich-pets-relax.md b/.changeset/rich-pets-relax.md new file mode 100644 index 00000000..78859768 --- /dev/null +++ b/.changeset/rich-pets-relax.md @@ -0,0 +1,5 @@ +--- +'homebridge-ring': patch +--- + +Set panic button names in such a way that they are properly reflected in the Home app. Note, this only impacts users who have the `showPanicButtons` option enabled. These users will likely see a new warning about "Configured Name" not being a supported characteristic of "Switch", which can be ignored. diff --git a/packages/homebridge-ring/panic-buttons.ts b/packages/homebridge-ring/panic-buttons.ts index d7cc6d8c..f6c60b51 100644 --- a/packages/homebridge-ring/panic-buttons.ts +++ b/packages/homebridge-ring/panic-buttons.ts @@ -23,6 +23,9 @@ function matchesAnyAlarmState( return Boolean(alarmInfo && targetStates.includes(alarmInfo.state)) } +const burglarAlarmName = 'Burglar Alarm', + fireAlarmName = 'Fire Alarm' + export class PanicButtons extends BaseDataAccessory { constructor( public readonly device: RingDevice, @@ -38,7 +41,7 @@ export class PanicButtons extends BaseDataAccessory { characteristicType: Characteristic.On, serviceType: Service.Switch, serviceSubType: 'Burglar', - name: 'Burglar Alarm', + name: burglarAlarmName, getValue: (data) => matchesAnyAlarmState(data, burglarStates), setValue: (on) => { if (on) { @@ -50,12 +53,26 @@ export class PanicButtons extends BaseDataAccessory { return this.device.location.setAlarmMode('none') }, }) + this.registerCharacteristic({ + characteristicType: Characteristic.Name, + serviceType: Service.Switch, + serviceSubType: 'Burglar', + name: burglarAlarmName, + getValue: () => burglarAlarmName, + }) + this.registerCharacteristic({ + characteristicType: Characteristic.ConfiguredName, + serviceType: Service.Switch, + serviceSubType: 'Burglar', + name: burglarAlarmName, + getValue: () => burglarAlarmName, + }) this.registerCharacteristic({ characteristicType: Characteristic.On, serviceType: Service.Switch, serviceSubType: 'Fire', - name: 'Fire Alarm', + name: fireAlarmName, getValue: (data) => matchesAnyAlarmState(data, fireStates), setValue: (on) => { if (on) { @@ -67,6 +84,20 @@ export class PanicButtons extends BaseDataAccessory { return this.device.location.setAlarmMode('none') }, }) + this.registerCharacteristic({ + characteristicType: Characteristic.Name, + serviceType: Service.Switch, + serviceSubType: 'Fire', + name: fireAlarmName, + getValue: () => fireAlarmName, + }) + this.registerCharacteristic({ + characteristicType: Characteristic.ConfiguredName, + serviceType: Service.Switch, + serviceSubType: 'Fire', + name: fireAlarmName, + getValue: () => fireAlarmName, + }) } initBase() {