UNPKG

node-red-contrib-home-assistant-websocket

Version:
49 lines (48 loc) 2.75 kB
"use strict"; var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { if (kind === "m") throw new TypeError("Private method is not writable"); if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; var _UpdateConfig_homeAssistant; Object.defineProperty(exports, "__esModule", { value: true }); const InputOutputController_1 = __importDefault(require("../../common/controllers/InputOutputController")); const InputError_1 = __importDefault(require("../../common/errors/InputError")); const NoConnectionError_1 = __importDefault(require("../../common/errors/NoConnectionError")); class UpdateConfig extends InputOutputController_1.default { constructor(props) { super(props); _UpdateConfig_homeAssistant.set(this, void 0); __classPrivateFieldSet(this, _UpdateConfig_homeAssistant, props.homeAssistant, "f"); } async onInput({ parsedMessage, message, send, done }) { var _a, _b, _c, _d; if (!((_a = this.integration) === null || _a === void 0 ? void 0 : _a.isConnected)) { throw new NoConnectionError_1.default(); } if (!((_b = this.integration) === null || _b === void 0 ? void 0 : _b.isIntegrationLoaded)) { throw new InputError_1.default('home-assistant.error.integration_not_loaded', 'home-assistant.error.error'); } const config = { entity_picture: parsedMessage.entityPicture.value, name: parsedMessage.name.value, icon: parsedMessage.icon.value, options: parsedMessage.options.value, }; this.status.setSending(); await ((_c = this.integration) === null || _c === void 0 ? void 0 : _c.sendUpdateConfig(this.integration.getEntityConfigNode().config.server, (_d = parsedMessage.id.value) !== null && _d !== void 0 ? _d : this.node.id, config)); this.integration.saveHaConfigToContext(config); this.status.setSuccess('home-assistant.status.updated'); await this.setCustomOutputs(this.node.config.outputProperties, message, { config: this.node.config, }); send(message); done(); } } _UpdateConfig_homeAssistant = new WeakMap(); exports.default = UpdateConfig;