@ngreatorex/homie-device
Version:
Homie Device for NodeJS
69 lines • 2.93 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DefaultConfiguration = exports.PropertyDataType = void 0;
const lodash_1 = __importDefault(require("lodash"));
const framework_1 = require("./framework");
var PropertyDataType;
(function (PropertyDataType) {
PropertyDataType[PropertyDataType["integer"] = 0] = "integer";
PropertyDataType[PropertyDataType["float"] = 1] = "float";
PropertyDataType[PropertyDataType["boolean"] = 2] = "boolean";
PropertyDataType[PropertyDataType["string"] = 3] = "string";
PropertyDataType[PropertyDataType["enum"] = 4] = "enum";
PropertyDataType[PropertyDataType["color"] = 5] = "color";
})(PropertyDataType = exports.PropertyDataType || (exports.PropertyDataType = {}));
exports.DefaultConfiguration = {
dataType: PropertyDataType.string,
retained: false,
settable: true,
};
class HomieProperty extends framework_1.HomieTopologyElement {
constructor(parent, config) {
super(lodash_1.default.merge({}, exports.DefaultConfiguration, config), parent);
this.onConnect = () => {
super.onConnect();
this.publishAttributes({
datatype: lodash_1.default.isNumber(this.config.dataType) ? PropertyDataType[this.config.dataType] : this.config.dataType,
format: this.config.format,
name: this.friendlyName,
retained: !!this.config.retained,
settable: this.config.settable,
unit: this.config.unit,
});
};
this.invokeSetter = (range, value) => {
if (!this.config.settable) {
throw new Error("This property is not settable");
}
this.emit("set", { range, value });
};
this.publishValue = (value, rangeIndex) => {
this.parent.publishPropertyValue(this, value, rangeIndex);
};
}
set unit(value) { this.config.unit = value; }
get unit() { return this.config.unit; }
set datatype(value) { this.config.dataType = value; }
get datatype() { return this.config.dataType; }
set format(value) { this.config.format = value; }
get format() { return this.config.format; }
set retained(value) {
if (!lodash_1.default.isBoolean(value)) {
throw new Error("retained must be a boolean");
}
this.config.retained = value;
}
get retained() { return this.config.retained; }
get settable() { return this.config.settable; }
set settable(value) {
if (!lodash_1.default.isBoolean(value)) {
throw new Error("retained must be a boolean");
}
this.config.settable = value;
}
}
exports.default = HomieProperty;
//# sourceMappingURL=HomieProperty.js.map