@bacnet-js/device
Version:
A TypeScript library for implementing BACnet IP devices in Node.js.
40 lines • 1.3 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 BDPolledSingletProperty extends BDAbstractSingletProperty {
#poll;
#data;
constructor(identifier, type, poll, encoding) {
super(identifier);
this.#poll = poll;
this.#data = { type, value: poll({ date: new Date() }), encoding };
}
getData(ctx) {
this.#data.value = this.#poll(ctx ?? { date: new Date() });
return this.#data;
}
getValue(ctx) {
return this.getData().value;
}
/**
*
* @internal
*/ ___readData(index, ctx) {
return this.getData(ctx);
}
async setData() {
throw new BDError('Cannot set data of polled property', ErrorCode.WRITE_ACCESS_DENIED, ErrorClass.PROPERTY);
}
async setValue() {
throw new BDError('Cannot set value of polled property', ErrorCode.WRITE_ACCESS_DENIED, ErrorClass.PROPERTY);
}
/**
*
* @internal
*/
async ___writeData() {
throw new BDError('Cannot write data of polled property', ErrorCode.WRITE_ACCESS_DENIED, ErrorClass.PROPERTY);
}
}
//# sourceMappingURL=polled.js.map