Otomatisasi yang dikelola aplikasi untuk iOS

Otomatisasi yang dikelola aplikasi adalah otomatisasi yang dibuat secara terprogram oleh aplikasi partner menggunakan Automation API.

Otomatisasi tersebut tidak akan muncul dalam daftar otomatisasi Google Home app (GHA).

Informasi yang ditulis ke feed aktivitas Home API saat otomatisasi yang dikelola aplikasi dipicu dapat disesuaikan, atau dihentikan sepenuhnya. Misalnya, jika partner menawarkan layanan bermerek bernama "Arktik" yang diterapkan menggunakan otomatisasi yang dikelola aplikasi, partner dapat menentukan bahwa saat otomatisasi yang dikelola aplikasi mereka berjalan, layanan Arktik dirujuk di feed aktivitas, bukan nama otomatisasi sebenarnya.

Membuat otomatisasi yang dikelola aplikasi

Untuk membuat otomatisasi yang dikelola aplikasi, gunakan prosedur berikut.

  1. Buat grafik logika otomatisasi.

  2. Opsional Jika Anda ingin aktivitas otomatisasi muncul di feed aktivitas, Anda dapat mengisi instance AppManagedAutomationConfig dengan pesan yang dilokalkan yang ingin Anda tampilkan di feed sebagai pengganti nama otomatisasi. Pesan ini dapat berupa nama aplikasi atau layanan yang dilokalkan, atau pesan lain yang Anda inginkan. Jika Anda tidak memberikan string yang dilokalkan, eksekusi otomatisasi dicatat seperti eksekusi otomatisasi lainnya. Google merekomendasikan agar Anda menyetel string yang dilokalkan ini untuk memastikan pengalaman pengguna terbaik.

    let automationConfig = AppManagedAutomationConfig(
        managingAppDisplayNames: [
          LocalizedText(text: "My Custom SmartApp", locale: "en-US"),
          LocalizedText(text: "Mi aplicación personalizada", locale: "es-MX")
        ]
    )
    
  3. Buat instance otomatisasi menggunakan Automation.Builder.

    1. Tetapkan name otomatisasi.
    2. Tetapkan client_feature_group ke "APP_MANAGED_EXECUTION_REPORTED" jika Anda ingin histori eksekusi otomatisasi muncul di tab Aktivitas di GHA, atau "APP_MANAGED_EXECUTION_UNREPORTED" jika Anda tidak ingin histori eksekusi otomatisasi muncul.
    3. Tetapkan automationGraph.
    4. Opsional Tetapkan appManagedAutomationConfig otomatisasi (lihat Langkah 2).
  4. Terakhir, panggil build() untuk membuat instance Automation.

Contoh ini menunjukkan seluruh prosedur:


import GoogleHomeSDK
import GoogleHomeTypes

let devices = try await home.devices().list()
let mySensor: HomeDevice = devices.first(where: {
    $0.types.contains(OccupancySensorDeviceType.self) &&
    $0.structureID == structure.id
})

let myLight: HomeDevice = devices.first(
  where: {
    $0.types.contains(OnOffLightDeviceType.self) &&
    $0.structureID == structure.id
  }
)

// 1. Create logic graph
let starterNode = StarterNode(
    device: mySensor,
    trait: Matter.OccupancySensingTrait.self
)

let actionNode = ActionNode(
    device: myLight,
    command: Matter.OnOffTrait.on()
)

// Bundle nodes into a sequential graph
let automationGraph = SequentialFlow(
    nodes: [starterNode, actionNode]
)

// 2. Build the AppManagedAutomationConfig with the localized app names
let automationConfig = AppManagedAutomationConfig(
    managingAppDisplayNames: [
      LocalizedText(text: "My Custom SmartApp", locale: "en-US"),
      LocalizedText(text: "Mi aplicación personalizada", locale: "es-MX")
    ]
)

// 3. Build the Automation with both configuration and the graph
let myFunctionalAutomation = try AutomationBuilder()
    .setName("Motion Activated Light")                         // a. Set the name
    .setClientFeatureGroup("APP_MANAGED_EXECUTION_UNREPORTED") // b. set the clientFeatureGroup
    .setAutomationGraph(automationGraph)                       // c. Attach the logic graph
    .setAppManagedAutomationConfig(automationConfig)           // d. Set the automationConfig
    .build() // 4. build the automation