Key Value API

Key Value API は、デバイス、部屋、自動化オブジェクト用の新しいカスタム データ管理 API を提供します。カスタム データのライフサイクルは、関連付けられているオブジェクトのライフサイクルに厳密にスコープ設定されます。たとえば、Room オブジェクトに関連付けられたカスタムデータ(「Lucy's room」など)は、Room オブジェクトとともに自動的に削除、移動、転送(構造間)されます。

Swift API の変更は CustomAppData コントローラを中心に行われ、カスタム アプリケーション データが属するオブジェクトの拡張機能を提供し、標準の作成、読み取り、更新、削除(CRUD)機能が含まれます。

デバイスの例

guard let device = home.devices.first(where: { $0.name == deviceName }) else { return }
var response = try await device.customAppData[key]
print("Before: \(response)")
try await device.customAppData.update(key: key, value: value)
response = try await device.customAppData[key]
print("After: \(response)")
try await device.customAppData.delete(key)

Room の例

guard let room = home.rooms.first(where: { $0.name == roomName }) else { return }
try await room.customAppData.update(key: "nickname", value: "Lucy's Room")
let response = try await room.customAppData["nickname"]
try await room.customAppData.delete("nickname")

自動化の例

guard let automation = home.automations.first(where: { $0.name == automationName }) else { return }
var response = try await automation.customAppData[key]
print("Before: \(response)")
try await automation.customAppData.update(key: key, value: value)
response = try await automation.customAppData[key]
print("After: \(response)")
try await automation.customAppData.delete(key)

制限事項

  • キーは、有効な UTF-8 文字の文字列で、最大長は 128 文字にする必要があります。キーは空の文字列にできます。
  • 値は、有効な UTF-8 文字の文字列にする必要があります。最大長は 1, 024 文字です。値は空の文字列にできます。
  • 各オブジェクトには、Key-Value ペアの行を 10 個まで含めることができます。