UNPKG

node-red-contrib-home-assistant-websocket

Version:
38 lines (37 loc) 1.67 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = buttonNode; const helpers_1 = require("../../common/controllers/helpers"); const Events_1 = __importDefault(require("../../common/events/Events")); const Status_1 = __importDefault(require("../../common/status/Status")); const globals_1 = require("../../globals"); const migrate_1 = require("../../helpers/migrate"); const node_1 = require("../../helpers/node"); const index_1 = require("../../homeAssistant/index"); const ButtonController_1 = __importDefault(require("./ButtonController")); function buttonNode(config) { globals_1.RED.nodes.createNode(this, config); this.config = (0, migrate_1.migrate)(config); const { entityConfigNode, serverConfigNode } = (0, node_1.getConfigNodes)(this); const homeAssistant = (0, index_1.getHomeAssistant)(serverConfigNode); const status = new Status_1.default({ config: serverConfigNode.config, node: this, }); const entityConfigEvents = new Events_1.default({ node: this, emitter: entityConfigNode, }); entityConfigEvents.setStatus(status); const controllerDeps = (0, helpers_1.createControllerDependencies)(this, homeAssistant); entityConfigNode.integration.setStatus(status); const controller = new ButtonController_1.default({ node: this, status, ...controllerDeps, }); entityConfigEvents.addListener(index_1.HaEvent.AutomationTriggered, controller.onTrigger.bind(controller)); }