Skip to content

Commit

Permalink
Fix panic button naming in HomeKit
Browse files Browse the repository at this point in the history
Relates to #1420
  • Loading branch information
dgreif committed Aug 4, 2024
1 parent 297e42a commit 1552181
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/rich-pets-relax.md
Original file line number Diff line number Diff line change
@@ -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.
35 changes: 33 additions & 2 deletions packages/homebridge-ring/panic-buttons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<RingDevice> {
constructor(
public readonly device: RingDevice,
Expand All @@ -38,7 +41,7 @@ export class PanicButtons extends BaseDataAccessory<RingDevice> {
characteristicType: Characteristic.On,
serviceType: Service.Switch,
serviceSubType: 'Burglar',
name: 'Burglar Alarm',
name: burglarAlarmName,
getValue: (data) => matchesAnyAlarmState(data, burglarStates),
setValue: (on) => {
if (on) {
Expand All @@ -50,12 +53,26 @@ export class PanicButtons extends BaseDataAccessory<RingDevice> {
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) {
Expand All @@ -67,6 +84,20 @@ export class PanicButtons extends BaseDataAccessory<RingDevice> {
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() {
Expand Down

0 comments on commit 1552181

Please sign in to comment.