@ngreatorex/homie-device
Version:
Homie Device for NodeJS
36 lines • 1.5 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const HomieTopologyWithConfiguration_1 = __importDefault(require("./HomieTopologyWithConfiguration"));
class HomieTopologyRoot extends HomieTopologyWithConfiguration_1.default {
constructor(config) {
super(config);
this.client$ = null;
}
set client(client) {
this.client$ = client;
}
get client() { return this.client$; }
rawPublish(path, value, options) {
var _a;
if (this.client$ === null) {
throw new Error("client has not been initialized");
}
const resolvedTopic = `${((_a = this.config.mqtt) === null || _a === void 0 ? void 0 : _a.base_topic) || "homie"}/${path}`;
this.logger.debug(`publishing ${resolvedTopic}: ${value}`);
this.client$.publish(resolvedTopic, value, options || {});
}
rawSubscribe(path) {
var _a;
if (this.client$ === null) {
throw new Error("client has not been initialized");
}
const resolvedTopic = `${((_a = this.config.mqtt) === null || _a === void 0 ? void 0 : _a.base_topic) || "homie"}/${path}`;
this.logger.debug(`subscribing to ${resolvedTopic}`);
this.client$.subscribe(resolvedTopic);
}
}
exports.default = HomieTopologyRoot;
//# sourceMappingURL=HomieTopologyRoot.js.map