UNPKG

@koush/ring-client-api

Version:

Unofficial API for Ring doorbells, cameras, security alarm system and smart lighting

78 lines (77 loc) 3.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PanicButtons = void 0; const hap_1 = require("./hap"); const base_data_accessory_1 = require("./base-data-accessory"); const burglarStates = [ 'burglar-alarm', 'user-verified-burglar-alarm', 'burglar-accelerated-alarm', ], fireStates = [ 'fire-alarm', 'user-verified-co-or-fire-alarm', 'fire-accelerated-alarm', ]; function matchesAnyAlarmState({ alarmInfo }, targetStates) { return Boolean(alarmInfo && targetStates.includes(alarmInfo.state)); } class PanicButtons extends base_data_accessory_1.BaseDataAccessory { constructor(device, accessory, logger, config) { super(); this.device = device; this.accessory = accessory; this.logger = logger; this.config = config; const { Characteristic, Service } = hap_1.hap, locationName = device.location.name; this.registerCharacteristic({ characteristicType: Characteristic.On, serviceType: Service.Switch, serviceSubType: 'Burglar', name: 'Burglar Alarm', getValue: (data) => matchesAnyAlarmState(data, burglarStates), setValue: (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({ characteristicType: Characteristic.On, serviceType: Service.Switch, serviceSubType: 'Fire', name: 'Fire Alarm', getValue: (data) => matchesAnyAlarmState(data, fireStates), setValue: (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_1.hap; this.registerCharacteristic({ characteristicType: Characteristic.Manufacturer, serviceType: Service.AccessoryInformation, getValue: (data) => data.manufacturerName || 'Ring', }); this.registerCharacteristic({ characteristicType: Characteristic.Model, serviceType: Service.AccessoryInformation, getValue: () => 'Panic Buttons for ' + this.device.location.name, }); this.registerCharacteristic({ characteristicType: Characteristic.SerialNumber, serviceType: Service.AccessoryInformation, getValue: () => 'None', }); super.initBase(); } } exports.PanicButtons = PanicButtons;