node-red-contrib-home-assistant-websocket
Version:
Node-RED integration with Home Assistant through websocket and REST API
62 lines (61 loc) • 2.53 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 = currentStateNode;
const joi_1 = __importDefault(require("joi"));
const helpers_1 = require("../../common/controllers/helpers");
const ComparatorService_1 = __importDefault(require("../../common/services/ComparatorService"));
const InputService_1 = __importDefault(require("../../common/services/InputService"));
const Status_1 = __importDefault(require("../../common/status/Status"));
const TransformState_1 = __importDefault(require("../../common/TransformState"));
const globals_1 = require("../../globals");
const migrate_1 = require("../../helpers/migrate");
const node_1 = require("../../helpers/node");
const homeAssistant_1 = require("../../homeAssistant");
const CurrentStateController_1 = __importDefault(require("./CurrentStateController"));
const inputs = {
entityId: {
messageProp: ['payload.entity_id', 'payload.entityId'],
configProp: 'entity_id',
},
};
const inputSchema = joi_1.default.object({
entityId: joi_1.default.string().required(),
});
function currentStateNode(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,
});
if (this.config.blockInputOverrides) {
inputService.disableInputOverrides();
}
const controllerDeps = (0, helpers_1.createControllerDependencies)(this, homeAssistant);
const transformState = new TransformState_1.default(serverConfigNode.config.ha_boolean);
const comparatorService = new ComparatorService_1.default({
nodeRedContextService: controllerDeps.nodeRedContextService,
homeAssistant,
jsonataService: controllerDeps.jsonataService,
transformState,
});
// eslint-disable-next-line no-new
new CurrentStateController_1.default({
comparatorService,
inputService,
node: this,
status,
transformState,
...controllerDeps,
});
}