-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbacnet-object-property.js
63 lines (51 loc) · 1.51 KB
/
bacnet-object-property.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//
// BACnet device implementation.
// Property of an object, such as the current value or maximum reading.
//
const nodeUtil = require('util');
const bacnet = require('bacstack');
const propertyTypeMap = require('./typemap-property');
const Util = require('./util');
const pi = bacnet.enum.PropertyIdentifier;
const typeEnumMap = {
[pi.OBJECT_TYPE]: bacnet.enum.ObjectType,
};
class BACnetObjectProperty
{
constructor(propertyId, typeId = undefined, readOnly = false) {
this.propertyId = propertyId;
this.typeId = typeId || propertyTypeMap[propertyId];
this.readOnly = readOnly;
if (this.typeId === undefined) {
throw new Error(`Property ${Util.getPropName(propertyId)} has no default `
+ `type set, you must specify one yourself or update the bacnet-device `
+ `Node module.`);
}
}
get value() {
return this._value;
}
set value(newValue) {
if (this.readOnly) {
throw new Error(`Property ${Util.getPropName(this.propertyId)} cannot be changed.`);
}
this._value = newValue;
// TODO: Notify any subscribeCOV listeners
console.log('value updated, notify listeners');
}
valueAsString() {
let lookup = typeEnumMap[this.propertyId];
let value = this._value;
if (lookup) {
value = Util.getEnumName(lookup, value) + `(${value})`;
}
return value;
}
toString() {
return `BACnetObjectProperty { ${Util.getPropName(this.propertyId)}(${this.propertyId}) = ${this.valueAsString()} }`;
}
[nodeUtil.inspect.custom]() {
return this.toString();
}
};
module.exports = BACnetObjectProperty;