node-red-contrib-home-assistant-websocket
Version:
Node-RED integration with Home Assistant through websocket and REST API
69 lines (68 loc) • 2.78 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = renderTemplateNode;
const joi_1 = __importDefault(require("joi"));
const helpers_1 = require("../../common/controllers/helpers");
const InputService_1 = __importDefault(require("../../common/services/InputService"));
const Status_1 = __importDefault(require("../../common/status/Status"));
const const_1 = require("../../const");
const globals_1 = require("../../globals");
const migrate_1 = require("../../helpers/migrate");
const node_1 = require("../../helpers/node");
const homeAssistant_1 = require("../../homeAssistant");
const RenderTemplateController_1 = __importDefault(require("./RenderTemplateController"));
const inputs = {
template: {
messageProp: 'template',
configProp: 'template',
},
resultsLocation: {
messageProp: 'resultsLocation',
configProp: 'resultsLocation',
},
resultsLocationType: {
messageProp: 'resultsLocationType',
configProp: 'resultsLocationType',
},
templateLocation: {
messageProp: 'templateLocation',
configProp: 'templateLocation',
},
templateLocationType: {
messageProp: 'templateLocationType',
configProp: 'templateLocationType',
},
};
const inputSchema = joi_1.default.object({
template: joi_1.default.string().required(),
resultsLocation: joi_1.default.string(),
resultsLocationType: joi_1.default.string().valid(const_1.TypedInputTypes.Message, const_1.TypedInputTypes.Flow, const_1.TypedInputTypes.Global),
templateLocation: joi_1.default.string().empty(''),
templateLocationType: joi_1.default.string().valid(const_1.TypedInputTypes.Message, const_1.TypedInputTypes.Flow, const_1.TypedInputTypes.Global, const_1.TypedInputTypes.None),
});
function renderTemplateNode(config) {
globals_1.RED.nodes.createNode(this, config);
this.config = (0, migrate_1.migrate)(config);
const serverConfigNode = (0, node_1.getServerConfigNode)(this.config.server);
const homeAssistant = (0, homeAssistant_1.getHomeAssistant)(serverConfigNode);
const status = new Status_1.default({
config: serverConfigNode.config,
node: this,
});
const inputService = new InputService_1.default({
inputs,
nodeConfig: this.config,
schema: inputSchema,
});
const controllerDeps = (0, helpers_1.createControllerDependencies)(this, homeAssistant);
// eslint-disable-next-line no-new
new RenderTemplateController_1.default({
inputService,
node: this,
status,
...controllerDeps,
});
}