UNPKG

node-red-contrib-smartnora

Version:

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

69 lines (68 loc) 3.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const mapping_1 = require("./mapping"); const util_1 = require("./util"); module.exports = function (RED) { RED.nodes.registerType('noraf-thermostat', function (config) { var _a, _b; RED.nodes.createNode(this, config); const noraConfig = RED.nodes.getNode(config.nora); if (!(noraConfig === null || noraConfig === void 0 ? void 0 : noraConfig.valid)) { return; } const availableModes = config.modes.split(','); const rangeMin = parseInt(config.rangeMin, 10); const rangeMax = parseInt(config.rangeMax, 10); (0, util_1.registerNoraDevice)(this, RED, config, { deviceConfig: { type: 'action.devices.types.THERMOSTAT', traits: ['action.devices.traits.TemperatureSetting'], name: { name: config.devicename, }, roomHint: config.roomhint, willReportState: true, attributes: { availableThermostatModes: availableModes, thermostatTemperatureUnit: config.unit, bufferRangeCelsius: parseInt(config.bufferRangeCelsius, 10) || undefined, commandOnlyTemperatureSetting: (_a = config.commandOnly) !== null && _a !== void 0 ? _a : undefined, queryOnlyTemperatureSetting: (_b = config.queryOnly) !== null && _b !== void 0 ? _b : undefined, thermostatTemperatureRange: !isNaN(rangeMin) && !isNaN(rangeMax) ? { minThresholdCelsius: rangeMin, maxThresholdCelsius: rangeMax, } : undefined, }, state: { online: true, thermostatMode: 'off', thermostatTemperatureAmbient: 25, thermostatTemperatureSetpoint: 20, }, noraSpecific: {}, }, updateStatus: ({ state, update }) => { const setpoint = state.thermostatMode === 'heatcool' ? (0, util_1.R) `${state.thermostatTemperatureSetpointLow}-${state.thermostatTemperatureSetpointHigh}` : (0, util_1.R) `${state.thermostatTemperatureSetpoint}`; update((0, util_1.R) `${state.thermostatMode}/T:${state.thermostatTemperatureAmbient}/S:${setpoint}`); }, mapStateToOutput: state => ({ payload: { mode: state.thermostatMode, activeMode: state.activeThermostatMode, setpoint: state.thermostatTemperatureSetpoint, setpointLow: state.thermostatTemperatureSetpointLow, setpointHigh: state.thermostatTemperatureSetpointHigh, }, }), handleNodeInput: async ({ msg, updateState }) => { await updateState(msg === null || msg === void 0 ? void 0 : msg.payload, [ ...mapping_1.TEMPERATURE_SETTING_STATE_MAPPING, ]); }, }); }); };