-
Notifications
You must be signed in to change notification settings - Fork 531
Expand file tree
/
Copy pathinit.lua
More file actions
executable file
·61 lines (52 loc) · 1.88 KB
/
init.lua
File metadata and controls
executable file
·61 lines (52 loc) · 1.88 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
-- Copyright 2025 SmartThings, Inc.
-- Licensed under the Apache License, Version 2.0
local capabilities = require "st.capabilities"
local zcl_clusters = require "st.zigbee.zcl.clusters"
local configurations = require "configurations"
local function component_to_endpoint(device, component_id)
if component_id == "main" then
return device.fingerprinted_endpoint_id
else
local ep_num = component_id:match("switch(%d)")
return ep_num and tonumber(ep_num) or device.fingerprinted_endpoint_id
end
end
local function endpoint_to_component(device, ep)
if ep == device.fingerprinted_endpoint_id then
return "main"
else
return string.format("switch%d", ep)
end
end
local device_init = function(self, device)
device:set_component_to_endpoint_fn(component_to_endpoint)
device:set_endpoint_to_component_fn(endpoint_to_component)
end
local function on_handler(driver, device, command)
local attr = capabilities.switch.switch
if command.component == "main" then
-- The main component is set to on by the device and cannot be set to on itself. It can only trigger off
device:emit_event_for_endpoint(device.fingerprinted_endpoint_id, attr.on())
device.thread:call_with_delay(1, function(d)
device:emit_event_for_endpoint(device.fingerprinted_endpoint_id, attr.off())
end)
else
device:send_to_component(command.component, zcl_clusters.OnOff.server.commands.On(device))
end
end
local laisiao_bath_heater = {
NAME = "Zigbee Laisiao Bathroom Heater",
supported_capabilities = {
capabilities.switch,
},
lifecycle_handlers = {
init = configurations.reconfig_wrapper(device_init),
},
capability_handlers = {
[capabilities.switch.ID] = {
[capabilities.switch.commands.on.NAME] = on_handler
}
},
can_handle = require("laisiao.can_handle"),
}
return laisiao_bath_heater