Thiết bị chiếu sáng sử dụng các đặc điểm Matter tiêu chuẩn để xác định thiết bị cố định, bật/tắt trạng thái nguồn và điều chỉnh mức độ sáng.
Loại thiết bị đèn cơ bản nhất là
OnOffLight
được triển khai bằng các đặc điểm
OnOff và
Identify
và có thể hỗ trợ đặc điểm
LevelControl
và đặc điểm
LightEffects.
Các loại đèn khác cung cấp thêm chức năng và được triển khai bằng các đặc điểm khác:
| Loại thiết bị Home API | Đặc điểm | Ứng dụng mẫu Kotlin | Trường hợp sử dụng |
|---|---|---|---|
|
Đèn nhiệt độ màu
Thiết bị chiếu sáng có thể bật hoặc tắt, điều chỉnh cường độ ánh sáng và điều chỉnh nhiệt độ màu. |
Đặc điểm bắt buộc matter Identify matter OnOff matter LevelControl matter ColorControl |
bật và tắt, độ sáng |
Sáng |
|
Đèn có thể điều chỉnh độ sáng
Thiết bị chiếu sáng có thể bật hoặc tắt, điều chỉnh cường độ ánh sáng và chuyển đổi bằng cảm biến phát hiện người trong nhà được liên kết. |
Đặc điểm bắt buộc matter Xác định matter OnOff matter LevelControl |
bật và tắt, độ sáng |
Sáng |
|
Đèn màu mở rộng
Thiết bị chiếu sáng có thể bật hoặc tắt, điều chỉnh cường độ ánh sáng, điều chỉnh nhiệt độ màu và chuyển đổi bằng cảm biến phát hiện người trong nhà được liên kết. |
Đặc điểm bắt buộc matter Identify matter OnOff matter LevelControl matter ColorControl |
bật và tắt, độ sáng |
Sáng |
|
Bật/tắt đèn
Thiết bị chiếu sáng có thể bật hoặc tắt. |
Đặc điểm bắt buộc matter Xác định matter OnOff |
bật và tắt, độ sáng |
Sáng |
Luôn kiểm tra khả năng hỗ trợ thuộc tính và lệnh cho một thiết bị trước khi sử dụng bất kỳ tính năng nào hoặc cố gắng cập nhật thuộc tính. Hãy xem bài viết Điều khiển thiết bị trên Android để biết thêm thông tin.
Điều kiện tiên quyết
Trước khi làm việc với thiết bị chiếu sáng và đường cong chiếu sáng, hãy đảm bảo ứng dụng của bạn khởi chạy Home SDK và bao gồm các lệnh nhập bắt buộc:
import com.google.home.HomeDevice import com.google.home.Structure import com.google.home.google.DayOfWeek import com.google.home.google.ExtendedColorControl import com.google.home.google.ExtendedColorControlTrait import com.google.home.google.LightingCurve import com.google.home.google.LightingCurveTrait import com.google.home.matter.standard.ColorControl import com.google.home.matter.standard.ColorControlTrait import com.google.home.matter.standard.ColorTemperatureLightDevice import com.google.home.matter.standard.DimmableLightDevice import com.google.home.matter.standard.ExtendedColorLightDevice import com.google.home.matter.standard.GeneralDiagnostics import com.google.home.matter.standard.Identify import com.google.home.matter.standard.IdentifyTrait import com.google.home.matter.standard.LevelControl import com.google.home.matter.standard.LevelControlTrait import com.google.home.matter.standard.OnOff import com.google.home.matter.standard.OnOffLightDevice import com.google.home.matter.standard.OnOffTrait import com.google.home.matter.standard.RootNodeDevice import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.firstOrNull
Tìm thiết bị chiếu sáng
Để tìm thiết bị chiếu sáng trong một công trình, hãy lọc danh sách thiết bị theo loại thiết bị, chẳng hạn như OnOffLightDevice và DimmableLightDevice.
// Get all On/Off Light devices in the structure val onOffLights: List<HomeDevice> = home.devices().list().filter { it.has(OnOffLightDevice) } // Get all Dimmable Light devices in the structure val dimmableLights: List<HomeDevice> = home.devices().list().filter { it.has(DimmableLightDevice) } // Retrieve a specific device type instance to access its traits val onOffLightDevice: OnOffLightDevice? = onOffLights.firstOrNull()?.type(OnOffLightDevice)?.firstOrNull() val dimmableLightDevice: DimmableLightDevice? = dimmableLights.firstOrNull()?.type(DimmableLightDevice)?.firstOrNull()
Bạn cũng có thể truy xuất tất cả thiết bị chiếu sáng trên nhiều loại thiết bị chiếu sáng trong một bộ lọc:
// Get a list of devices with similar device types (lights) val lightDevices = home.devices().map { devices -> devices.filter { it.has(DimmableLightDevice) || it.has(OnOffLightDevice) || it.has(ColorTemperatureLightDevice) || it.has(ExtendedColorLightDevice) } }
Xem thông tin cơ bản về thiết bị
Được triển khai trong Ứng dụng mẫu cho Android
Đặc điểm BasicInformation bao gồm các thông tin như tên nhà cung cấp, mã nhà cung cấp, mã sản phẩm, tên sản phẩm (bao gồm cả thông tin về kiểu máy) và phiên bản phần mềm của thiết bị:
// Get device basic information. All general information traits are on the RootNodeDevice type. device.type(RootNodeDevice).first().standardTraits.basicInformation?.let { basicInformation -> println("vendorName ${basicInformation.vendorName}") println("vendorId ${basicInformation.vendorId}") println("productId ${basicInformation.productId}") println("productName ${basicInformation.productName}") println("softwareVersion ${basicInformation.softwareVersion}") }
Xác định thiết bị chiếu sáng
Khi một phòng có nhiều đèn, bạn có thể giúp người dùng xác định vị trí của một thiết bị cố định cụ thể bằng cách kích hoạt trạng thái nhận dạng hình ảnh, chẳng hạn như nhấp nháy đèn trong vài giây. Cả 4 loại thiết bị đèn đều yêu cầu đặc điểm Identify.
Gọi lệnh identify với thời lượng identifyTime tính bằng giây để bắt đầu trạng thái nhận dạng. Việc truyền 0 sẽ dừng trạng thái nhận dạng ngay lập tức. Bạn cũng có thể gọi triggerEffect để chạy một hiệu ứng hình ảnh cụ thể, chẳng hạn như Blink hoặc Breathe.
suspend fun identifyLight(lightDevice: DimmableLightDevice) {
val identifyTrait = lightDevice.standardTraits.identify ?: return
// Blink the light for 10 seconds so the user can locate it
if (identifyTrait.supports(Identify.Command.Identify)) {
identifyTrait.identify(identifyTime = 10u)
}
// Or trigger a specific visual identification effect
if (identifyTrait.supports(Identify.Command.TriggerEffect)) {
identifyTrait.triggerEffect(
effectIdentifier = IdentifyTrait.EffectIdentifierEnum.Blink,
effectVariant = IdentifyTrait.EffectVariantEnum.Default
)
}
}
Kiểm tra khả năng kết nối của thiết bị chiếu sáng
Khả năng kết nối của một thiết bị thực sự được kiểm tra ở cấp loại thiết bị vì một số thiết bị hỗ trợ nhiều loại thiết bị. Trạng thái được trả về là sự kết hợp của các trạng thái kết nối cho tất cả các đặc điểm trên thiết bị đó.
let lightConnectivity = dimmableLightDeviceType.metadata.sourceConnectivity .connectivityState
Bạn có thể thấy trạng thái partiallyOnline trong trường hợp có nhiều loại thiết bị
khi không có kết nối Internet. Các đặc điểm tiêu chuẩn của Matter vẫn có thể hoạt động trực tuyến nhờ tính năng định tuyến cục bộ, nhưng các đặc điểm dựa trên đám mây sẽ không hoạt động.
Lấy địa chỉ IP của thiết bị
Để tìm địa chỉ IP của thiết bị, hãy sử dụng thuộc tính networkInterfaces của GeneralDiagnosticsTrait.
Địa chỉ được trả về dưới dạng đối tượng Data. Bạn có thể định dạng các đối tượng này thành chuỗi IPv4 hoặc IPv6 chuẩn bằng khung Network:
func getIpAddresses(trait: Matter.GeneralDiagnosticsTrait) -> [String] {
let interfaces = trait.attributes.networkInterfaces ?? []
var ipAddresses: [String] = []
for interface in interfaces {
for data in interface.iPv4Addresses {
if let ipv4 = IPv4Address(data) {
ipAddresses.append(String(describing: ipv4))
}
}
for data in interface.iPv6Addresses {
if let ipv6 = IPv6Address(data) {
ipAddresses.append(String(describing: ipv6))
}
}
}
return ipAddresses
}
Điều khiển thiết bị chiếu sáng
Các loại thiết bị OnOffLight và DimmableLight sử dụng các đặc điểm Matter tiêu chuẩn để xác định thiết bị cố định, bật/tắt trạng thái nguồn và điều chỉnh mức độ sáng.
Bật hoặc tắt đèn
Sử dụng đặc điểm OnOff để đọc trạng thái nguồn hiện tại của OnOffLight hoặc DimmableLight và để bật hoặc tắt đèn.
Trước khi đọc thuộc tính onOff, hãy xác minh rằng thiết bị có hỗ trợ thuộc tính này. Một số thiết bị hoạt động dưới dạng điểm cuối chỉ có lệnh và không báo cáo trạng thái.
// Check if the OnOff trait supports the onOff attribute. if (onOffTrait.supports(OnOff.Attribute.onOff)) { println("onOffTrait supports onOff state") } else { println("onOffTrait is for a command only device!") }
Khi onOff là true, đèn sẽ bật. Khi onOff là false, đèn sẽ tắt.
Để thay đổi trạng thái nguồn của đèn, hãy xác minh rằng đặc điểm đó hỗ trợ lệnh dự kiến, sau đó gọi on(), off() hoặc toggle().
// Check if the OnOff trait supports the toggle command. if (onOffTrait.supports(OnOff.Command.Toggle)) { println("onOffTrait supports toggle command") } else { println("onOffTrait does not support stateful toggle command") }
// Calling a command on a trait. try { onOffTrait.toggle() } catch (e: HomeException) { // Code for handling the exception }
Bạn cũng có thể gọi trực tiếp on() và off() để đặt trạng thái rõ ràng:
onOffTrait.off() onOffTrait.on()
Để tắt đèn bằng hiệu ứng chuyển đổi hình ảnh dần dần, hãy gọi offWithEffect() và chỉ định giá trị EffectIdentifierEnum:
// Turn off the light using the DyingLight effect. onOffTrait.offWithEffect( effectIdentifier = OnOffTrait.EffectIdentifierEnum.DyingLight, effectVariant = 0u, )
Điều chỉnh độ sáng
DimmableLight cần có đặc điểm LevelControl và OnOffLight có thể tuỳ ý hỗ trợ đặc điểm này. Sử dụng đặc điểm này để đọc và kiểm soát mức độ sáng của đèn.
Thuộc tính currentLevel báo cáo mức độ sáng hiện tại theo thang điểm từ 0 đến 254. Bạn cũng có thể kiểm tra minLevel và maxLevel để xác định
phạm vi độ sáng hợp lệ mà phần cứng hỗ trợ.
Để đặt độ sáng thành một giá trị cụ thể, hãy gọi moveToLevel(). Xin lưu ý rằng moveToLevel() chỉ thay đổi mức hiện tại khi đèn đã bật, trừ phi bạn định cấu hình optionsOverride bằng executeIfOff. Để tự động bật đèn khi đặt mức độ sáng khác 0 (hoặc tắt đèn khi đặt mức độ sáng ở mức tối thiểu), hãy sử dụng moveToLevelWithOnOff().
// Change the brightness of the light to 50% levelControlTrait.moveToLevel( level = 127u.toUByte(), transitionTime = null, optionsMask = LevelControlTrait.OptionsBitmap(), optionsOverride = LevelControlTrait.OptionsBitmap(), )
Ví dụ sau đây đọc mức độ sáng hiện tại và sử dụng moveToLevelWithOnOff() để đặt đèn có thể điều chỉnh độ sáng thành 75% độ sáng (190u) trong quá trình chuyển đổi 1 giây (10u phần mười giây):
suspend fun setLightBrightness(lightDevice: DimmableLightDevice) { val levelControl = lightDevice.standardTraits.levelControl ?: return // Read the current brightness level (0 to 254) val currentLevel: UByte? = levelControl.currentLevel println("Current brightness level: $currentLevel") // Move to ~75% brightness (190 out of 254) and turn on the light if it is off if (levelControl.supports(LevelControl.Command.MoveToLevelWithOnOff)) { levelControl.moveToLevelWithOnOff( level = 190u, transitionTime = 10u, optionsMask = LevelControlTrait.OptionsBitmap(), optionsOverride = LevelControlTrait.OptionsBitmap() ) } }
Bạn cũng có thể tăng hoặc giảm độ sáng tương ứng với mức hiện tại bằng cách gọi stepWithOnOff() bằng StepModeEnum.Up hoặc StepModeEnum.Down và stepSize.
Màu của thành phần điều khiển
Đặc điểmColorControl có trên cả ColorTemperatureLightDevice và ExtendedColorLightDevice.
Đặc điểm này cho phép bạn điều chỉnh nhiệt độ màu theo độ nghịch đảo vi mô hoặc mired.
val colorControlTrait = colorTempLightDevice.standardTraits.colorControl ?: return // Read the current color temperature and hardware limits in mireds // (Mireds = 1,000,000 / Kelvin; e.g., 370 mireds ≈ 2700K warm white, 250 mireds = 4000K cool white) val currentMireds = colorControlTrait.colorTemperatureMireds val minMireds = colorControlTrait.colorTempPhysicalMinMireds ?: 153u // ~6500K (coolest) val maxMireds = colorControlTrait.colorTempPhysicalMaxMireds ?: 500u // 2000K (warmest) // Clamp target (370 mireds ≈ 2700K) to the device's physical bounds val targetMireds = 370u.toUShort().coerceIn(minMireds, maxMireds) if ( colorControlTrait.supports( ColorControl.Command.MoveToColorTemperature ) ) { colorControlTrait.moveToColorTemperature( colorTemperatureMireds = targetMireds, transitionTime = 20u, // 2.0 seconds (in 0.1s units) optionsMask = ColorControlTrait.OptionsBitmap(), optionsOverride = ColorControlTrait.OptionsBitmap() ) }
Bạn cũng có thể đặt màu bằng cách sử dụng toạ độ sắc độ CIE 1931 và giá trị sắc độ cũng như độ bão hoà 16 bit.
val colorControlTrait = extendedColorLightDevice.standardTraits.colorControl ?: return // 1. Move to CIE 1931 xy chromaticity coordinates (scaled 0..65279) // Example: x = 0.3127 (20493), y = 0.3290 (21561) for D65 white point if (colorControlTrait.supports(ColorControl.Command.MoveToColor)) { colorControlTrait.moveToColor( colorX = 20493u, colorY = 21561u, transitionTime = 10u, // 1.0 second (in 0.1s units) optionsMask = ColorControlTrait.OptionsBitmap(), optionsOverride = ColorControlTrait.OptionsBitmap() ) } val currentX = colorControlTrait.currentX val currentY = colorControlTrait.currentY // 2. Move to 16-bit Enhanced Hue (0..65534) and 8-bit Saturation (0..254) if ( colorControlTrait.supports( ColorControl.Command.EnhancedMoveToHueAndSaturation ) ) { colorControlTrait.enhancedMoveToHueAndSaturation( enhancedHue = 43690u, // ~240° (Blue) on the 0..65534 scale saturation = 254u, // Full saturation transitionTime = 15u, // 1.5 seconds (in 0.1s units) optionsMask = ColorControlTrait.OptionsBitmap(), optionsOverride = ColorControlTrait.OptionsBitmap() ) } // 3. Start a hardware color loop across the device's hue range if (colorControlTrait.supports(ColorControl.Command.ColorLoopSet)) { colorControlTrait.colorLoopSet( updateFlags = ColorControlTrait.UpdateFlagsBitmap( updateAction = true, updateDirection = true, updateTime = true, updateStartHue = true ), action = ColorControlTrait.ColorLoopActionEnum .ActivateFromColorLoopStartEnhancedHue, direction = ColorControlTrait.ColorLoopDirectionEnum.Increment, time = 30u, // 30 seconds per full cycle startHue = 0u, optionsMask = ColorControlTrait.OptionsBitmap(), optionsOverride = ColorControlTrait.OptionsBitmap() ) }
ExtendedColorControl là một đặc điểm không bắt buộc của Google trên ExtendedColorLightDevice giúp đơn giản hoá việc kiểm soát màu bằng cách chấp nhận tên màu, giá trị RGB hoặc giá trị HSV dấu phẩy động hợp nhất kết hợp màu và độ sáng trong một đơn vị.
val extendedColorControlTrait = extendedColorLightDevice.googleTraits.extendedColorControl ?: return // 1. Set color by name if ( extendedColorControlTrait.supports( ExtendedColorControl.Command.MoveToColorName ) ) { extendedColorControlTrait.moveToColorName(colorName = "Lavender") } val currentColorName = extendedColorControlTrait.currentName // 2. Set color using 8-bit RGB values (0..255 per channel) // Automatically coordinates brightness (LevelControl) and color (ColorControl) if ( extendedColorControlTrait.supports( ExtendedColorControl.Command.MoveToColorRgb ) ) { extendedColorControlTrait.moveToColorRgb( red = 255u, green = 128u, blue = 0u ) } val currentRed = extendedColorControlTrait.currentRed val currentGreen = extendedColorControlTrait.currentGreen val currentBlue = extendedColorControlTrait.currentBlue // 3. Set color and brightness together using floating-point HSV // hue: 0.0f..360.0f, saturation: 0.0f..1.0f, value (brightness): 0.0f..1.0f if ( extendedColorControlTrait.supports( ExtendedColorControl.Command.MoveToColorHsv ) ) { extendedColorControlTrait.moveToColorHsv( hue = 210.0f, saturation = 0.85f, value = 0.75f ) } val currentHue = extendedColorControlTrait.currentHue val currentSaturation = extendedColorControlTrait.currentSaturation val currentValue = extendedColorControlTrait.currentValue
Quản lý đường cong ánh sáng
Đường cong chiếu sáng xác định một lịch biểu tự động giúp chuyển đổi mượt mà độ sáng và nhiệt độ màu (không bắt buộc) của đèn mục tiêu trong suốt cả ngày. Ví dụ: đường cong chiếu sáng có thể tăng dần độ sáng của đèn vào buổi sáng và giảm độ sáng xuống tông màu ấm hơn vào buổi tối. Các loại thiết bị chiếu sáng chỉ hỗ trợ độ sáng, chẳng hạn như Đèn có thể điều chỉnh độ sáng, sẽ tuân theo đường cong độ sáng và bỏ qua nhiệt độ màu.
Đặc điểm LightingCurve là một đặc điểm Google Home platform ở cấp cấu trúc. Bạn truy cập vào dịch vụ này
từ một thực thể Structure
thay vì từ một thiết bị chiếu sáng riêng lẻ.
Mỗi lịch biểu trên đặc điểm được biểu thị bằng một LightingCurveSetting, ghép nối một settingId duy nhất với một LightingCurveConfig. Bảng sau đây mô tả các trường cấu hình của LightingCurveConfig:
| Trường | Mô tả |
|---|---|
curvePointsList |
Một trình tự gồm ít nhất hai mục CurvePoint có thời gian riêng biệt. Mỗi điểm chỉ định một time (CurveTimeOfDay có hours từ 0 đến 23 và minutes từ 0 đến 59), một brightnessPercent (0 đến 100) và một colorTemperature không bắt buộc tính theo Kelvin. Nếu bạn chỉ định colorTemperature cho bất kỳ điểm nào, thì giá trị này phải là giá trị dương cho tất cả các điểm. |
roomId |
Mã nhận dạng của phòng mục tiêu (ví dụ: room@{uuid}). Áp dụng đường cong chiếu sáng cho đèn có thể điều chỉnh độ sáng và nhiệt độ màu tương thích trong phòng đó. Chỉ định roomId hoặc devices. |
devices |
Đối tượng TargetDevices chứa danh sách các mục nhập TargetDevice, mỗi mục nhập có một id thiết bị và mã nhận dạng type thiết bị (chẳng hạn như home.matter.0000.types.0101 cho DimmableLight hoặc home.matter.0000.types.010c cho ColorTemperatureLight). Hãy chỉ định devices hoặc roomId. |
daysOfWeekList |
Các ngày trong tuần mà đường cong chiếu sáng chạy (DayOfWeek). Nếu danh sách trống, đường cong chiếu sáng sẽ chạy hằng ngày. |
adaptive |
Giá trị boolean không bắt buộc cho biết liệu đường cong chiếu sáng có thích ứng hay không, tức là đèn mục tiêu sẽ tiếp tục mức đường cong hoạt động khi được bật trong phạm vi thời gian đặt lịch. Khi false, việc thay đổi đèn theo cách thủ công sẽ tách đèn khỏi đường cong chiếu sáng trong thời gian còn lại của ngày. Khi true, đèn đã tắt rồi bật lại trong phạm vi thời gian đặt lịch sẽ kết nối lại với đường cong chiếu sáng, khiến đèn tuân theo độ sáng và nhiệt độ màu hiện tại của đường cong, đồng thời tuân theo đường cong từ thời điểm đó. |
enabled |
Giá trị boolean không bắt buộc cho biết chế độ cài đặt đường cong ánh sáng có đang hoạt động hay không. Mặc định là true khi tạo chế độ cài đặt mới. Khi enabled bị bỏ qua trong lệnh cập nhật, trạng thái của enabled sẽ không thay đổi. |
Đọc chế độ cài đặt đường cong ánh sáng
Để kiểm tra các đường cong chiếu sáng được định cấu hình cho một cấu trúc, hãy truy xuất đặc điểm LightingCurve từ Structure và đọc thuộc tính lightingCurveSettingsList của đặc điểm đó.
suspend fun readLightingCurves(structure: Structure) {
val lightingCurve = structure.trait(LightingCurve).firstOrNull() ?: return
for (setting in lightingCurve.lightingCurveSettingsList) {
val settingId = setting.settingId
val config = setting.config
println("Setting ID: $settingId, enabled: ${config?.enabled}")
config?.curvePointsList?.forEach { point ->
println(
" Time: ${point.time?.hours}:${point.time?.minutes}, " +
"Brightness: ${point.brightnessPercent}%, " +
"ColorTemp: ${point.colorTemperature}K"
)
}
}
}
Tạo chế độ cài đặt đường cong chiếu sáng
Để tạo lịch biểu đường cong chiếu sáng mới trên một cấu trúc, hãy tạo một LightingCurveConfig có ít nhất hai mục CurvePoint, đèn mục tiêu (được chỉ định bằng roomId hoặc devices) và các ngày hoạt động trong tuần. Sau đó, hãy chuyển cấu hình đến createLightingCurveSetting(). Lệnh này trả về settingId duy nhất được chỉ định cho chế độ cài đặt đường cong ánh sáng mới.
Ví dụ sau đây tạo một đường cong chiếu sáng vào ngày trong tuần cho một phòng. Độ sáng tăng từ 30% ở nhiệt độ màu ấm 2700K lúc 7:00 sáng lên 80% ở nhiệt độ màu mát hơn 4000K lúc 9:00 sáng, sau đó giảm xuống 20% ở nhiệt độ màu rất ấm 2200K lúc 9:00 tối:
suspend fun createRoomLightingCurve(
structure: Structure,
targetRoomId: String
): String? {
val lightingCurve = structure.trait(LightingCurve).firstOrNull() ?: return null
val curvePoints = listOf(
LightingCurveTrait.CurvePoint(
time = LightingCurveTrait.CurveTimeOfDay(hours = 7, minutes = 0),
brightnessPercent = 30,
colorTemperature = 2700
),
LightingCurveTrait.CurvePoint(
time = LightingCurveTrait.CurveTimeOfDay(hours = 9, minutes = 0),
brightnessPercent = 80,
colorTemperature = 4000
),
LightingCurveTrait.CurvePoint(
time = LightingCurveTrait.CurveTimeOfDay(hours = 21, minutes = 0),
brightnessPercent = 20,
colorTemperature = 2200
)
)
val config = LightingCurveTrait.LightingCurveConfig(
curvePointsList = curvePoints,
roomId = targetRoomId,
daysOfWeekList = listOf(
DayOfWeek.MONDAY,
DayOfWeek.TUESDAY,
DayOfWeek.WEDNESDAY,
DayOfWeek.THURSDAY,
DayOfWeek.FRIDAY
),
adaptive = true,
enabled = true
)
// Returns the newly created settingId
return lightingCurve.createLightingCurveSetting(config = config)
}
Để nhắm đến các thiết bị chiếu sáng cụ thể thay vì toàn bộ phòng, hãy cung cấp tham số devices bằng LightingCurveTrait.TargetDevices:
val targetDevices = LightingCurveTrait.TargetDevices(
devicesList = listOf(
LightingCurveTrait.TargetDevice(
id = dimmableLight.id.id,
type = DimmableLightDevice.TYPE_ID
)
)
)
val deviceCurveConfig = LightingCurveTrait.LightingCurveConfig(
curvePointsList = curvePoints,
devices = targetDevices,
daysOfWeekList = listOf(DayOfWeek.SATURDAY, DayOfWeek.SUNDAY),
adaptive = true,
enabled = true
)
val settingId = lightingCurve.createLightingCurveSetting(
config = deviceCurveConfig
)
Cập nhật chế độ cài đặt đường cong chiếu sáng
Để sửa đổi đường cong chiếu sáng hiện có (chẳng hạn như thay đổi các điểm trên đường cong, cập nhật các ngày hoạt động trong tuần hoặc bật và tắt lịch biểu), hãy gọi updateLightingCurveSetting() bằng settingId mục tiêu và LightingCurveConfig đã cập nhật.
suspend fun updateLightingCurve(
structure: Structure,
settingId: String,
updatedConfig: LightingCurveTrait.LightingCurveConfig
) {
val lightingCurve = structure.trait(LightingCurve).firstOrNull() ?: return
lightingCurve.updateLightingCurveSetting(
settingId = settingId,
config = updatedConfig
)
}
Xoá chế độ cài đặt đường cong ánh sáng
Để xoá chế độ cài đặt đường cong ánh sáng khỏi một cấu trúc, hãy gọi deleteLightingCurveSetting() bằng settingId của chế độ cài đặt mà bạn muốn xoá.
suspend fun deleteLightingCurve(
structure: Structure,
settingId: String
) {
val lightingCurve = structure.trait(LightingCurve).firstOrNull() ?: return
lightingCurve.deleteLightingCurveSetting(settingId = settingId)
}