UNPKG

node-red-contrib-home-assistant-websocket

Version:
38 lines (37 loc) 1.86 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 NoIntegrationError_1 = __importDefault(require("../../common/errors/NoIntegrationError")); const Integration_1 = require("../../common/integration/Integration"); class DeviceAction extends InputOutputController_1.default { async onInput({ message, send, done }) { var _a, _b, _c, _d; if (!((_a = this.homeAssistant) === null || _a === void 0 ? void 0 : _a.isConnected)) { throw new NoConnectionError_1.default(); } if (!this.homeAssistant.isIntegrationLoaded) { throw new NoIntegrationError_1.default(); } const capabilities = (_b = this.node.config.capabilities) === null || _b === void 0 ? void 0 : _b.reduce((acc, cap) => { acc[cap.name] = cap.value; return acc; }, {}); const payload = { type: Integration_1.MessageType.DeviceAction, action: { ...this.node.config.event, ...capabilities }, }; await this.homeAssistant.websocket.send(payload); await this.setCustomOutputs(this.node.config.outputProperties, message, { config: this.node.config, data: payload, }); this.status.setSuccess(`${(_c = this.node.config.event) === null || _c === void 0 ? void 0 : _c.domain}.${(_d = this.node.config.event) === null || _d === void 0 ? void 0 : _d.type}`); send(message); done(); } } exports.default = DeviceAction;