homebridge-hatch-baby-rest
Version:
Homebridge plugin for Hatch Rest/Restore WiFi sound machines
50 lines (49 loc) • 2.11 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RestIot = void 0;
const operators_1 = require("rxjs/operators");
const iot_device_1 = require("./iot-device");
const rest_client_1 = require("./rest-client");
class RestIot extends iot_device_1.IotDevice {
constructor(info, onIotClient, restClient) {
super(info, onIotClient);
this.info = info;
this.onIotClient = onIotClient;
this.restClient = restClient;
this.model = this.info.product === "restoreIot" /* Product.restoreIot */
? 'Restore IoT'
: "riotPlus" /* Product.riotPlus */
? 'Rest+ 2nd Gen'
: 'Rest 2nd Gen';
this.onSomeContentPlaying = this.onState.pipe((0, operators_1.map)((state) => state.current.playing !== 'none'), (0, operators_1.distinctUntilChanged)());
this.onFirmwareVersion = this.onState.pipe((0, operators_1.map)((state) => state.deviceInfo.f));
}
setCurrent(playing, step, srId) {
this.update({
current: {
playing,
step,
srId,
},
});
}
async turnOnRoutine() {
const routines = await this.fetchRoutines();
this.setCurrent('routine', 1, routines[0].id);
}
turnOff() {
this.setCurrent('none', 0, 0);
}
async fetchRoutines() {
const routinesPath = (0, rest_client_1.apiPath)(`service/app/routine/v2/fetch?macAddress=${encodeURIComponent(this.info.macAddress)}`), allRoutines = await this.restClient.request({
url: routinesPath,
method: 'GET',
}), sortedRoutines = allRoutines.sort((a, b) => a.displayOrder - b.displayOrder), touchRingRoutines = sortedRoutines.filter((routine) => {
return (routine.type === 'favorite' || // Before upgrade, only favorites were on touch ring
routine.button0 // After upgrade, many routine types can be on touch ring but will have `button0: true`
);
});
return touchRingRoutines;
}
}
exports.RestIot = RestIot;