OnOffTrait

struct OnOffTrait

This trait provides an interface for turning devices on and off.

  • No supported events for OnOffTrait.

    Declaration

    Swift

    static let supportedEventTypes: [any Event.Type]
  • List of the commands that are supported by OnOffTrait.

    Declaration

    Swift

    static let supportedCommandTypes: [any Command.Type]
  • The trait identifier.

    Declaration

    Swift

    static let identifier: String
  • Metadata about this Trait.

    Declaration

    Swift

    let metadata: TraitMetadata
  • List of attributes for the OnOffTrait.

    Declaration

    Swift

    let attributes: Matter.OnOffTrait.Attributes
  • Creates a new Trait instance using data read from the given TraitDecoder.

    Throws

    HomeError.parseError when parsing fails.

    Declaration

    Swift

    init(decoder: TraitDecoder, interactionProxy: (any InteractionProxy)?, metadata: TraitMetadata) throws

    Parameters

    decoder

    The raw data representing this Trait.

    interactionProxy

    Proxy to the Interaction Client.

    metadata

    Metadata about this Trait.

  • Writes this object to the given TraitEncoder. Throws HomeError.encodingFailed if the data could not be encoded.

    Declaration

    Swift

    func encode(with encoder: TraitEncoder) throws
  • This API provides the ability to invalidate state retrieved through subscriptions to the target device in the cases where state is not being reported correctly, either intentionally (e.g attributes in Matter traits with the “C” quality) or unintentionally due to poor implementations.

    When successful, this API will result in a forced read of the convening scope as specified by the sub-class and return the result through existing Trait subscriptions if present and active.

    This API is to be used sparingly as it can impact the performance and battery life of the target device. As such, this API may be throttled by the platform. Callers SHALL be prepared to deal with HomeErrors thrown by this call.

    Declaration

    Swift

    func forceRead() async throws
  • Attributes for the OnOffTrait.

    Declaration

    Swift

    struct Attributes
  • Returns a Boolean value indicating whether two values are equal.

    Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

    Declaration

    Swift

    static func == (lhs: Matter.OnOffTrait, rhs: Matter.OnOffTrait) -> Bool

    Parameters

    lhs

    A value to compare.

    rhs

    Another value to compare.

  • Hashes the essential components of this value by feeding them into the given hasher.

    Implement this method to conform to the Hashable protocol. The components used for hashing must be the same as the components compared in your type’s == operator implementation. Call hasher.combine(_:) with each of these components.

    Important

    In your implementation of hash(into:), don’t call finalize() on the hasher instance provided, or replace it with a different instance. Doing so may become a compile-time error in the future.

    Declaration

    Swift

    func hash(into hasher: inout Hasher)
  • Whether the device supports the off command for this trait.

    Declaration

    Swift

    var supportsOffCommand: Bool { get }
  • Turn off the device, and set the onOff attribute to false.

    Declaration

    Swift

    func off() async throws
  • The batchable version of off command above.

    See also

    off

    Declaration

    Swift

    func offBatchable() throws -> BatchableCommand<Void>
  • Whether the device supports the on command for this trait.

    Declaration

    Swift

    var supportsOnCommand: Bool { get }
  • Turn on the device, and set the onOff attribute to true.

    Declaration

    Swift

    func on() async throws
  • The batchable version of on command above.

    See also

    on

    Declaration

    Swift

    func onBatchable() throws -> BatchableCommand<Void>
  • Whether the device supports the toggle command for this trait.

    Declaration

    Swift

    var supportsToggleCommand: Bool { get }
  • If the device is off, turn the device on and set the onOff attribute to true. If the device is on, turn the device off and set the onOff attribute to false.

    Declaration

    Swift

    func toggle() async throws
  • The batchable version of toggle command above.

    See also

    toggle

    Declaration

    Swift

    func toggleBatchable() throws -> BatchableCommand<Void>
  • Whether the device supports the offWithEffect command for this trait.

    Declaration

    Swift

    var supportsOffWithEffectCommand: Bool { get }
  • Allow devices to be turned off using enhanced ways of fading.

    Declaration

    Swift

    func offWithEffect(effectIdentifier: Matter.OnOffTrait.EffectIdentifierEnum, effectVariant: UInt8) async throws

    Parameters

    effectIdentifier

    The fading effect to use when turning the device off. Must be a value from [OnOffTrait.EffectIdentifierEnum].

    effectVariant

    Variant of the effect, indicated by the effectIdentifier parameter, that is triggered. This must be one of the values in [OnOffTrait.DelayedAllOffEffectVariantEnum] or [OnOffTrait.DyingLightEffectVariantEnum] that correspond to the effect specified for effectIdentifier.

  • The batchable version of offWithEffect command above.

    See also

    offWithEffect

    Declaration

    Swift

    func offWithEffectBatchable(effectIdentifier: Matter.OnOffTrait.EffectIdentifierEnum, effectVariant: UInt8) throws -> BatchableCommand<Void>
  • Whether the device supports the onWithRecallGlobalScene command for this trait.

    Declaration

    Swift

    var supportsOnWithRecallGlobalSceneCommand: Bool { get }
  • Allow the recall of the settings (global scene) the device had when the device was turned off. This command is ignored if the globalSceneControl attribute is true. If the globalSceneControl attribute is false, the global scene is recalled, the onOff attribute is updated accordingly, and the globalSceneControl attribute is set to true. When this command is called, if the onTime attribute is 0, then the offWaitTime attribute is also set to 0.

    Declaration

    Swift

    func onWithRecallGlobalScene() async throws
  • The batchable version of onWithRecallGlobalScene command above.

    See also

    onWithRecallGlobalScene

    Declaration

    Swift

    func onWithRecallGlobalSceneBatchable() throws -> BatchableCommand<Void>
  • Whether the device supports the onWithTimedOff command for this trait.

    Declaration

    Swift

    var supportsOnWithTimedOffCommand: Bool { get }
  • Allow the device to be turned on for a specific duration with a guarded off duration so that, should the device be subsequently turned off, further OnWithTimedOff commands received during this time are prevented from turning the devices back on.

    Declaration

    Swift

    func onWithTimedOff(onOffControl: Matter.OnOffTrait.OnOffControlBitmap, onTime: UInt16, offWaitTime: UInt16) async throws

    Parameters

    onOffControl

    When set to 1, the onWithTimedOff command will only be processed if the onOff attribute is true. When set to 0, the onWithTimedOff command is always processed.

    onTime

    The duration for which device is turned on. Sets the value of the onTime attribute.

    offWaitTime

    The guarded off duration to set for the device. Sets the value of the offWaitTime attribute.

  • The batchable version of onWithTimedOff command above.

    See also

    onWithTimedOff

    Declaration

    Swift

    func onWithTimedOffBatchable(onOffControl: Matter.OnOffTrait.OnOffControlBitmap, onTime: UInt16, offWaitTime: UInt16) throws -> BatchableCommand<Void>
  • Delayed fading effects for lighting.

    Declaration

    Swift

    enum DelayedAllOffEffectVariantEnum
  • Dying effects for lighting.

    Declaration

    Swift

    enum DyingLightEffectVariantEnum
  • Fading effect types for use with lighting.

    Declaration

    Swift

    enum EffectIdentifierEnum
  • Startup behaviors for a device.

    Declaration

    Swift

    enum StartUpOnOffEnum
  • OnOff cluster FeatureMap.

    Declaration

    Swift

    struct Feature
  • Flags for cluster control.

    Declaration

    Swift

    struct OnOffControlBitmap