Contents

HomeAccessorySettingsContainer

A snapshot of an accessory’s settings and their current values.

Declaration

@MainActor protocol HomeAccessorySettingsContainer

Overview

Create a type that adopts this protocol, with a property for each setting. Declare each property with one of the setting property wrappers: HomeAccessoryToggleSetting, HomeAccessoryRangeSetting, HomeAccessoryEnumSetting, HomeAccessoryTextFieldSetting, or HomeAccessoryInformationSetting. Each wrapper stores details such as the setting’s identifier and label.

List the settings’ projected values (with the $ prefix) in availableSettings, in the order you want them to appear. For example:

struct ThermostatSettings: HomeAccessorySettingsContainer {
    static let ecoModeID = "eco-mode"

    @HomeAccessoryToggleSetting(id: Self.ecoModeID, label: "Eco Mode")
    var ecoMode: Bool?

    var availableSettings: [any HomeAccessorySetting] { [$ecoMode] }

    init(ecoMode: Bool? = nil) { self.ecoMode = ecoMode }
}

Store identifiers as static constants so your provider can reuse them. Your provider should create a new container each time settings(context:for:) runs, rather than retaining one.

Topics

Listing the available settings

See Also

Displaying accessory configuration