UNPKG

@bacnet-js/device

Version:

A TypeScript library for implementing BACnet IP devices in Node.js.

30 lines 1.73 kB
import assert from 'node:assert'; import { BDSingletProperty, BDPolledArrayProperty, BDPolledSingletProperty, } from '../properties/index.js'; import { BDObject } from './generic/object.js'; import { ObjectType, ApplicationTag, PropertyIdentifier, ErrorClass, ErrorCode, } from '@bacnet-js/client'; import { BDError } from '../errors.js'; export class BDMultiStateValue extends BDObject { stateText; presentValue; numberOfStates; constructor(instance, opts) { assert(opts.states.length > 0, 'states array must not be empty'); super({ type: ObjectType.MULTI_STATE_VALUE, instance }, opts.name, opts.description); const numberOfStatesValue = opts.states.length; this.numberOfStates = this.addProperty(new BDPolledSingletProperty(PropertyIdentifier.NUMBER_OF_STATES, ApplicationTag.UNSIGNED_INTEGER, () => numberOfStatesValue)); const stateTextData = opts.states.map((state) => { return { type: ApplicationTag.CHARACTER_STRING, value: state }; }); this.stateText = this.addProperty(new BDPolledArrayProperty(PropertyIdentifier.STATE_TEXT, () => stateTextData)); this.presentValue = this.addProperty(new BDSingletProperty(PropertyIdentifier.PRESENT_VALUE, ApplicationTag.UNSIGNED_INTEGER, opts.writable ?? false, 1)); this.presentValue.on('beforecov', (prop, data) => { if (data.value < 1 || data.value > numberOfStatesValue) { throw new BDError('state index out of range', ErrorCode.INCONSISTENT_PARAMETERS, ErrorClass.PROPERTY); } }); if (opts.presentValue) { this.presentValue.setValue(opts.presentValue); } } } //# sourceMappingURL=multistatevalue.js.map