-
-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(homebridge): panic buttons for burglar and fire
- Loading branch information
Showing
10 changed files
with
242 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { RingDevice, RingDeviceData, AlarmState } from '../api' | ||
import { HAP, hap } from './hap' | ||
import { RingPlatformConfig } from './config' | ||
import { BaseAccessory } from './base-accessory' | ||
|
||
const burglarStates: AlarmState[] = [ | ||
'burglar-alarm', | ||
'user-verified-burglar-alarm', | ||
'burglar-accelerated-alarm' | ||
], | ||
fireStates: AlarmState[] = [ | ||
'fire-alarm', | ||
'user-verified-co-or-fire-alarm', | ||
'fire-accelerated-alarm' | ||
] | ||
|
||
function matchesAnyAlarmState( | ||
{ alarmInfo }: RingDeviceData, | ||
targetStates: AlarmState[] | ||
) { | ||
return Boolean(alarmInfo && targetStates.includes(alarmInfo.state)) | ||
} | ||
|
||
export class PanicButtons extends BaseAccessory<RingDevice> { | ||
constructor( | ||
public readonly device: RingDevice, | ||
public readonly accessory: HAP.Accessory, | ||
public readonly logger: HAP.Log, | ||
public readonly config: RingPlatformConfig | ||
) { | ||
super() | ||
|
||
const { Characteristic, Service } = hap, | ||
locationName = device.location.locationDetails.name | ||
|
||
this.registerCharacteristic( | ||
Characteristic.On, | ||
this.getService(Service.Switch, 'Burglar Alarm', 'Burglar'), | ||
data => matchesAnyAlarmState(data, burglarStates), | ||
on => { | ||
if (on) { | ||
this.logger.info(`Burglar Alarm activated for ${locationName}`) | ||
return this.device.location.triggerBurglarAlarm() | ||
} | ||
|
||
this.logger.info(`Burglar Alarm turned off for ${locationName}`) | ||
return this.device.location.setAlarmMode('none') | ||
} | ||
) | ||
|
||
this.registerCharacteristic( | ||
Characteristic.On, | ||
this.getService(Service.Switch, 'Fire Alarm', 'Fire'), | ||
data => matchesAnyAlarmState(data, fireStates), | ||
on => { | ||
if (on) { | ||
this.logger.info(`Fire Alarm activated for ${locationName}`) | ||
return this.device.location.triggerFireAlarm() | ||
} | ||
|
||
this.logger.info(`Fire Alarm turned off for ${locationName}`) | ||
return this.device.location.setAlarmMode('none') | ||
} | ||
) | ||
} | ||
|
||
initBase() { | ||
const { Characteristic, Service } = hap | ||
|
||
this.registerCharacteristic( | ||
Characteristic.Manufacturer, | ||
Service.AccessoryInformation, | ||
data => data.manufacturerName || 'Ring' | ||
) | ||
this.registerCharacteristic( | ||
Characteristic.Model, | ||
Service.AccessoryInformation, | ||
() => 'Panic Buttons for ' + this.device.location.locationDetails.name | ||
) | ||
this.registerCharacteristic( | ||
Characteristic.SerialNumber, | ||
Service.AccessoryInformation, | ||
() => 'None' | ||
) | ||
|
||
super.initBase() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.