Attribute server for normal attributes that can be read and written.

Type Parameters

  • T

Hierarchy (view full)

Constructors

  • Type Parameters

    • T

    Parameters

    • id: AttributeId
    • name: string
    • readAcl: undefined | AccessLevel
    • writeAcl: undefined | AccessLevel
    • schema: TlvSchema<T>
    • isWritable: boolean
    • isSubscribable: boolean
    • requiresTimedInteraction: boolean
    • initValue: T
    • defaultValue: undefined | T
    • datasource: ClusterDatasource<any>
    • Optionalgetter: ((session?: Session, endpoint?: EndpointInterface, isFabricFiltered?: boolean, message?: Message) => T)
        • (session?, endpoint?, isFabricFiltered?, message?): T
        • Parameters

          Returns T

    • Optionalsetter: ((value: T, session?: Session, endpoint?: EndpointInterface, message?: Message) => boolean)

      Optional setter function to handle special requirements or the data are stored in different places. If a setter method is used for a writable attribute, the getter method must be implemented as well. The method needs to return if the stored value has changed or not.

        • (value, session?, endpoint?, message?): boolean
        • Parameters

          • value: T

            the value to be set.

          • Optionalsession: Session

            the session that is requesting the value (if any).

          • Optionalendpoint: EndpointInterface

            the endpoint the cluster server of this attribute is assigned to.

          • Optionalmessage: Message

          Returns boolean

          true if the value has changed, false otherwise.

    • Optionalvalidator: ((value: T, session?: Session, endpoint?: EndpointInterface) => void)

      Optional Validator function to handle special requirements for verification of stored data. The method should throw an error if the value is not valid. If a StatusResponseError is thrown this one is also returned to the client.

      If a setter is used then no validator should be used as the setter should handle the validation itself!

        • (value, session?, endpoint?): void
        • Parameters

          • value: T

            the value to be set.

          • Optionalsession: Session

            the session that is requesting the value (if any).

          • Optionalendpoint: EndpointInterface

            the endpoint the cluster server of this attribute is assigned to.

          Returns void

    Returns AttributeServer<T>

Properties

datasource: ClusterDatasource<any>
defaultValue: T
delayedChangeData?: DelayedChangeData = undefined
getter: ((session?: Session, endpoint?: EndpointInterface, isFabricFiltered?: boolean, message?: Message) => T)
isFixed = false
isSubscribable: boolean
isWritable: boolean
name: string
requiresTimedInteraction: boolean
schema: TlvSchema<T>
setter: ((value: T, session?: Session, endpoint?: EndpointInterface, message?: Message) => boolean)
validator: ((value: T, session?: Session, endpoint?: EndpointInterface) => void)
value: undefined | T = undefined

The value is undefined when getter/setter are used. But we still handle the version number here.

valueChangeListeners: ((value: T, version: number) => void)[] = ...
valueSetListeners: ((newValue: T, oldValue: T) => void)[] = ...

Accessors

Methods

  • Get the value of the attribute including the version number. This method is used by the Interaction model to read the value of the attribute and includes the ACL check. It should not be used locally in the code!

    If a getter is defined the value is determined by that getter method. The version number is always 0 for fixed attributes.

    Parameters

    Returns {
        value: T;
        version: number;
    }

    • value: T
    • version: number
  • Helper Method to handle needed version increases and trigger the relevant listeners. This method is used internally.

    Parameters

    • value: T
    • oldValue: undefined | T
    • considerVersionChanged: boolean

    Returns void

  • Set the value of the attribute. This method is used by the Interaction model to write the value of the attribute and includes the ACL check. It should not be used locally in the code!

    If a setter is defined this setter method is called to store the value.

    Listeners are called when the value changes (internal listeners) or in any case (external listeners).

    Parameters

    • value: T
    • session: Session
    • Optionalmessage: Message
    • delayChangeEvents: boolean = false

    Returns void

  • Set the value of the attribute locally. This method should be used locally in the code and does not include the ACL check.

    If a setter is defined this setter method is called to validate and store the value.

    Else if a validator is defined the value is validated before it is stored.

    Listeners are called when the value changes (internal listeners) or in any case (external listeners).

    Parameters

    • value: T

    Returns void

  • Add an external listener that is called when the value of the attribute changes. The listener is called with the new value and the old value. This method is a convenient alias for addValueSetListener.

    Parameters

    • listener: ((newValue: T, oldValue: T) => void)
        • (newValue, oldValue): void
        • Parameters

          • newValue: T
          • oldValue: T

          Returns void

    Returns void

  • When the value is handled by getter or setter methods and is changed by other processes this method can be used to notify the attribute server that the value has changed. This will increase the version number and trigger the listeners.

    ACL checks needs to be performed before calling this method.

    Parameters

    Returns void

  • When the value is handled by getter or setter methods and is changed by other processes and no session from the originating process is known this method can be used to notify the attribute server that the value has changed. This will increase the version number and trigger the listeners.

    ACL checks needs to be performed before calling this method.

    Returns void