HueEntertainmentSwift

一种与 Hue 娱乐 API 交互的方式。

用法

// Get a session
let session = HueSession()

// Find the IP of the bridge
try await session.findIP()

// Get a username, clientKey and appID to be used to create a streaming session.
// You'll want to save these values.
try await session.login(device: "YOURAPP#HERE")

// Load Entertainment Areas configured in the Hue app
let areas = try await session.areas()

// Get an area to stream to
guard let area = areas.first else { return }

// Start a streaming session for the area. This prevents other integrations
// from streaming as well.
try await session.start(area: area)

// Connect via DTLS to the bridge to enable UDP message streaming. Once called,
// you can send messages via `session.connection`
try session.connect()

// Turn on lights in the entertainment area. They'll get set randomly to the
// colors below. The `ramp` value determines how long it takes in seconds
session.on(colors: [Color.red, Color.green, Color.blue, Color.yellow], ramp: 2)

// Turn off lights in the entertainment area.
session.off()

// Stop the streaming session. Important to call this when you're done.
try await session.stop()

基本用法 可以在 Tests/ 目录的 testExample 中找到。

警告

使用本项目可能会对光敏性癫痫患者造成癫痫发作。如果您要运行示例,请务必小心