node-red-contrib-home-assistant-websocket
Version:
Node-RED integration with Home Assistant through websocket and REST API
44 lines (43 loc) • 1.65 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = entityNode;
const globals_1 = require("../../globals");
const migrate_1 = require("../../helpers/migrate");
const status_1 = require("../../helpers/status");
const utils_1 = require("../../helpers/utils");
const sensor_controller_1 = __importDefault(require("./sensor-controller"));
const switch_controller_1 = __importDefault(require("./switch-controller"));
function entityNode(config) {
globals_1.RED.nodes.createNode(this, config);
this.config = (0, migrate_1.migrate)(config);
(0, utils_1.checkValidServerConfig)(this, this.config.server);
switch (this.config.entityType) {
case 'binary_sensor':
case 'sensor': {
const status = new status_1.Status(this);
this.controller = new sensor_controller_1.default({
node: this,
config: this.config,
RED: globals_1.RED,
status,
});
break;
}
case 'switch': {
const status = new status_1.SwitchEntityStatus(this);
this.controller = new switch_controller_1.default({
node: this,
config: this.config,
RED: globals_1.RED,
status,
});
break;
}
default:
this.status({ text: 'Error' });
throw new Error(`Invalid entity type: ${this.config.entityType}`);
}
}
;