UNPKG

homebridge-hatch-baby-rest

Version:
61 lines (60 loc) 2.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RestMini = void 0; const hatch_sleep_types_1 = require("../shared/hatch-sleep-types"); const operators_1 = require("rxjs/operators"); const iot_device_1 = require("./iot-device"); class RestMini extends iot_device_1.IotDevice { constructor() { super(...arguments); this.model = 'Rest Mini'; this.audioTracks = hatch_sleep_types_1.restMiniAudioTracks; this.onVolume = this.onState.pipe((0, operators_1.map)((state) => (0, iot_device_1.convertToPercentage)(state.current.sound.v)), (0, operators_1.distinctUntilChanged)()); this.onAudioPlaying = this.onState.pipe((0, operators_1.map)((state) => state.current.playing !== 'none'), (0, operators_1.distinctUntilChanged)()); this.onAudioTrack = this.onState.pipe((0, operators_1.map)((state) => state.current.sound.id), (0, operators_1.distinctUntilChanged)()); this.onFirmwareVersion = this.onState.pipe((0, operators_1.map)((state) => state.deviceInfo.f)); } setVolume(percentage) { this.update({ current: { sound: { v: (0, iot_device_1.convertFromPercentage)(percentage), }, }, }); } setAudioPlaying(playing) { if (playing) { this.update({ current: { playing: 'remote', step: 1, }, }); } else { this.update({ current: { playing: 'none', step: 0, }, }); } } setAudioTrack(audioTrack) { if (audioTrack === 0 /* RestMiniAudioTrack.None */) { return; } this.update({ current: { playing: 'remote', step: 1, sound: { id: audioTrack, until: 'indefinite', }, }, }); } } exports.RestMini = RestMini;