אוטומציות שמנוהלות באפליקציה ל-iOS

אוטומציות שמנוהלות על ידי אפליקציות הן אוטומציות שנוצרות באופן פרוגרמטי על ידי אפליקציה של שותף באמצעות Automation API.

פעולות אוטומטיות כאלה לא מופיעות ברשימת הפעולות האוטומטיות של Google Home app (GHA).

אפשר להתאים אישית את המידע שנכתב בפיד הפעילות של Home APIs כשמופעלת פעולה אוטומטית שמנוהלת על ידי אפליקציה. לדוגמה, אם שותף מציע שירות ממותג בשם "Arctic" שמוטמע באמצעות פעולות אוטומטיות שמנוהלות על ידי אפליקציה, השותף יכול לציין שכאשר הפעולות האוטומטיות שמנוהלות על ידי אפליקציה פועלות, השירות Arctic יופיע בפיד הפעילות במקום השם של הפעולה האוטומטית בפועל.

יצירת פעולה אוטומטית שמנוהלת על ידי אפליקציה

כדי ליצור אוטומציה שמנוהלת על ידי אפליקציה, פועלים לפי ההוראות הבאות.

  1. יוצרים את תרשים הלוגיקה של האוטומציה.

  2. כדי להתאים אישית את האופן שבו הפעילות של האוטומציה מופיעה בפיד הפעילות, מאכלסים מופע של AppManagedAutomationConfig בהודעה המותאמת לשוק המקומי שרוצים שתופיע בפיד במקום שם האוטומציה. זה יכול להיות השם המקומי של אפליקציה או שירות, או כל הודעה אחרת שרוצים. אם לא תספקו מחרוזות מותאמות לשוק המקומי, הפעלות האוטומציה יתועדו ביומן כמו כל אוטומציה אחרת. ‫Google ממליצה להגדיר את המחרוזות המותאמות לשוק המקומי כדי להבטיח חוויית משתמש אופטימלית.

    let automationConfig = AppManagedAutomationConfig(
        managingAppDisplayNames: [
          LocalizedText(text: "My Custom SmartApp", locale: "en-US"),
          LocalizedText(text: "Mi aplicación personalizada", locale: "es-MX")
        ]
    )
    
  3. יוצרים את מופע האוטומציה באמצעות Automation.Builder.

    1. מגדירים את ה-name של הפעולה האוטומטית.
    2. מגדירים את client_feature_group לערך "APP_MANAGED_EXECUTION_REPORTED" כדי שהיסטוריית ההפעלה של האוטומציה תופיע בכרטיסייה "פעילות" ב-GHA.
    3. מגדירים את automationGraph.
    4. אופציונלי מגדירים את appManagedAutomationConfig של האוטומציה (ראו שלב 2).
  4. לבסוף, קוראים ל-build() כדי ליצור את המופע של Automation.

בדוגמה הזו מוצג התהליך המלא:


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_REPORTED")   // b. set the clientFeatureGroup
    .setAutomationGraph(automationGraph)                       // c. Attach the logic graph
    .setAppManagedAutomationConfig(automationConfig)           // d. Set the automationConfig
    .build() // 4. build the automation