-
Notifications
You must be signed in to change notification settings - Fork 531
Expand file tree
/
Copy pathinit.lua
More file actions
80 lines (65 loc) · 2.7 KB
/
init.lua
File metadata and controls
80 lines (65 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
-- Copyright 2025 SmartThings, Inc.
-- Licensed under the Apache License, Version 2.0
local clusters = require "st.zigbee.zcl.clusters"
local cluster_base = require "st.zigbee.cluster_base"
local data_types = require "st.zigbee.data_types"
local capabilities = require "st.capabilities"
local preferences = require "preferences"
local OnOff = clusters.OnOff
local Level = clusters.Level
local ColorControl = clusters.ColorControl
local PRIVATE_CLUSTER_ID = 0xFCC0
local PRIVATE_ATTRIBUTE_ID = 0x0009
local MFG_CODE = 0x115F
local function do_refresh(self, device)
device:send(OnOff.attributes.OnOff:read(device))
device:send(Level.attributes.CurrentLevel:read(device))
device:send(ColorControl.attributes.ColorTemperatureMireds:read(device))
end
local function emit_event_if_latest_state_missing(device, component, capability, attribute_name, value)
if device:get_latest_state(component, capability.ID, attribute_name) == nil then
device:emit_event(value)
end
end
local function device_added(driver, device, event)
device:send(cluster_base.write_manufacturer_specific_attribute(device,
PRIVATE_CLUSTER_ID, PRIVATE_ATTRIBUTE_ID, MFG_CODE, data_types.Uint8, 1)) -- private
local value = { minimum = 2700, maximum = 6000 }
if device:get_model() == "lumi.light.cwacn1" then
value.maximum = 6500
end
emit_event_if_latest_state_missing(device, "main", capabilities.colorTemperature, capabilities.colorTemperature.colorTemperatureRange.NAME, capabilities.colorTemperature.colorTemperatureRange(value))
end
local function do_configure(self, device)
device:configure()
preferences.sync_preferences(self, device)
device:send(ColorControl.commands.MoveToColorTemperature(device, 200, 0x0000))
do_refresh(self, device)
end
local function set_level_handler(driver, device, cmd)
local level = math.floor(cmd.args.level / 100.0 * 254)
local dimming_rate = 0x0000
device:send(Level.commands.MoveToLevelWithOnOff(device, level, dimming_rate))
end
local function init(self, device)
local value = { minimum = 2700, maximum = 6000 }
if device:get_model() == "lumi.light.cwacn1" then
value.maximum = 6500
end
emit_event_if_latest_state_missing(device, "main", capabilities.colorTemperature, capabilities.colorTemperature.colorTemperatureRange.NAME, capabilities.colorTemperature.colorTemperatureRange(value))
end
local aqara_light_handler = {
NAME = "Aqara Light Handler",
lifecycle_handlers = {
init = init,
added = device_added,
doConfigure = do_configure
},
capability_handlers = {
[capabilities.switchLevel.ID] = {
[capabilities.switchLevel.commands.setLevel.NAME] = set_level_handler
}
},
can_handle = require("aqara-light.can_handle"),
}
return aqara_light_handler