homebridge-hatch-baby-rest
Version:
Homebridge plugin for Hatch Rest/Restore WiFi sound machines
54 lines (53 loc) • 1.75 kB
JavaScript
import { RestMiniAudioTrack, restMiniAudioTracks, } from "../shared/hatch-sleep-types.js";
import { distinctUntilChanged, map } from 'rxjs/operators';
import { convertFromPercentage, convertToPercentage, IotDevice, } from "./iot-device.js";
export class RestMini extends IotDevice {
model = 'Rest Mini';
audioTracks = restMiniAudioTracks;
onVolume = this.onState.pipe(map((state) => convertToPercentage(state.current.sound.v)), distinctUntilChanged());
onAudioPlaying = this.onState.pipe(map((state) => state.current.playing !== 'none'), distinctUntilChanged());
onAudioTrack = this.onState.pipe(map((state) => state.current.sound.id), distinctUntilChanged());
onFirmwareVersion = this.onState.pipe(map((state) => state.deviceInfo.f));
setVolume(percentage) {
this.update({
current: {
sound: {
v: 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 === RestMiniAudioTrack.None) {
return;
}
this.update({
current: {
playing: 'remote',
step: 1,
sound: {
id: audioTrack,
until: 'indefinite',
},
},
});
}
}