node-red-contrib-home-assistant-websocket
Version:
Node-RED integration with Home Assistant through websocket and REST API
64 lines (63 loc) • 3.06 kB
JavaScript
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _NodeRedContextService_node;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ContextLocation = void 0;
exports.isContextLocation = isContextLocation;
const globals_1 = require("../../globals");
var ContextLocation;
(function (ContextLocation) {
ContextLocation["Msg"] = "msg";
ContextLocation["Flow"] = "flow";
ContextLocation["Global"] = "global";
})(ContextLocation || (exports.ContextLocation = ContextLocation = {}));
function isContextLocation(location) {
return Object.values(ContextLocation).includes(location);
}
class NodeRedContextService {
constructor(node) {
_NodeRedContextService_node.set(this, void 0);
__classPrivateFieldSet(this, _NodeRedContextService_node, node, "f");
}
get(location, property, message) {
if (location === 'msg') {
if (!message)
return;
return globals_1.RED.util.getMessageProperty(message, property);
}
const { key, store } = globals_1.RED.util.parseContextStore(property);
const context = __classPrivateFieldGet(this, _NodeRedContextService_node, "f").context();
switch (location) {
case 'flow':
return context.flow.get(key, store);
case 'global':
return context.global.get(key, store);
}
}
set(val, location, property, message) {
const { key, store } = globals_1.RED.util.parseContextStore(property);
switch (location) {
case 'flow':
case 'global':
__classPrivateFieldGet(this, _NodeRedContextService_node, "f").context()[location].set(key, val, store);
break;
case 'msg':
if (message) {
globals_1.RED.util.setObjectProperty(message, key, val);
}
break;
}
}
}
_NodeRedContextService_node = new WeakMap();
exports.default = NodeRedContextService;
;