UNPKG

node-red-contrib-smartnora

Version:

Google Smart Home integration via Smart Nora https://smart-nora.eu/

45 lines (44 loc) 2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const rxjs_1 = require("rxjs"); const operators_1 = require("rxjs/operators"); const scene_device_1 = require("../nora/scene-device"); const util_1 = require("./util"); module.exports = function (RED) { RED.nodes.registerType('noraf-scene', function (config) { RED.nodes.createNode(this, config); const noraConfig = RED.nodes.getNode(config.nora); if (!(noraConfig === null || noraConfig === void 0 ? void 0 : noraConfig.valid)) { return; } const { value: onValue, type: onType } = (0, util_1.convertValueType)(RED, config.onvalue, config.onvalueType, { defaultValue: true }); const { value: offValue, type: offType } = (0, util_1.convertValueType)(RED, config.offvalue, config.offvalueType, { defaultValue: false }); (0, util_1.registerNoraDevice)(this, RED, config, { deviceConfig: { type: 'action.devices.types.SCENE', traits: ['action.devices.traits.Scene'], name: { name: config.devicename, }, willReportState: true, roomHint: config.roomhint, attributes: { sceneReversible: !!config.scenereversible, }, state: { online: true }, noraSpecific: {}, }, customRegistration: device$ => device$.pipe((0, operators_1.switchMap)(d => d instanceof scene_device_1.FirebaseSceneDevice ? d.activateScene$ : rxjs_1.EMPTY), (0, operators_1.tap)(({ deactivate }) => { const value = !deactivate; this.send({ payload: (0, util_1.getValue)(RED, this, value ? onValue : offValue, value ? onType : offType), topic: config.topic }); })), }); }); };