UNPKG

node-red-contrib-home-assistant-websocket

Version:
27 lines (26 loc) 1.42 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const InputOutputController_1 = __importDefault(require("../../common/controllers/InputOutputController")); const NoConnectionError_1 = __importDefault(require("../../common/errors/NoConnectionError")); const const_1 = require("../../const"); class RenderTemplateController extends InputOutputController_1.default { async onInput({ message, parsedMessage, send, done, }) { if (!this.homeAssistant.websocket.isConnected) { throw new NoConnectionError_1.default(); } const { template, templateLocation, templateLocationType, resultsLocation, resultsLocationType, } = parsedMessage; this.status.setSending('api-render-template.status.requesting'); const results = await this.homeAssistant.http.renderTemplate(template.value); if (templateLocationType.value !== const_1.TypedInputTypes.None) { this.contextService.set(template.value, templateLocationType.value, templateLocation.value, message); } this.contextService.set(results, resultsLocationType.value, resultsLocation.value, message); send(message); this.status.setSuccess(); done(); } } exports.default = RenderTemplateController;