Key Value API

Key Value API는 기기, 방, 자동화 객체를 위한 새로운 맞춤 데이터 관리 API를 제공합니다. 커스텀 데이터의 수명 주기는 연결된 객체의 수명 주기로 엄격하게 범위가 지정됩니다. 예를 들어 방 객체와 연결된 맞춤 데이터('루시의 방' 등)는 방 객체와 함께 자동으로 삭제, 이동 또는 전송 (구조 간)됩니다.

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 문자열이어야 하며 최대 길이는 1, 024자입니다. 값은 빈 문자열일 수 있습니다.
  • 각 객체에는 키-값 쌍이 10개 행까지 포함될 수 있습니다.