WWSTCERT-10189 Ledvance zigbee meter plug#2729
WWSTCERT-10189 Ledvance zigbee meter plug#2729LQ107 wants to merge 18 commits intoSmartThingsCommunity:mainfrom
Conversation
| fingerprints: | ||
| - manufacturer: "LEDVANCE" | ||
| model: "PLUG COMPACT EU EM T" | ||
| deviceProfileName: "switch-power-energy" | ||
| id: "LEDVANCE/PLUG COMPACT EU EM T" | ||
| deviceLabel: "SMART ZIGBEE COMPACT OUTDOOR PLUG EU" No newline at end of file |
There was a problem hiding this comment.
please remove the changes to this file
drivers/SmartThings/zigbee-switch/src/simple-metering-config/fingerprints.lua
Show resolved
Hide resolved
| local can_handle_simple_metering_config = function(opts, driver, device) | ||
| -- 检查设备是否支持 Simple Metering 集群 (0x0702) | ||
| for _, cluster in ipairs(device.server_clusters) do | ||
| if cluster == 0x0702 then |
There was a problem hiding this comment.
we have other devices for which this would return true where we would not want your specific device's logic to be used, which is why we usually gate subdrivers via fingerprints
| local function device_init(driver, device) | ||
| -- 在设备初始化时设置 multipliers 和 divisors | ||
| device:configure() | ||
|
|
||
| -- 设置 Multiplier 为 1 | ||
| local write_multiplier_cmd = SimpleMetering.server.commands.WriteAttributes(device) | ||
| if write_multiplier_cmd then | ||
| device:send_to_component( | ||
| write_multiplier_cmd({ | ||
| {id = SimpleMetering.attributes.Multiplier.ID, value = 1, DataType = 0x22} -- 0x22 is 24-bit integer | ||
| }), | ||
| "main" | ||
| ) | ||
| end | ||
|
|
||
| -- 设置 Divisor 为 100 | ||
| local write_divisor_cmd = SimpleMetering.server.commands.WriteAttributes(device) | ||
| if write_divisor_cmd then | ||
| device:send_to_component( | ||
| write_divisor_cmd({ | ||
| {id = SimpleMetering.attributes.Divisor.ID, value = 100, DataType = 0x23} -- 0x23 is 32-bit integer | ||
| }), | ||
| "main" | ||
| ) | ||
| end | ||
| end |
There was a problem hiding this comment.
It is often the case that the driver init event happens before the radio is up after a hub restart, resulting in zigbee messages failing to be sent. I would recommend moving these to added or configure, since they likely do not need to be re-sent to the device every time they hub restarts.
| local divisor = device:get_field(SimpleMetering.attributes.Divisor.ID) or 100 | ||
| local multiplier = device:get_field(SimpleMetering.attributes.Multiplier.ID) or 1 |
There was a problem hiding this comment.
this field is not likely to be set. We do set a similar field from "st.zigbee.constants": constants.SIMPLE_METERING_MULTIPLIER_KEY (and divisor) in our defaults, but we never use the attribute ID as a key,
| if write_multiplier_cmd then | ||
| device:send_to_component( | ||
| write_multiplier_cmd({ | ||
| {id = SimpleMetering.attributes.Multiplier.ID, value = 1, DataType = 0x22} -- 0x22 is 24-bit integer |
There was a problem hiding this comment.
we provide "st.zigbee.data_types" which has a Int24 (and Int32 constant)
| if write_divisor_cmd then | ||
| device:send_to_component( | ||
| write_divisor_cmd({ | ||
| {id = SimpleMetering.attributes.Divisor.ID, value = 100, DataType = 0x23} -- 0x23 is 32-bit integer |
There was a problem hiding this comment.
in the ZCL this attribute is an Int24
|
Hi Steven ,
I have updated the driver according to the suggestion you provided. Please help me review it again, thank you very much .
Best regards!
Long,Jack
***@***.***
发件人: Steven Green ***@***.***>
发送时间: 2026年2月5日 4:23
收件人: SmartThingsCommunity/SmartThingsEdgeDrivers ***@***.***>
抄送: Long, Jack ***@***.***>; Author ***@***.***>
主题: Re: [SmartThingsCommunity/SmartThingsEdgeDrivers] WWSTCERT-10189 Ledvance zigbee meter plug (PR #2729)
You don't often get email from ***@***.******@***.***>. Learn why this is important<https://aka.ms/LearnAboutSenderIdentification>
@greens commented on this pull request.
________________________________
In drivers/SmartThings/zigbee-switch/fingerprints.yml<#2729 (comment)>:
- - id: "JNL/Y-K001-001"
- deviceLabel: Yanmi Switch (1 Way)
- manufacturer: JNL
- model: Y-K001-001
- deviceProfileName: basic-switch
- - id: "JNL/Y-K002-001"
- deviceLabel: Yanmi Switch (2 Way) 1
- manufacturer: JNL
- model: Y-K002-001
- deviceProfileName: basic-switch
zigbeeGeneric:
please do not remove other partners' fingerprints
―
Reply to this email directly, view it on GitHub<#2729 (review)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/B32Y5R5HB5C67Q7L5IPRYLD4KJII5AVCNFSM6AAAAACS4NOPFCVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZTONJSHA4TGMRYHE>.
You are receiving this because you authored the thread.Message ID: ***@***.******@***.***>>
|
| local function energy_meter_handler(driver, device, value, zb_rx) | ||
| local raw_value = value.value | ||
|
|
||
| if type(raw_value) ~= "number" or raw_value < 0 then | ||
| return | ||
| end | ||
|
|
||
| local divisor = device:get_field(zigbee_constants.SIMPLE_METERING_DIVISOR_KEY) or 100 | ||
| local multiplier = device:get_field(zigbee_constants.SIMPLE_METERING_MULTIPLIER_KEY) or 1 | ||
|
|
||
| if divisor == 0 then | ||
| return | ||
| end | ||
|
|
||
| local calculated_value = (raw_value * multiplier) / divisor | ||
|
|
||
| device:emit_event_for_endpoint( | ||
| zb_rx.address_header.src_endpoint.value, | ||
| capabilities.energyMeter.energy({ value = calculated_value, unit = "kWh" }) | ||
| ) | ||
| end |
There was a problem hiding this comment.
our default handlers should handle this case, provided your device properly reports its simple metering multiplier and divisor.
There was a problem hiding this comment.
I still think this function can be removed.
| @@ -0,0 +1,44 @@ | |||
| -- Copyright 2025 SmartThings, Inc. | |||
greens
left a comment
There was a problem hiding this comment.
Based on what you have here, I think all you need to add is the entry in fingerprints.yml. There does not seem to be any device-specific behavior that is different from our default handlers.
|
Hi Steven ,
Thanks for your feedback , when I only add the entry in fingerprints.yml and user Smartthings default handlers , the device can’t show the correct energy meter value in the Smartthings App , the displayed energy meter is 100 times the actual energy meter ,so I need add the sub driver for the device . Is there anything else we need to modify about our sub driver.
Best regards!
Long,Jack
***@***.***
发件人: Steven Green ***@***.***>
发送时间: 2026年2月12日 7:28
收件人: SmartThingsCommunity/SmartThingsEdgeDrivers ***@***.***>
抄送: Long, Jack ***@***.***>; Author ***@***.***>
主题: Re: [SmartThingsCommunity/SmartThingsEdgeDrivers] WWSTCERT-10189 Ledvance zigbee meter plug (PR #2729)
@greens requested changes on this pull request.
Based on what you have here, I think all you need to add is the entry in fingerprints.yml. There does not seem to be any device-specific behavior that is different from our default handlers.
―
Reply to this email directly, view it on GitHub<#2729 (review)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/B32Y5R57TKYP2CF52FRLOE34LO3IJAVCNFSM6AAAAACS4NOPFCVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZTOOBYGAYTQMRZHE>.
You are receiving this because you authored the thread.Message ID: ***@***.******@***.***>>
|
|
@LQ107 we should be reading the multiplier and divisor from the device on join. Is that not happening? Is it inaccurate? |
|
If not, you can simply set the multiplier and divisor fields in your driver's either way, we would like to see some unit tests added to verify your code's behavior |
|
Hi Steven ,
Thanks for your feedbacks , according to the idea you provided ,I set the multiplier and divisor fields in your driver's init handler , If there are any other issues with the driver, please contact me. Thank you very much.
Best regards!
Long,Jack
***@***.***
发件人: Steven Green ***@***.***>
发送时间: 2026年2月28日 5:17
收件人: SmartThingsCommunity/SmartThingsEdgeDrivers ***@***.***>
抄送: Long, Jack ***@***.***>; Mention ***@***.***>
主题: Re: [SmartThingsCommunity/SmartThingsEdgeDrivers] WWSTCERT-10189 Ledvance zigbee meter plug (PR #2729)
[https://avatars.githubusercontent.com/u/123942?s=20&v=4]greens left a comment (SmartThingsCommunity/SmartThingsEdgeDrivers#2729)<#2729 (comment)>
If not, you can simply set the multiplier and divisor fields in your driver's init handler rather than overwriting the default zigbee message handling
—
Reply to this email directly, view it on GitHub<#2729 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/B32Y5RYLCLPDF7A6V2LY75T4OCX6TAVCNFSM6AAAAACS4NOPFCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTSNZVGEZTEOBYG4>.
You are receiving this because you were mentioned.Message ID: ***@***.******@***.***>>
|
|
Invitation URL: |
Test Results 72 files 488 suites 0s ⏱️ Results for commit 99ce6ea. |
|
Minimum allowed coverage is Generated by 🐒 cobertura-action against 99ce6ea |
| local can_handle_simple_metering_config = function(opts, driver, device) | ||
| return device.fingerprinted == true | ||
| end |
There was a problem hiding this comment.
This is not how you should be checking for a specific device model. This will return true for every device, I expect.
There was a problem hiding this comment.
You should only need the init functions, or just rely on the defaults to read the multiplier/divisor.
Please include some unit tests if you think your changes are necessary.
…dd driver registration processing
|
Hi Steven ,
Thanks for your feedback , according to the modification suggestions you provided, I have modified the sub driver , If there are any other issues with the driver, please contact me. Thank you very much.
Best regards!
Long,Jack
***@***.***
发件人: Steven Green ***@***.***>
发送时间: 2026年3月4日 3:40
收件人: SmartThingsCommunity/SmartThingsEdgeDrivers ***@***.***>
抄送: Long, Jack ***@***.***>; Mention ***@***.***>
主题: Re: [SmartThingsCommunity/SmartThingsEdgeDrivers] WWSTCERT-10189 Ledvance zigbee meter plug (PR #2729)
@greens commented on this pull request.
…________________________________
On drivers/SmartThings/zigbee-switch/src/simple-metering-config/init.lua<#2729 (comment)>:
You should only need the init functions, or just rely on the defaults to read the multiplier/divisor.
Please include some unit tests if you think your changes are necessary.
―
Reply to this email directly, view it on GitHub<#2729 (review)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/B32Y5R2Q4H6EJSUCKPCI72T4O4YHHAVCNFSM6AAAAACS4NOPFCVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZTQOBUGY3DIOBQHE>.
You are receiving this because you were mentioned.Message ID: ***@***.******@***.***>>
|
check_lua_syntax.ps1
Outdated
test_can_handle.md
Outdated
There was a problem hiding this comment.
This is not how we handle unit tests. See the /tests directory for examples.
There was a problem hiding this comment.
revert these changes
just use git rm to remove files from tracking
| [SimpleMetering.attributes.Multiplier.ID] = function(driver, device, value, zb_rx) | ||
| device:set_field(zigbee_constants.SIMPLE_METERING_MULTIPLIER_KEY, value.value, {persist = true}) | ||
| end, | ||
| [SimpleMetering.attributes.Divisor.ID] = function(driver, device, value, zb_rx) | ||
| device:set_field(zigbee_constants.SIMPLE_METERING_DIVISOR_KEY, value.value, {persist = true}) |
There was a problem hiding this comment.
this is already how we handle these attributes by default
this code is redundant
| }, | ||
| lifecycle_handlers = { | ||
| init = function(driver, device) | ||
| configurations.power_reconfig_wrapper(device_init)(driver, device) |
There was a problem hiding this comment.
power_reconfig_wrapper has recently been renamed. this code will fail
greens
left a comment
There was a problem hiding this comment.
Change the copyright date to be 2026.
Include some unit tests.
Again, to reiterate for the third time, I do not think any of these changes should be necessary. We read the multiplier and divisor from the device during join and use them for energy calculations.
If that is not your experience when testing, then the only change you need is the init handler to set those fields manually.
Check all that apply
Type of Change
Checklist
Description of Change
Summary of Completed Tests