-
Notifications
You must be signed in to change notification settings - Fork 530
WWSTCERT-10189 Ledvance zigbee meter plug #2729
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
Changes from 25 commits
c8278e8
316276d
c01a9d0
5e5a387
98aafe1
6a76283
14de7ba
99ce6ea
22bc75b
b81fa6b
328797c
8f598e7
5004c95
09b89b7
3a46f9d
b7eb6b6
6b409cb
41d31e7
28e7783
875c75f
4011278
3347541
6063c89
9424f57
2f5fe4b
d02ef90
c6d53e8
6ee58b2
2c5a233
420f963
4650e24
5e6d9d6
542e724
bea9429
d0f3ccb
d555fe4
0d04304
d25cf5c
905fe30
c4f13dd
c651f91
c81e7e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| -- Copyright 2026 SmartThings, Inc. | ||
| -- Licensed under the Apache License, Version 2.0 | ||
|
|
||
| return function(opts, driver, device, ...) | ||
| local FINGERPRINTS = require("simple-metering-config.fingerprints") | ||
| for _, fingerprint in ipairs(FINGERPRINTS) do | ||
| if device:get_manufacturer() == fingerprint.mfr and device:get_model() == fingerprint.model then | ||
| local subdriver = require("simple-metering-config") | ||
| return true, subdriver | ||
| end | ||
| end | ||
| return false | ||
| end | ||
|
LQ107 marked this conversation as resolved.
Outdated
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| -- Copyright 2026 SmartThings, Inc. | ||
| -- Licensed under the Apache License, Version 2.0 | ||
|
|
||
| return { | ||
| { mfr = "LEDVANCE", model = "PLUG COMPACT EU EM T" } | ||
| } | ||
|
LQ107 marked this conversation as resolved.
Outdated
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| -- Copyright 2026 SmartThings, Inc. | ||
| -- Licensed under the Apache License, Version 2.0 | ||
|
|
||
| local capabilities = require "st.capabilities" | ||
| local zigbee_constants = require "st.zigbee.constants" | ||
| local SimpleMetering = require "st.zigbee.cluster".clusters.SimpleMetering | ||
|
|
||
| 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 | ||
|
LQ107 marked this conversation as resolved.
Outdated
|
||
| 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. our default handlers should handle this case, provided your device properly reports its simple metering multiplier and divisor.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still think this function can be removed. |
||
|
|
||
| local function device_init(driver, device) | ||
| -- Set default multiplier and divisor values as suggested by SmartThings | ||
| device:set_field(zigbee_constants.SIMPLE_METERING_MULTIPLIER_KEY, 1, {persist = true}) | ||
| device:set_field(zigbee_constants.SIMPLE_METERING_DIVISOR_KEY, 100, {persist = true}) | ||
| end | ||
|
|
||
| local simple_metering_config_subdriver = { | ||
| NAME = "Simple Metering Config", | ||
| supported_capabilities = { | ||
| capabilities.energyMeter, | ||
| capabilities.powerMeter | ||
| }, | ||
|
LQ107 marked this conversation as resolved.
Outdated
|
||
| zigbee_handlers = { | ||
| attr = { | ||
| [SimpleMetering.ID] = { | ||
| [SimpleMetering.attributes.CurrentSummationDelivered.ID] = energy_meter_handler | ||
| } | ||
| } | ||
| }, | ||
| lifecycle_handlers = { | ||
| init = device_init | ||
| }, | ||
| can_handle = require("simple-metering-config.can_handle") | ||
| } | ||
|
|
||
| return simple_metering_config_subdriver | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| -- Copyright 2026 SmartThings, Inc. | ||
| -- Licensed under the Apache License, Version 2.0 | ||
|
|
||
| local test = require "integration_test" | ||
| local zigbee_test_utils = require "integration_test.zigbee_test_utils" | ||
| local clusters = require "st.zigbee.zcl.clusters" | ||
| local SimpleMetering = clusters.SimpleMetering | ||
| local capabilities = require "st.capabilities" | ||
| local t_utils = require "integration_test.utils" | ||
|
|
||
| local mock_device = test.mock_device.build_test_zigbee_device( | ||
| { | ||
| profile = t_utils.get_profile_definition("switch-power-energy.yml"), | ||
| zigbee_endpoints = { | ||
| [1] = { | ||
| id = 1, | ||
| manufacturer = "LEDVANCE", | ||
| model = "PLUG COMPACT EU EM T", | ||
| server_clusters = { 0x0006, 0x0702 } | ||
| } | ||
| } | ||
| } | ||
| ) | ||
|
|
||
| zigbee_test_utils.prepare_zigbee_env_info() | ||
|
|
||
| local function test_init() | ||
| test.mock_device.add_test_device(mock_device) | ||
| end | ||
|
|
||
| test.set_test_init_function(test_init) | ||
|
|
||
| test.register_message_test( | ||
| "Energy meter report should be handled with default multiplier and divisor", | ||
| { | ||
| { | ||
| channel = "zigbee", | ||
| direction = "receive", | ||
| message = { mock_device.id, SimpleMetering.attributes.CurrentSummationDelivered:build_test_attr_report(mock_device, 1000) } | ||
| }, | ||
| { | ||
| channel = "capability", | ||
| direction = "send", | ||
| message = mock_device:generate_test_message("main", capabilities.energyMeter.energy({ value = 10, unit = "kWh" })) | ||
| } | ||
| } | ||
| ) | ||
|
|
||
| test.register_message_test( | ||
| "Energy meter report with zero value should be ignored", | ||
| { | ||
| { | ||
| channel = "zigbee", | ||
| direction = "receive", | ||
| message = { mock_device.id, SimpleMetering.attributes.CurrentSummationDelivered:build_test_attr_report(mock_device, 0) } | ||
| } | ||
| } | ||
| ) | ||
|
|
||
| test.register_message_test( | ||
| "Energy meter report with negative value should be ignored", | ||
| { | ||
| { | ||
| channel = "zigbee", | ||
| direction = "receive", | ||
| message = { mock_device.id, SimpleMetering.attributes.CurrentSummationDelivered:build_test_attr_report(mock_device, -100) } | ||
| } | ||
| } | ||
| ) | ||
|
|
||
| test.run_registered_tests() |
Uh oh!
There was an error while loading. Please reload this page.