/** * @license * Copyright 2022-2026 Matter.js Authors * SPDX-License-Identifier: Apache-2.0 */ import { ActionContext } from "#behavior/context/ActionContext.js"; import { Duration, MaybePromise, Observable, Timer } from "@matter/general"; import { Switch } from "@matter/types/clusters/switch"; declare const SwitchServerBase: import("../../index.js").ClusterBehavior.Type, import("@matter/types").ClusterType.Concrete, new () => {}, "switch">; /** * This is the default server implementation of {@link SwitchBehavior}. * * This implementation includes all features of {@link Switch.Cluster} and implements all mandatory commands. * You should use {@link SwitchServer.with} to specialize the class for the features your implementation * supports. * * To support all features and events the implementation adds some custom state attributes that can - or are required * to - be used. These are: * * `rawPosition` - The raw position of the switch. This is the position as reported by the device and is not yet * debounced. If the position is already debounced, just set the `currentPosition` attribute. The debouncing uses the * `debounceDelay` attribute value as timeframe in milliseconds and sets the `currentPosition` attribute when the value * is stable for this timeframe. Report positions either through `rawPosition` or through `currentPosition`, not both; * mixing them leaves the order of events undefined. * * `debounceDelay` - The timeframe in milliseconds to wait until a newly reported position is considered stable. * * `longPressDelay` - The timeframe in milliseconds to wait until a position is considered "long" pressed. This * attribute is REQUIRED if the device supports the Momentary Switch LongPress (MSL) feature. * * `multiPressDelay` - The timeframe in milliseconds starting with a stable release to detect multi-presses. This * attribute is REQUIRED if the device supports the Momentary Switch MultiPress (MSM) feature. * * `momentaryNeutralPosition` - The number of the position considered as the neutral position for the momentary switch. * This defaults to position 0 but can be changed by settings this attribute. it is available as soon as the Momentary * Switch (MS) feature is used. */ export declare class SwitchBaseServer extends SwitchServerBase { #private; protected internal: SwitchBaseServer.Internal; readonly state: SwitchBaseServer.State; readonly events: SwitchBaseServer.Events; static readonly schema: import("@matter/model").ClusterModel; initialize(): MaybePromise; /** * Method to reset the state of the Switch to start a clean new cycle. Mainly relevant for automated testing. * * Waits for the switch state lock, then drops pending debounced positions, timers and results not applied yet, so * nothing from before the reset is reported or written after it, and continues from the current position. */ resetState(): MaybePromise; [Symbol.asyncDispose](): Promise; } export declare namespace SwitchBaseServer { /** A decided consequence of a switch input, applied in the order the inputs occurred. */ type Result = { /** Emits an event. */ kind: "event"; emit(server: SwitchBaseServer): void; } | { /** Writes the currentPosition attribute. */ kind: "position"; position: number; }; class Internal { /** Timer to debounce the raw position. */ debounceTimer?: Timer; /** Timer to detect a long press. */ longPressTimer?: Timer; /** Timer to detect the end of a multi press sequence; runs only while the switch is released. */ multiPressTimer?: Timer; /** Emits the raw position that stayed stable for debounceDelay. */ debounceExpired: Observable<[position: number], void>; /** Emits when the switch was held in one press for longPressDelay. */ longPressExpired: Observable; /** Emits when the switch stayed released for multiPressDelay. */ multiPressExpired: Observable; /** Results in the order their inputs occurred that are not applied yet. */ results: Result[]; /** Emits when a result was queued. */ resultsQueued: Observable; /** Position this server writes to currentPosition, whose change it decided already. */ positionBeingWritten?: number; /** Indicator if a multi press sequence is in progress, from its first press until it ends. */ multiPressSequenceActive: boolean; /** Counter to count the number of presses. */ currentNumberOfPressesCounter: number; /** Indicator if the multi press sequence was aborted. */ multiPressReportingAborted: boolean; /** Indicator if the current press was reported with InitialPress; the release events refer to that report. */ currentPressReported: boolean; /** Position of the latest decided change; it leads currentPosition while position writes are queued. */ previouslyReportedPosition: number; /** Position of the previous multi press. */ previousMultiPressPosition: number | null; /** Position of the current long press. */ currentLongPressPosition: number | null; /** Flag to indicate if the current press is a long press. */ currentIsLongPress: boolean; } class State extends SwitchServerBase.State { /** Raw position of the switch. Set this to debounce the value; do not also set `currentPosition` directly. */ rawPosition: number; /** * Debounce Delay to wait until a newly reported raw position is considered stable and written to the * currentPosition attribute. */ debounceDelay?: Duration; /** Time to wait until a value is considered "long" pressed */ longPressDelay: Duration; /** Timeframe starting with a stable release to detect multi-presses. */ multiPressDelay: Duration; /** Number of the position considered as the neutral position for the momentary switch. */ momentaryNeutralPosition: number; numberOfPositions: number; multiPressMax: number; } /** Enhance the relevant events for rawPosition attribute. */ class Events extends SwitchServerBase.Events { rawPosition$Changed: Observable<[value: number, oldValue: number, context?: ActionContext | undefined], void>; rawPosition$Changing: Observable<[value: number, oldValue: number, context?: ActionContext | undefined], void>; } } declare const SwitchServer_base: import("../../index.js").ClusterBehavior.Type, { actionSwitch: false; latchingSwitch: false; momentarySwitch: false; momentarySwitchLongPress: false; momentarySwitchMultiPress: false; momentarySwitchRelease: false; }>, import("@matter/types").ClusterType.Concrete, typeof SwitchBaseServer.Internal, "switch">; export declare class SwitchServer extends SwitchServer_base { } export {}; //# sourceMappingURL=SwitchServer.d.ts.map