UNPKG

node-red-contrib-home-assistant-websocket

Version:
84 lines (83 loc) 3.53 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.inputSchema = exports.inputs = void 0; exports.default = BinarySensor; 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 BinarySensorController_1 = __importDefault(require("./BinarySensorController")); exports.inputs = { state: { messageProp: 'payload.state', configProp: 'state', default: 'payload', }, stateType: { messageProp: 'payload.stateType', configProp: 'stateType', default: const_1.TypedInputTypes.Message, }, attributes: { messageProp: 'payload.attributes', configProp: 'attributes', default: [], }, }; exports.inputSchema = joi_1.default.object({ state: joi_1.default.alternatives() .try(joi_1.default.string(), joi_1.default.boolean(), joi_1.default.number()) .required(), stateType: joi_1.default.string() .valid(const_1.TypedInputTypes.Message, const_1.TypedInputTypes.Flow, const_1.TypedInputTypes.Global, const_1.TypedInputTypes.JSONata, const_1.TypedInputTypes.String, const_1.TypedInputTypes.Number, const_1.TypedInputTypes.Boolean) .required(), attributes: joi_1.default.alternatives().try( // schema for config attributes joi_1.default.array().items(joi_1.default.object({ property: joi_1.default.string().required(), value: joi_1.default.any().required(), valueType: joi_1.default.string() .valid(const_1.TypedInputTypes.Message, const_1.TypedInputTypes.Flow, const_1.TypedInputTypes.Global, const_1.TypedInputTypes.JSONata, const_1.TypedInputTypes.String, const_1.TypedInputTypes.Number, const_1.TypedInputTypes.Boolean, const_1.TypedInputTypes.Date) .required(), })), // schema for message attributes joi_1.default.object().pattern(/.*/, [ joi_1.default.string(), joi_1.default.number(), joi_1.default.boolean(), joi_1.default.object(), joi_1.default.array(), ])), }); function BinarySensor(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, homeAssistant_1.getHomeAssistant)(serverConfigNode); const status = new Status_1.default({ config: serverConfigNode.config, node: this, }); const controllerDeps = (0, helpers_1.createControllerDependencies)(this, homeAssistant); const inputService = new InputService_1.default({ inputs: exports.inputs, nodeConfig: this.config, schema: exports.inputSchema, }); // eslint-disable-next-line no-new new BinarySensorController_1.default({ inputService, node: this, status, integration: entityConfigNode.integration, ...controllerDeps, }); }