-
Notifications
You must be signed in to change notification settings - Fork 510
PIOT-252 add yanmi Y-K003-001 switch #2424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
thinkaName
wants to merge
1
commit into
SmartThingsCommunity:main
Choose a base branch
from
thinkaName:yanmi-Y-K00x-001
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+504
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe this meets your needs, then: https://github.com/SmartThingsCommunity/SmartThingsEdgeDrivers/blob/main/drivers/SmartThings/zigbee-switch/src/multi-switch-no-master/init.lua
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
andYanmi Switch (3 Way) 3
alongside the already existingYanmi Switch (3 Way) 1
. Am I misunderstanding? The code looks identical to me.There was a problem hiding this comment.
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.