UNPKG

bacnet-device

Version:

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

89 lines 3.65 kB
import { type BACNetAppData, type ApplicationTag, type PropertyIdentifier, type ApplicationTagValueTypeMap } from '@innovation-system/node-bacnet'; import { type EventMap, AsyncEventEmitter } from '../events.js'; import { TaskQueue } from '../taskqueue.js'; /** * Maps the names of property events to the respective arrays of arguments. * Used to strongly type calls to `AsyncEventEmitter.prototype.on()`. * * @see {@link AsyncEventEmitter} */ export interface BDPropertyEvents<Tag extends ApplicationTag, Type extends ApplicationTagValueTypeMap[Tag], Data extends BACNetAppData<Tag, Type> | BACNetAppData<Tag, Type>[]> extends EventMap { /** * Emitted before a property value changes. Listeners can throw in order to * block the change from going through (useful for additional validation). */ beforecov: [property: BDAbstractProperty<Tag, Type, Data>, raw: Data]; /** * Emitted after a property value has changed. Errors throws by listeners * will be ignored. */ aftercov: [property: BDAbstractProperty<Tag, Type, Data>, raw: Data]; } /** * Enumerates the types of properties that can be defined. */ export declare enum BDPropertyType { /** A property whose data consists of a single value. */ SINGLET = 0, /** A property whose data consists of an array of values. */ ARRAY = 1 } /** * Dictionary of items available while accessing a property's data, * usually via a `context` or `ctx` argument. */ export interface BDPropertyAccessContext { /** The date and time at which the property is being accessed. */ date: Date; } /** * Describes a function that may be set as a property's data instead of a * static value. */ export type BDPropertyDataGetter<Data extends BACNetAppData | BACNetAppData[]> = (ctx: BDPropertyAccessContext) => Data; /** * Abstract base class for all types of properties. */ export declare abstract class BDAbstractProperty<Tag extends ApplicationTag, Type extends ApplicationTagValueTypeMap[Tag], Data extends BACNetAppData<Tag, Type> | BACNetAppData<Tag, Type>[]> extends AsyncEventEmitter<BDPropertyEvents<Tag, Type, Data>> { #private; /** * @see {@link BDPropertyType} */ abstract readonly type: BDPropertyType; /** * This property's BACnet identifier. */ readonly identifier: PropertyIdentifier; constructor(identifier: PropertyIdentifier, writable: boolean, data: Data | BDPropertyDataGetter<Data>); /** * Returns true if the property is writable (commandable) from other devices * on the BACnet network, false otherwise. */ isWritable(): boolean; /** * Sets whether this property can be written to from other devices on the * BACnet network. */ setWritable(writable: boolean): void; getData(): Data; setData(data: Data): Promise<void>; abstract ___readData(index: number, ctx: BDPropertyAccessContext): BACNetAppData | BACNetAppData[]; abstract ___writeData(value: BACNetAppData<Tag, Type> | BACNetAppData<Tag, Type>[]): Promise<void>; /** * Allows the object to which this property is added to share its own task * queue, so that calls to `setData` may be managed transactionally * with requests to access the property's data coming from the BACnet * network. * @see {@link setData} * @internal */ ___setQueue(queue: TaskQueue): void; /** * Used by subclasses to update this property's data. * @see {@link ___readData} * @see {@link ___writeData} * @internal */ protected ___updateData(data: Data): Promise<void>; } //# sourceMappingURL=abstract.d.ts.map