UNPKG

@koush/ring-client-api

Version:

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

64 lines (63 loc) 2.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Beam = void 0; const api_1 = require("../api"); const hap_1 = require("./hap"); const base_device_accessory_1 = require("./base-device-accessory"); class Beam extends base_device_accessory_1.BaseDeviceAccessory { constructor(device, accessory, logger, config) { super(); this.device = device; this.accessory = accessory; this.logger = logger; this.config = config; this.isLightGroup = this.device.data.deviceType === api_1.RingDeviceType.BeamsLightGroupSwitch; this.groupId = this.device.data.groupId; const { Characteristic, Service } = hap_1.hap, { MotionSensor } = Service, { data: { deviceType }, } = this.device; if (deviceType !== api_1.RingDeviceType.BeamsMotionSensor) { this.registerCharacteristic({ characteristicType: Characteristic.On, serviceType: Service.Lightbulb, getValue: (data) => Boolean(data.on), setValue: (value) => this.setOnState(value), }); this.getService(Service.Lightbulb).setPrimaryService(true); } if (deviceType === api_1.RingDeviceType.BeamsMultiLevelSwitch) { this.registerLevelCharacteristic({ characteristicType: Characteristic.Brightness, serviceType: Service.Lightbulb, getValue: (data) => { return data.level && !isNaN(data.level) ? 100 * data.level : 0; }, setValue: (value) => this.setLevelState(value), }); } if (device.data.motionStatus !== undefined) { this.registerCharacteristic({ characteristicType: hap_1.hap.Characteristic.MotionDetected, serviceType: MotionSensor, getValue: (data) => data.motionStatus === 'faulted', }); this.initSensorService(MotionSensor); } } setOnState(on) { this.logger.info(`Turning ${this.device.name} ${on ? 'On' : 'Off'}`); const { beamDurationSeconds } = this.config, duration = beamDurationSeconds ? Math.min(beamDurationSeconds, 32767) : undefined; if (this.isLightGroup && this.groupId) { return this.device.location.setLightGroup(this.groupId, on, duration); } const data = on ? { lightMode: 'on', duration } : { lightMode: 'default' }; return this.device.sendCommand('light-mode.set', data); } setLevelState(level) { this.logger.info(`Setting brightness of ${this.device.name} to ${level}%`); return this.device.setInfo({ device: { v1: { level: level / 100 } }, }); } } exports.Beam = Beam;