API Key Value

L'API Key Value fornisce nuove API di gestione dei dati personalizzati per gli oggetti Device, Room e Automation. Il ciclo di vita dei dati personalizzati è strettamente limitato al ciclo di vita dell'oggetto a cui sono associati. Ad esempio, i dati personalizzati (come "Stanza di Lucy") associati a un oggetto Room verranno eliminati, spostati o trasferiti automaticamente (tra le strutture) con l'oggetto Room.

La modifica dell'API Swift è incentrata sul CustomAppData controller e fornisce estensioni agli oggetti a cui appartengono i dati dell'applicazione personalizzata, incluse le funzioni standard di creazione, lettura, aggiornamento ed eliminazione (CRUD).

Esempio di dispositivo

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)

Esempio di stanza

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")

Esempio di automazione

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)

Restrizioni

  • La chiave deve essere una stringa di caratteri UTF-8 validi, con una lunghezza massima di 128. La chiave può essere una stringa vuota.
  • Il valore deve essere una stringa di caratteri UTF-8 validi, con una lunghezza massima di 1024. Il valore può essere una stringa vuota.
  • Ogni oggetto può avere 10 righe di coppie chiave-valore.