@bacnet-js/device
Version:
A TypeScript library for implementing BACnet IP devices in Node.js.
53 lines • 1.57 kB
JavaScript
import { ErrorCode, ErrorClass, ApplicationTag, } from '@bacnet-js/client';
import { BDError } from '../../errors.js';
import { BDAbstractSingletProperty } from './abstract.js';
import {} from '../types.js';
export class BDSingletProperty extends BDAbstractSingletProperty {
#writable;
#data;
constructor(identifier, type, writable, value, encoding) {
super(identifier);
this.#data = { type, value, encoding };
this.#writable = writable;
}
getData(ctx) {
return this.#data;
}
getValue(ctx) {
return this.getData().value;
}
async setData(data) {
await this.___asyncEmitSeries(true, 'beforecov', this, data);
this.#data = data;
await this.___asyncEmitSeries(false, 'aftercov', this, data);
}
async setValue(value) {
await this.setData({ ...this.getData(), value });
}
/**
*
* @internal
*/
___readData(index, ctx) {
return this.getData(ctx);
}
/**
*
* @internal
*/
async ___writeData(data) {
if (!this.#writable) {
throw new BDError('not writable', ErrorCode.WRITE_ACCESS_DENIED, ErrorClass.PROPERTY);
}
if (Array.isArray(data)) {
if (data.length !== 1) {
throw new BDError('property is not an array or list', ErrorCode.WRITE_ACCESS_DENIED, ErrorClass.PROPERTY);
}
else {
data = data[0];
}
}
await this.setData(data);
}
}
//# sourceMappingURL=singlet.js.map