# OpenCloseTrait

    struct OpenCloseTrait

This trait belongs to devices that support opening and closing, and in some cases opening and
closing partially or potentially in more than one direction.
- `


  ### [supportedEventTypes](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google/OpenCloseTrait#/s:15GoogleHomeTypes0A0O14OpenCloseTraitV014supportedEventC0Say0aB3SDK0H0_pXpGvpZ)


  ` List of the event types that are supported by `OpenCloseTrait`.

  #### Declaration

  Swift

      static let supportedEventTypes: [any Event.Type]

- `


  ### [supportedCommandTypes](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google/OpenCloseTrait#/s:15GoogleHomeTypes0A0O14OpenCloseTraitV016supportedCommandC0Say0aB3SDK0H0_pXpGvpZ)


  ` List of the commands that are supported by `OpenCloseTrait`.

  #### Declaration

  Swift

      static let supportedCommandTypes: [any Command.Type]

- `


  ### [identifier](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google/OpenCloseTrait#/s:15GoogleHomeTypes0A0O14OpenCloseTraitV10identifierSSvpZ)


  ` The trait identifier.

  #### Declaration

  Swift

      static let identifier: String

- `


  ### [metadata](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google/OpenCloseTrait#/s:15GoogleHomeTypes0A0O14OpenCloseTraitV8metadata0aB3SDK0F8MetadataVvp)


  ` Metadata about this `Trait`.

  #### Declaration

  Swift

      let metadata: TraitMetadata

- `


  ### [attributes](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google/OpenCloseTrait#/s:15GoogleHomeTypes0A0O14OpenCloseTraitV10attributesAE10AttributesVvp)


  ` List of attributes for the `OpenCloseTrait`.

  #### Declaration

  Swift

      let attributes: https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google.html.OpenCloseTrait.https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google/OpenCloseTrait/Attributes.html

- `


  ### [init(decoder:interactionProxy:metadata:)](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google/OpenCloseTrait#/s:15GoogleHomeTypes0A0O14OpenCloseTraitV7decoder16interactionProxy8metadataAE0aB3SDK0F7DecoderV_AI011InteractionI0_pSgAI0F8MetadataVtKcfc)


  ` 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. |

- `


  ### [encode(with:)](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google/OpenCloseTrait#/s:15GoogleHomeTypes0A0O14OpenCloseTraitV6encode4withy0aB3SDK0F7EncoderC_tKF)


  ` 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

- `


  ### [forceRead()](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google/OpenCloseTrait#/s:15GoogleHomeTypes0A0O14OpenCloseTraitV9forceReadyyYaKF)


  ` 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 `HomeError`s thrown by this call.

  #### Declaration

  Swift

      func forceRead() async throws

- `


  ### [Attributes](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google/OpenCloseTrait/Attributes.html)


  ` Attributes for the `https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google/OpenCloseTrait.html`.

  #### Declaration

  Swift

      struct Attributes

- `


  ### [==(_:_:)](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google/OpenCloseTrait#/s:15GoogleHomeTypes0A0O14OpenCloseTraitV2eeoiySbAE_AEtFZ)


  ` 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: https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google.html.OpenCloseTrait, rhs: https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google.html.OpenCloseTrait) -> Bool

  #### Parameters

  |---|---|
  | ` lhs ` | A value to compare. |
  | ` rhs ` | Another value to compare. |

- `


  ### [hash(into:)](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google/OpenCloseTrait#/s:15GoogleHomeTypes0A0O14OpenCloseTraitV4hash4intoys6HasherVz_tF)


  ` 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)

- `


  ### [DirectionOpenState](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google/OpenCloseTrait/DirectionOpenState.html)


  ` Current state for the given open direction.

  #### Declaration

  Swift

      struct DirectionOpenState

- `


  ### [OpenFollowUpEvent](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google/OpenCloseTrait/OpenFollowUpEvent.html)


  ` Follow up response for the `open` command.

  #### Declaration

  Swift

      struct OpenFollowUpEvent

- `


  ### [CloseFollowUpEvent](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google/OpenCloseTrait/CloseFollowUpEvent.html)


  ` Follow up response for the `close` command.

  #### Declaration

  Swift

      struct CloseFollowUpEvent

- `


  ### [GoToOpenPercentageFollowUpEvent](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google/OpenCloseTrait/GoToOpenPercentageFollowUpEvent.html)


  ` Follow up response for the `goToOpenPercentage` command.

  #### Declaration

  Swift

      struct GoToOpenPercentageFollowUpEvent

- `


  ### [supportsOpenCommand](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google/OpenCloseTrait#/s:15GoogleHomeTypes0A0O14OpenCloseTraitV08supportsD7CommandSbvp)


  ` Whether the device supports the `open` command for this trait.

  #### Declaration

  Swift

      var supportsOpenCommand: Bool { get }

- `


  ### [open(openDirection:)](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google/OpenCloseTrait#/s:15GoogleHomeTypes0A0O14OpenCloseTraitV4open0G9DirectionyAE0H0O_tYaKF)


  ` Fully open the device.

  #### Declaration

  Swift

      func open(openDirection: https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google.html.OpenCloseTrait.https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google/OpenCloseTrait/Direction.html) async throws

  #### Parameters

  |---|---|
  | ` openDirection ` | The direction in which to open. Only present if the device supports multiple directions, as indicated by the `OpenCloseTrait/Attributes/openDirection` attribute, and a direction is specified by the user. |

- `


  ### [openBatchable(openDirection:)](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google/OpenCloseTrait#/s:15GoogleHomeTypes0A0O14OpenCloseTraitV13openBatchable0G9Direction0aB3SDK0H7CommandVyytGAE0I0O_tKF)


  ` The batchable version of open command above.
  See also
  open

  #### Declaration

  Swift

      func openBatchable(openDirection: https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google.html.OpenCloseTrait.https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google/OpenCloseTrait/Direction.html) throws -> BatchableCommand<Void>

- `


  ### [supportsCloseCommand](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google/OpenCloseTrait#/s:15GoogleHomeTypes0A0O14OpenCloseTraitV08supportsE7CommandSbvp)


  ` Whether the device supports the `close` command for this trait.

  #### Declaration

  Swift

      var supportsCloseCommand: Bool { get }

- `


  ### [close()](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google/OpenCloseTrait#/s:15GoogleHomeTypes0A0O14OpenCloseTraitV5closeyyYaKF)


  ` Fully close the device.

  #### Declaration

  Swift

      func close() async throws

- `


  ### [closeBatchable()](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google/OpenCloseTrait#/s:15GoogleHomeTypes0A0O14OpenCloseTraitV14closeBatchable0aB3SDK0H7CommandVyytGyKF)


  ` The batchable version of close command above.
  See also
  close

  #### Declaration

  Swift

      func closeBatchable() throws -> BatchableCommand<Void>

- `


  ### [supportsGoToOpenPercentageCommand](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google/OpenCloseTrait#/s:15GoogleHomeTypes0A0O14OpenCloseTraitV012supportsGoToD17PercentageCommandSbvp)


  ` Whether the device supports the `goToOpenPercentage` command for this trait.

  #### Declaration

  Swift

      var supportsGoToOpenPercentageCommand: Bool { get }

- `


  ### [goToOpenPercentage(openPercent:openDirection:)](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google/OpenCloseTrait#/s:15GoogleHomeTypes0A0O14OpenCloseTraitV04goToD10Percentage11openPercent0J9DirectionySd_AE0L0OtYaKF)


  ` Open the device to a specific percentage, where 0 is closed and 100 is fully open.

  #### Declaration

  Swift

      func goToOpenPercentage(openPercent: Float64, openDirection: https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google.html.OpenCloseTrait.https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google/OpenCloseTrait/Direction.html) async throws

  #### Parameters

  |---|---|
  | ` openPercent ` | Indicates the percentage that a device should be opened, where 0 is closed and 100 is fully open. |
  | ` openDirection ` | The direction in which to open. Only present if the device supports multiple directions, as indicated by the `OpenCloseTrait/Attributes/openDirection` attribute, and a direction is specified by the user. |

- `


  ### [goToOpenPercentageBatchable(openPercent:openDirection:)](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google/OpenCloseTrait#/s:15GoogleHomeTypes0A0O14OpenCloseTraitV04goToD19PercentageBatchable11openPercent0K9Direction0aB3SDK0J7CommandVyytGSd_AE0M0OtKF)


  ` The batchable version of goToOpenPercentage command above.
  See also
  goToOpenPercentage

  #### Declaration

  Swift

      func goToOpenPercentageBatchable(openPercent: Float64, openDirection: https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google.html.OpenCloseTrait.https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google/OpenCloseTrait/Direction.html) throws -> BatchableCommand<Void>

- `


  ### [supportsStepCommand](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google/OpenCloseTrait#/s:15GoogleHomeTypes0A0O14OpenCloseTraitV19supportsStepCommandSbvp)


  ` Whether the device supports the `step` command for this trait.

  #### Declaration

  Swift

      var supportsStepCommand: Bool { get }

- `


  ### [step(openRelativePercent:openDirection:)](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google/OpenCloseTrait#/s:15GoogleHomeTypes0A0O14OpenCloseTraitV4step19openRelativePercent0H9DirectionySd_AE0K0OtYaKF)


  ` Adjust the open-close state of the device relative to the current state.

  #### Declaration

  Swift

      func step(openRelativePercent: Float64, openDirection: https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google.html.OpenCloseTrait.https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google/OpenCloseTrait/Direction.html) async throws

  #### Parameters

  |---|---|
  | ` openRelativePercent ` | The exact percentage to change open-close state. |
  | ` openDirection ` | The direction in which to open. Only present if the device supports multiple directions, as indicated by the `OpenCloseTrait/Attributes/openDirection` attribute, and a direction is specified by the user. |

- `


  ### [stepBatchable(openRelativePercent:openDirection:)](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google/OpenCloseTrait#/s:15GoogleHomeTypes0A0O14OpenCloseTraitV13stepBatchable19openRelativePercent0I9Direction0aB3SDK0H7CommandVyytGSd_AE0L0OtKF)


  ` The batchable version of step command above.
  See also
  step

  #### Declaration

  Swift

      func stepBatchable(openRelativePercent: Float64, openDirection: https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google.html.OpenCloseTrait.https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google/OpenCloseTrait/Direction.html) throws -> BatchableCommand<Void>

- `


  ### [Direction](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google/OpenCloseTrait/Direction.html)


  ` Direction in which the device is opened.

  #### Declaration

  Swift

      enum Direction

- `


  ### [OpenCloseFeature](https://developers.home.google.com/reference/swift/GoogleHomeTypes/Enums/Google/OpenCloseTrait/OpenCloseFeature.html)


  ` OpenClose trait FeatureMap.

  #### Declaration

  Swift

      struct OpenCloseFeature