UNPKG

@koush/ring-client-api

Version:

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

105 lines (104 loc) 4.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Chime = void 0; const hap_1 = require("./hap"); const base_data_accessory_1 = require("./base-data-accessory"); const util_1 = require("../api/util"); const minutesFor24Hours = 24 * 60; class Chime 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, snoozeService = this.getService(Service.Switch, device.name + ' Snooze', 'snooze'), playDingService = this.getService(Service.Switch, device.name + ' Play Ding', 'play-ding'), playMotionService = this.getService(Service.Switch, device.name + ' Play Motion', 'play-motion'); // Snooze Switch this.registerCharacteristic({ characteristicType: Characteristic.On, serviceType: snoozeService, getValue: (data) => Boolean(data.do_not_disturb.seconds_left), setValue: (snooze) => { if (snooze) { (0, util_1.logInfo)(device.name + ' snoozed for 24 hours'); return device.snooze(minutesFor24Hours); } (0, util_1.logInfo)(device.name + ' snooze cleared'); return device.clearSnooze(); }, requestUpdate: () => device.requestUpdate(), }); snoozeService.setPrimaryService(true); // Speaker Service this.registerCharacteristic({ characteristicType: Characteristic.Mute, serviceType: Service.Speaker, getValue: () => false, }); this.registerLevelCharacteristic({ characteristicType: Characteristic.Volume, serviceType: Service.Speaker, getValue: (data) => data.settings.volume, setValue: (volume) => device.setVolume(volume), requestUpdate: () => device.requestUpdate(), }); this.getService(Service.Speaker) .getCharacteristic(Characteristic.Volume) .setProps({ minValue: 0, maxValue: 11, }); // Play Sound Switches this.registerCharacteristic({ characteristicType: Characteristic.On, serviceType: playDingService, getValue: () => false, setValue: (play) => { if (!play) { return; } setTimeout(() => { playDingService .getCharacteristic(Characteristic.On) .updateValue(false); }, 1000); return this.device.playSound('ding'); }, requestUpdate: () => device.requestUpdate(), }); this.registerCharacteristic({ characteristicType: Characteristic.On, serviceType: playMotionService, getValue: () => false, setValue: (play) => { if (!play) { return; } setTimeout(() => { playMotionService .getCharacteristic(Characteristic.On) .updateValue(false); }, 1000); return this.device.playSound('motion'); }, requestUpdate: () => device.requestUpdate(), }); // Accessory Information Service this.registerCharacteristic({ characteristicType: Characteristic.Manufacturer, serviceType: Service.AccessoryInformation, getValue: () => 'Ring', }); this.registerCharacteristic({ characteristicType: Characteristic.Model, serviceType: Service.AccessoryInformation, getValue: () => device.model, }); this.registerCharacteristic({ characteristicType: Characteristic.SerialNumber, serviceType: Service.AccessoryInformation, getValue: (data) => data.device_id || 'Unknown', }); } } exports.Chime = Chime;