MCPcopy Index your code
hub / github.com/WebThingsIO/webthing-node / constructor

Method constructor

lib/property.ts:41–60  ·  view source on GitHub ↗

* Initialize the object. * * @param {Thing} thing Thing this property belongs to * @param {String} name Name of the property * @param {Value} value Value object to hold the property value * @param {Object} metadata Property metadata, i.e. type, description, unit, *

(thing: Thing,
              name: string,
              value: Value<ValueType>,
              metadata: Property.PropertyMetadata)

Source from the content-addressed store, hash-verified

39 * etc., as an object.
40 */
41 constructor(thing: Thing,
42 name: string,
43 value: Value<ValueType>,
44 metadata: Property.PropertyMetadata) {
45 this.thing = thing;
46 this.name = name;
47 this.value = value;
48 this.hrefPrefix = '';
49 this.href = `/properties/${this.name}`;
50 this.metadata = JSON.parse(JSON.stringify(metadata || {}));
51
52 delete metadata.title;
53 delete metadata.unit;
54 delete metadata['@type'];
55 this.validate = ajv.compile(metadata);
56
57 // Add the property change observer to notify the Thing about a property
58 // change.
59 this.value.on('update', () => this.thing.propertyNotify(this));
60 }
61
62 /**
63 * Validate new property value before setting it.

Callers

nothing calls this directly

Calls 1

propertyNotifyMethod · 0.80

Tested by

no test coverage detected