node-red-contrib-smartnora
Version:
Google Smart Home integration via Smart Nora https://smart-nora.eu/
34 lines (33 loc) • 1.56 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DeviceContext = void 0;
const rxjs_1 = require("rxjs");
const operators_1 = require("rxjs/operators");
class DeviceContext {
constructor(node) {
this.node = node;
this.error$ = new rxjs_1.Subject();
this.status$ = new rxjs_1.Subject();
this.local$ = new rxjs_1.Subject();
this.connected$ = new rxjs_1.Subject();
this.online$ = new rxjs_1.Subject();
}
startUpdating(stop$) {
(0, rxjs_1.combineLatest)([
this.connected$.pipe((0, operators_1.startWith)(false)),
this.status$.pipe((0, operators_1.startWith)(null)),
this.error$.pipe((0, operators_1.startWith)(null)),
this.local$.pipe((0, operators_1.startWith)(false)),
this.online$.pipe((0, operators_1.startWith)(true)),
]).pipe((0, operators_1.debounceTime)(0), (0, operators_1.tap)(([connected, state, error, local, online]) => {
this.node.status(connected
? (online ?
(error
? { fill: 'yellow', shape: 'ring', text: error }
: { fill: local ? 'blue' : 'green', shape: 'dot', text: `${state || 'connected'}` })
: { fill: 'red', shape: 'ring', text: 'offline' })
: { fill: 'red', shape: 'ring', text: 'disconnected' });
}), (0, operators_1.ignoreElements)(), (0, operators_1.takeUntil)(stop$)).subscribe();
}
}
exports.DeviceContext = DeviceContext;