This is the default server implementation of LevelControlBehavior.

This implementation includes all features of LevelControl.Cluster and implements all mandatory commands. The On-Off Feature is automatically turned on as defined by the matter specification. You should use LevelControlServer.with to specialize the class for the features your implementation supports.

This default implementation also handles the OnOff cluster dependency and the ColorControl dependency as defined by the Matter specification automatically.

This implementation ignores by default all transition times and sets the level immediately. Alternatively, you can set the managedTransitionTimeHandling state attribute to true to have matter.js manage transition times by changing the level value step-wise every second. This might be an intermediate solution if you develop independently of defined hardware.

If you develop for a specific hardware you should extend the LevelControlServer class and implement the following methods to natively use device features to correctly support the transition times. For this the default implementation uses special protected methods which are used by the real commands and are only responsible for the actual value change logic. The benefit of this structure is that basic data validations and options checks are already done, and you can focus on the actual hardware interaction:

If you add own implementation you can use:

All overridable methods except setRemainingTime can be implemented sync or async by returning a Promise.

Hierarchy

  • LevelControlLogicBase
    • LevelControlServerLogic

Constructors

  • Parameters

    • agent: Agent
    • backing: BehaviorBacking

    Returns LevelControlServerLogic

Properties

[reference]: Datasource<StateType>
agent: Agent
cluster: never

The implemented cluster.

context: ActionContext
endpoint: Endpoint<Empty>
events: EventEmitter & Omit<ClusterEvents<LevelControl.Cluster, Type<Of<{
    attributes: {};
    commands: {};
    events: {};
    id: 0;
    name: "Unknown";
    revision: 0;
}>, typeof ClusterBehavior, LevelControlInterface>>,
    | "minLevel$Changing"
    | "maxLevel$Changing"
    | "minLevel$Changed"
    | "maxLevel$Changed"
    | "options$Changing"
    | "options$Changed"
    | "currentLevel$Changing"
    | "onLevel$Changing"
    | "onOffTransitionTime$Changing"
    | "onTransitionTime$Changing"
    | "offTransitionTime$Changing"
    | "defaultMoveRate$Changing"
    | "currentLevel$Changed"
    | "onLevel$Changed"
    | "onOffTransitionTime$Changed"
    | "onTransitionTime$Changed"
    | "offTransitionTime$Changed"
    | "defaultMoveRate$Changed"> & {
    currentLevel$Changing: ClusterEvents.AttributeObservable<Attribute<null | number, any>>;
    onLevel$Changing: ClusterEvents.AttributeObservable<WritableAttribute<null | number, any>>;
    options$Changing: ClusterEvents.AttributeObservable<WritableAttribute<TypeFromPartialBitSchema<{
        coupleColorTempToLevel: BitFlag;
        executeIfOff: BitFlag;
    }>, any>>;
    remainingTime$Changing: ClusterEvents.AttributeObservable<Attribute<number, any>>;
    startUpCurrentLevel$Changing: ClusterEvents.AttributeObservable<WritableAttribute<null | number, any>>;
} & {
    defaultMoveRate$Changing: undefined | ClusterEvents.AttributeObservable<OptionalWritableAttribute<null | number, any>>;
    maxLevel$Changing: undefined | ClusterEvents.AttributeObservable<OptionalAttribute<number, any>>;
    minLevel$Changing: undefined | ClusterEvents.AttributeObservable<OptionalAttribute<number, any>>;
    offTransitionTime$Changing: undefined | ClusterEvents.AttributeObservable<OptionalWritableAttribute<null | number, any>>;
    onOffTransitionTime$Changing: undefined | ClusterEvents.AttributeObservable<OptionalWritableAttribute<number, any>>;
    onTransitionTime$Changing: undefined | ClusterEvents.AttributeObservable<OptionalWritableAttribute<null | number, any>>;
} & {
    currentLevel$Changed: ClusterEvents.AttributeObservable<Attribute<null | number, any>>;
    onLevel$Changed: ClusterEvents.AttributeObservable<WritableAttribute<null | number, any>>;
    options$Changed: ClusterEvents.AttributeObservable<WritableAttribute<TypeFromPartialBitSchema<{
        coupleColorTempToLevel: BitFlag;
        executeIfOff: BitFlag;
    }>, any>>;
    remainingTime$Changed: ClusterEvents.AttributeObservable<Attribute<number, any>>;
    startUpCurrentLevel$Changed: ClusterEvents.AttributeObservable<WritableAttribute<null | number, any>>;
} & {
    defaultMoveRate$Changed: undefined | ClusterEvents.AttributeObservable<OptionalWritableAttribute<null | number, any>>;
    maxLevel$Changed: undefined | ClusterEvents.AttributeObservable<OptionalAttribute<number, any>>;
    minLevel$Changed: undefined | ClusterEvents.AttributeObservable<OptionalAttribute<number, any>>;
    offTransitionTime$Changed: undefined | ClusterEvents.AttributeObservable<OptionalWritableAttribute<null | number, any>>;
    onOffTransitionTime$Changed: undefined | ClusterEvents.AttributeObservable<OptionalWritableAttribute<number, any>>;
    onTransitionTime$Changed: undefined | ClusterEvents.AttributeObservable<OptionalWritableAttribute<null | number, any>>;
} & {} & {}

Access the behavior's events.

features: TypeFromBitSchema<{}> & TypeFromBitSchema<{
    frequency: BitFlag;
    lighting: BitFlag;
    onOff: BitFlag;
}> & TypeFromBitSchema<{
    frequency: BitFlag;
    lighting: BitFlag;
    onOff: BitFlag;
}>

Supported features as a flag object.

internal: Internal
session: SecureSession
state: State

Access the behavior's state.

Base cluster state include all attribute values but may be extended by subclasses.

defaults: ClusterState.Type<WithFeatures<LevelControl.Cluster, readonly [OnOff, Lighting]>, Type<LevelControl.Cluster, Type<Of<{
    attributes: {};
    commands: {};
    events: {};
    id: 0;
    name: "Unknown";
    revision: 0;
}>, typeof ClusterBehavior, LevelControlInterface>, LevelControlInterface>>
dependencies?: Iterable<Type, any, any>
early: boolean
Events: ClusterEvents.Type<WithFeatures<LevelControl.Cluster, readonly [OnOff, Lighting]>, Type<LevelControl.Cluster, Type<Of<{
    attributes: {};
    commands: {};
    events: {};
    id: 0;
    name: "Unknown";
    revision: 0;
}>, typeof ClusterBehavior, LevelControlInterface>, LevelControlInterface>>
id

The behavior ID for ClusterBehaviors is the name of the cluster.

name: string
schema?: Schema
supervisor: RootSupervisor
supports: ((other: Type) => boolean)

Type declaration

    • (other): boolean
    • Does this behavior support functionality of a specific implementation?

      Parameters

      Returns boolean

Accessors

  • get currentLevel(): number
  • The current level value as number. Throws an StatusResponse Error when null!

    Returns number

  • get maxLevel(): number
  • Returns the maximum level, including feature specific fallback value handling.

    Returns number

  • get minLevel(): number
  • Returns the minimum level, including feature specific fallback value handling.

    Returns number

Methods

  • Returns Promise<void>

  • Execute logic with elevated privileges.

    The provided function executes with privileges escalated to offline mode. This is not commonly necessary.

    Elevated logic effectively ignores ACLs so should be used with care.

    Note that interactions with the behavior will remain elevated until the synchronous completion of this call. You should only elevate privileges for synchronous logic.

    Parameters

    • fn: (() => void)

      the elevated logic

        • (): void
        • Returns void

    Returns void

  • Type Parameters

    • This extends Behavior
    • K extends string | number | symbol

    Parameters

    • this: This
    • attributeName: K

    Returns void

  • Create a generic callback function that has the same properties as a Reactor.

    Like a reactor, the callback's "this" will be bound to an active Behavior instance. Because of this: The reactor MUST be a real JS function - arrow functions will not work!

    Type Parameters

    • A extends any[]
    • R

    Parameters

    Returns ((...args: A) => undefined | R)

      • (...args): undefined | R
      • Parameters

        • Rest...args: A

        Returns undefined | R

  • Protected

    This is the default implementation of the required interaction with the OnOff cluster on the same endpoint when the onOff feature is used. This implementation just sets the current level to the onLevel value when the device is turned on. Other fading up/down logic required by the MatterSpecification.v12.Cluster §1.6.4.1.1 needs to be implemented in a specialized class if needed.

    Parameters

    • onOff: boolean

      The new onOff state

    Returns void

  • Behaviors are ephemeral and should not perform initialization in their constructor. They can override this method instead.

    This method may be synchronous or asyncronous. If asynchronous, the behavior will not be available for external use until initialization completes.

    Returns void

  • Default implementation notes: After the options checks it uses the moveLogic method to set the level. If you want to implement own logic just override moveLogic with is also used for moveWithOnOff. The logic is implemented as follows: When no move rate is provided and also no default move rate is set, the server will move as fast as possible, so we set to min/max directly. Else the step logic is applied and the level is increased or decreased by the step size every second.

    Parameters

    Returns MaybePromise<void>

  • Protected

    Default implementation of the move logic. When no move rate is provided and also no default move rate is set, the server will move as fast as possible, so it is set to min/max directly. Else the step logic is applied and the level is increased or decreased by the step size every second. The method uses setLevel to set the level and handle the on/off state if the method is called by a *WithOnOff command.

    Parameters

    • moveMode: LevelControl.MoveMode

      Mode (Up/Down) of the move action

    • rate: null | number

      Rate of the move action, null if no rate is provided and the default should be used

    • withOnOff: boolean

      true if the method is called by a *WithOnOff command

    • Optionaloptions: TypeFromPartialBitSchema<{
          coupleColorTempToLevel: BitFlag;
          executeIfOff: BitFlag;
      }>

      Options for the command

    Returns MaybePromise<void>

  • Default implementation notes: This method ignores the transition time provided by the command or settings and just sets the level to the requested value. After the options and value checks it uses the moveToLevelLogic method to set the level. If you want to implement own logic just override moveToLevelLogic with is also used for moveToLevelWithOnOff.

    Parameters

    Returns MaybePromise<void>

  • Protected

    Default implementation of the moveToLevel logic. When a transition time is specified the implementation uses a step based logic to manage the move. It also checks if the level is within the min and max level range and sets the level accordingly. The method uses setLevel to set the level and handle the on/off state if the method is called by a *WithOnOff command.

    Parameters

    • level: number

      Level to set

    • transitionTime: null | number

      Transition time, ignored in this default implementation

    • withOnOff: boolean

      true if the method is called by a *WithOnOff command

    • Optionaloptions: TypeFromPartialBitSchema<{
          coupleColorTempToLevel: BitFlag;
          executeIfOff: BitFlag;
      }>

      Options for the command

    Returns MaybePromise<void>

  • Default implementation notes: This method ignores the transition time provided by the command or settings and just sets the level to the requested value. After the options and value checks it uses the moveToLevelLogic method to set the level. If you want to implement own logic just override moveToLevelLogic with is also used for moveToLevel.

    Parameters

    Returns MaybePromise<void>

  • Default implementation notes: This implementation uses the moveLogic method to set the level. If you want to implement own logic just override moveLogic with is also used for move. The logic is implemented as follows: When no move rate is provided and also no default move rate is set, the server will move as fast as possible, so we set to min/max directly. Else the step logic is applied and the level is increased or decreased by the step size every second.

    Parameters

    Returns MaybePromise<void>

  • Install a Reactor.

    Important: The reactor MUST be a real JS function - arrow functions will not work!

    Type Parameters

    Parameters

    Returns void

  • Type Parameters

    • This extends Behavior
    • K extends string | number | symbol

    Parameters

    • this: This
    • attributeName: K

    Returns Exclude<This["state"][K], undefined>

  • Protected

    Default implementation of the logic to set the level including the handing of the on/off state when one of the *WithOnOff commands is called. This implementation checks if the level is at the minLevel and the device is on, it will turn off the device. If the level is above the minLevel and the device is off, it will turn on the device.

    Parameters

    • level: number

      Level which is set by the command

    • withOnOff: boolean

      true if the method is called by a *WithOnOff command

    • Optionaloptions: TypeFromPartialBitSchema<{
          coupleColorTempToLevel: BitFlag;
          executeIfOff: BitFlag;
      }>

      Options for the command

    Returns MaybePromise<void>

  • Protected

    Method to set the remaining time attribute when Lighting feature is enabled.

    Parameters

    • remainingTime: number

      Remaining time in 1/10th of a second

    Returns void

  • Default implementation notes: After the options checks it uses the stepLogic method to set the level. If you want to implement own logic just override stepLogic with is also used for stepWithOnOff. The logic is implemented as follows: When no transition time is provided, the server will move as fast as possible, so we set to currentlevel +/- stepSize directly. Else the step logic is applied and the level is increased or decreased by the step size every transition time interval.

    Parameters

    Returns MaybePromise<void>

  • Protected

    Default implementation of the step logic. When no transition time is provided, the server will move as fast as possible, so it is set to min/max directly. Else the level is increased or decreased by the step size every second. The method uses setLevel to set the level and handle the on/off state if the method is called by a *WithOnOff command. The remaining time is updated with every step.

    Parameters

    • stepMode: LevelControl.StepMode

      Mode (Up/Down) of the step action

    • stepSize: number

      Size of the step action

    • transitionTime: null | number

      Time of the step action in 10th of a second

    • withOnOff: boolean

      true if the method is called by a *WithOnOff command

    • Optionaloptions: TypeFromPartialBitSchema<{
          coupleColorTempToLevel: BitFlag;
          executeIfOff: BitFlag;
      }>

      Options for the command

    Returns MaybePromise<void>

  • Default implementation notes: This implementation uses the stepLogic method to set the level. If you want to implement own logic just override stepLogic with is also used for step. The logic is implemented as follows: When no transition time is provided, the server will move as fast as possible, so we set to min/max directly. Else the step logic is applied and the level is increased or decreased by the step size every transition time interval.

    Parameters

    Returns MaybePromise<void>

  • Parameters

    Returns MaybePromise<void>

    MatterSpecification.v13.Cluster § 1.6.7.4

  • Protected

    Default implementation of the stop logic. This stops any level transitions currently appening and sets the remaining time to 0.

    Parameters

    Returns MaybePromise<void>

  • Parameters

    Returns MaybePromise<void>

    MatterSpecification.v13.Cluster § 1.6.7

  • Description used in diagnostic messages.

    Returns string

  • Type Parameters

    Parameters

    Returns This