Key Value API

Key Value API は、デバイス、会議室、自動化オブジェクト用の新しいカスタム データ管理 API を提供します。カスタム データのライフサイクルは、関連付けられているオブジェクトのライフサイクルに厳密にスコープ設定されます。たとえば、会議室オブジェクトに関連付けられたカスタムデータ(「Lucy's 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)

ルームの例

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)

制限事項

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