Key Value API

키-값 API는 기기, 방, 자동화 객체를 위한 새로운 맞춤 데이터 관리 API를 제공합니다. 맞춤 데이터의 수명 주기는 연결된 객체의 수명 주기로 엄격하게 범위가 지정됩니다. 예를 들어 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)

객실 예시

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 문자로 구성된 문자열이어야 하며 최대 길이는 1024입니다. 값은 빈 문자열일 수 있습니다.
  • 각 객체에는 10개의 키-값 쌍 행이 있을 수 있습니다.