Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions drivers/SmartThings/zigbee-switch/fingerprints.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2369,6 +2369,11 @@ zigbeeManufacturer:
manufacturer: LAISIAO
model: yuba
deviceProfileName: switch-smart-bath-heater-laisiao
- id: "JNL/Y-K003-001"
deviceLabel: Yanmi Switch (3 Way) 1
manufacturer: JNL
model: Y-K003-001
deviceProfileName: basic-switch
zigbeeGeneric:
- id: "genericSwitch"
deviceLabel: Zigbee Switch
Expand Down
84 changes: 84 additions & 0 deletions drivers/SmartThings/zigbee-switch/src/Yanmi/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
-- Copyright 2025 SmartThings
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.

local stDevice = require "st.device"
local configurations = require "configurations"


local FINGERPRINTS = {
{ mfr = "JNL", model = "Y-K003-001", switches = 3 }
}

local function can_handle_Yanmi(opts, driver, device, ...)
for _, fingerprint in ipairs(FINGERPRINTS) do
if device:get_manufacturer() == fingerprint.mfr and device:get_model() == fingerprint.model then
local subdriver = require("Yanmi")
return true, subdriver
end
end
return false
end

local function get_children_info(device)
for _, fingerprint in ipairs(FINGERPRINTS) do
if device:get_model() == fingerprint.model then
return fingerprint.switches
end
end
end

local function find_child(parent, ep_id)
return parent:get_child_by_parent_assigned_key(string.format("%02X", ep_id))
end

local function create_child_devices(driver, device)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How many zigbee endpoints that support the On/Off cluster does this device have? It may be that you do not need a sub-driver at all, because of how the base driver handles this case: https://github.com/SmartThingsCommunity/SmartThingsEdgeDrivers/blob/main/drivers/SmartThings/zigbee-switch/src/init.lua#L104

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, this switch has 3 endpoints. In the future, there will be 2-key and 1-key switches that will use this driver.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as long as the zigbee endpoints report support for the On/Off cluster, they should still work with the base driver

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the labels generated by the base driver are not what I want.I hope that the endpoint of the switch will generate labels 1, 2, and 3 in sequence.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The label of the first endpoint of this driver is 2, not 1.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But your base device's label is Yanmi Switch (3 Way) 1.multi-switch-no-master would create, Yanmi Switch (3 Way) 2 and Yanmi Switch (3 Way) 3 alongside the already existing Yanmi Switch (3 Way) 1. Am I misunderstanding? The code looks identical to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a real device to the hub to test the multi-switch-no-master driver, and found that it was not like what you described.The label of the first endpoint of this driver is 2.Next are 3 and 4.

local switch_amount = get_children_info(device)
local base_name = string.sub(device.label, 0, -2)
-- Create Switch 2-3
for i = 2, switch_amount, 1 do
if find_child(device, i) == nil then
local metadata = {
type = "EDGE_CHILD",
parent_assigned_child_key = string.format("%02X", i),
label = base_name .. i,
profile = "basic-switch",
parent_device_id = device.id,
vendor_provided_label = base_name .. i,
}
driver:try_create_device(metadata)
end
end
device:refresh()
end

local function device_added(driver, device)
if device.network_type ~= stDevice.NETWORK_TYPE_CHILD then
create_child_devices(driver, device)
end
end

local function device_init(driver, device, event)
device:set_find_child(find_child)
end

local Yanmi_switch = {
NAME = "Zigbee Yanmi Switch",
lifecycle_handlers = {
added = device_added,
init = configurations.power_reconfig_wrapper(device_init)
},
can_handle = can_handle_Yanmi
}

return Yanmi_switch
3 changes: 2 additions & 1 deletion drivers/SmartThings/zigbee-switch/src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ local zigbee_switch_driver_template = {
lazy_load_if_possible("inovelli-vzm31-sn"),
lazy_load_if_possible("laisiao"),
lazy_load_if_possible("tuya-multi"),
lazy_load_if_possible("frient")
lazy_load_if_possible("frient"),
lazy_load_if_possible("Yanmi")
},
zigbee_handlers = {
global = {
Expand Down
Loading
Loading