UNPKG

node-red-contrib-smartnora

Version:

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

48 lines (47 loc) 1.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const util_1 = require("./util"); module.exports = function (RED) { RED.nodes.registerType('noraf-blinds', function (config) { RED.nodes.createNode(this, config); (0, util_1.registerNoraDevice)(this, RED, config, { deviceConfig: { type: 'action.devices.types.BLINDS', traits: ['action.devices.traits.OpenClose'], name: { name: config.devicename, }, roomHint: config.roomhint, willReportState: true, noraSpecific: {}, state: { online: true, openPercent: 100, }, attributes: {}, }, updateStatus: ({ state, update }) => { update(`${'openPercent' in state && adjustPercent(state.openPercent)}%`); }, mapStateToOutput: (state) => { if ('openPercent' in state) { return { payload: { openPercent: adjustPercent(state.openPercent), }, }; } }, handleNodeInput: async ({ msg, updateState }) => { var _a; if (typeof ((_a = msg === null || msg === void 0 ? void 0 : msg.payload) === null || _a === void 0 ? void 0 : _a.openPercent) === 'number') { msg.payload.openPercent = adjustPercent(msg.payload.openPercent); } await updateState(msg === null || msg === void 0 ? void 0 : msg.payload); }, }); function adjustPercent(openPercent) { return config.invert ? 100 - openPercent : openPercent; } }); };