Skip to content

Commit d572842

Browse files
authored
default Eve devices to main driver (#2534)
1 parent 658e57b commit d572842

File tree

3 files changed

+166
-11
lines changed

3 files changed

+166
-11
lines changed

drivers/SmartThings/matter-switch/src/sub_drivers/eve_energy/init.lua

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
local capabilities = require "st.capabilities"
99
local clusters = require "st.matter.clusters"
1010
local cluster_base = require "st.matter.cluster_base"
11-
local utils = require "st.utils"
11+
local st_utils = require "st.utils"
1212
local data_types = require "st.matter.data_types"
1313
local device_lib = require "st.device"
14+
local switch_utils = require "switch_utils.utils"
15+
local fields = require "switch_utils.fields"
1416

1517
local SWITCH_INITIALIZED = "__switch_intialized"
1618
local COMPONENT_TO_ENDPOINT_MAP = "__component_to_endpoint_map"
@@ -37,9 +39,11 @@ local MINIMUM_ST_ENERGY_REPORT_INTERVAL = (15 * 60) -- 15 minutes, reported in s
3739
-------------------------------------------------------------------------------------
3840

3941
local function is_eve_energy_products(opts, driver, device)
40-
-- this sub driver does not support child devices
42+
-- this sub driver does NOT support child devices, and ONLY supports Eve devices
43+
-- that do NOT support the Electrical Sensor device type
4144
if device.network_type == device_lib.NETWORK_TYPE_MATTER and
42-
device.manufacturer_info.vendor_id == EVE_MANUFACTURER_ID then
45+
device.manufacturer_info.vendor_id == EVE_MANUFACTURER_ID and
46+
#switch_utils.get_endpoints_by_device_type(device, fields.DEVICE_TYPE_ID.ELECTRICAL_SENSOR) == 0 then
4347
return true
4448
end
4549

@@ -326,7 +330,7 @@ end
326330
local function watt_accumulated_attr_handler(driver, device, ib, zb_rx)
327331
if ib.data.value then
328332
local totalConsumptionRawValue = ib.data.value
329-
local totalConsumptionWh = utils.round(1000 * totalConsumptionRawValue)
333+
local totalConsumptionWh = st_utils.round(1000 * totalConsumptionRawValue)
330334
updateEnergyMeter(device, totalConsumptionWh)
331335
report_power_consumption_to_st_energy(device, totalConsumptionWh)
332336
end

drivers/SmartThings/matter-switch/src/switch_handlers/attribute_handlers.lua

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -294,13 +294,6 @@ end
294294

295295
function AttributeHandlers.energy_imported_factory(is_cumulative_report)
296296
return function(driver, device, ib, response)
297-
-- workaround: ignore devices supporting Eve's private energy cluster AND the ElectricalEnergyMeasurement cluster
298-
local EVE_MANUFACTURER_ID, EVE_PRIVATE_CLUSTER_ID = 0x130A, 0x130AFC01
299-
local eve_private_energy_eps = device:get_endpoints(EVE_PRIVATE_CLUSTER_ID)
300-
if device.manufacturer_info.vendor_id == EVE_MANUFACTURER_ID and #eve_private_energy_eps > 0 then
301-
return
302-
end
303-
304297
if is_cumulative_report then
305298
AttributeHandlers.cumul_energy_imported_handler(driver, device, ib, response)
306299
elseif device:get_field(fields.CUMULATIVE_REPORTS_NOT_SUPPORTED) then

drivers/SmartThings/matter-switch/src/test/test_eve_energy.lua

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ local test = require "integration_test"
55
local capabilities = require "st.capabilities"
66
local t_utils = require "integration_test.utils"
77
local data_types = require "st.matter.data_types"
8+
local fields = require "switch_utils.fields"
89

910
local clusters = require "st.matter.clusters"
1011
local cluster_base = require "st.matter.cluster_base"
@@ -53,6 +54,73 @@ local mock_device = test.mock_device.build_test_matter_device({
5354
}
5455
})
5556

57+
local mock_device_electrical_sensor = test.mock_device.build_test_matter_device({
58+
profile = t_utils.get_profile_definition("power-energy-powerConsumption.yml"),
59+
manufacturer_info = {
60+
vendor_id = 0x130A,
61+
product_id = 0x0050,
62+
},
63+
endpoints = {
64+
{
65+
endpoint_id = 0,
66+
clusters = {
67+
{ cluster_id = clusters.Basic.ID, cluster_type = "SERVER" },
68+
},
69+
device_types = {
70+
{ device_type_id = 0x0016, device_type_revision = 1 } -- RootNode
71+
}
72+
},
73+
{
74+
endpoint_id = 1,
75+
clusters = {
76+
{
77+
cluster_id = clusters.OnOff.ID,
78+
cluster_type = "SERVER",
79+
cluster_revision = 1,
80+
feature_map = 0, --u32 bitmap
81+
},
82+
{
83+
cluster_id = PRIVATE_CLUSTER_ID,
84+
cluster_type = "SERVER",
85+
cluster_revision = 1,
86+
feature_map = 0, --u32 bitmap
87+
}
88+
},
89+
device_types = {
90+
{ device_type_id = 0x010A, device_type_revision = 1 } -- On/Off Plug
91+
}
92+
},
93+
{
94+
endpoint_id = 2,
95+
clusters = {
96+
{
97+
cluster_id = clusters.ElectricalEnergyMeasurement.ID,
98+
cluster_type = "SERVER",
99+
cluster_revision = 1,
100+
feature_map = clusters.ElectricalEnergyMeasurement.types.Feature.CUMULATIVE_ENERGY,
101+
}
102+
},
103+
device_types = {
104+
{ device_type_id = fields.DEVICE_TYPE_ID.ELECTRICAL_SENSOR, device_type_revision = 1 }
105+
}
106+
}
107+
}
108+
})
109+
110+
local function test_init_electrical_sensor()
111+
local cluster_subscribe_list = {
112+
clusters.OnOff.attributes.OnOff,
113+
clusters.ElectricalEnergyMeasurement.attributes.CumulativeEnergyImported,
114+
clusters.ElectricalEnergyMeasurement.attributes.PeriodicEnergyImported,
115+
}
116+
local subscribe_request = cluster_subscribe_list[1]:subscribe(mock_device_electrical_sensor)
117+
for i, cluster in ipairs(cluster_subscribe_list) do
118+
subscribe_request:merge(cluster:subscribe(mock_device_electrical_sensor))
119+
end
120+
test.socket.matter:__expect_send({ mock_device_electrical_sensor.id, subscribe_request })
121+
test.mock_device.add_test_device(mock_device_electrical_sensor)
122+
end
123+
56124
local function test_init()
57125
local cluster_subscribe_list = {
58126
clusters.OnOff.attributes.OnOff,
@@ -374,4 +442,94 @@ test.register_coroutine_test(
374442
}
375443
)
376444

445+
local cumulative_report_val_19 = {
446+
energy = 19000,
447+
start_timestamp = 0,
448+
end_timestamp = 0,
449+
start_systime = 0,
450+
end_systime = 0,
451+
apparent_energy = 0,
452+
reactive_energy = 0
453+
}
454+
455+
local cumulative_report_val_29 = {
456+
energy = 29000,
457+
start_timestamp = 0,
458+
end_timestamp = 0,
459+
start_systime = 0,
460+
end_systime = 0,
461+
apparent_energy = 0,
462+
reactive_energy = 0
463+
}
464+
465+
local cumulative_report_val_39 = {
466+
energy = 39000,
467+
start_timestamp = 0,
468+
end_timestamp = 0,
469+
start_systime = 0,
470+
end_systime = 0,
471+
apparent_energy = 0,
472+
reactive_energy = 0
473+
}
474+
475+
test.register_coroutine_test(
476+
"Cumulative Energy measurement should generate correct messages",
477+
function()
478+
local mock_device = mock_device_electrical_sensor
479+
480+
test.mock_time.advance_time(901) -- move time 15 minutes past 0 (this can be assumed to be true in practice in all cases)
481+
test.socket.matter:__queue_receive(
482+
{
483+
mock_device.id,
484+
clusters.ElectricalEnergyMeasurement.server.attributes.CumulativeEnergyImported:build_test_report_data(
485+
mock_device, 1, cumulative_report_val_19
486+
)
487+
}
488+
)
489+
test.socket.capability:__expect_send(
490+
mock_device:generate_test_message("main", capabilities.energyMeter.energy({ value = 19.0, unit = "Wh" }))
491+
)
492+
test.socket.capability:__expect_send(
493+
mock_device:generate_test_message("main", capabilities.powerConsumptionReport.powerConsumption({
494+
start = "1970-01-01T00:00:00Z",
495+
["end"] = "1970-01-01T00:15:00Z",
496+
deltaEnergy = 0.0,
497+
energy = 19.0
498+
}))
499+
)
500+
test.socket.matter:__queue_receive(
501+
{
502+
mock_device.id,
503+
clusters.ElectricalEnergyMeasurement.server.attributes.CumulativeEnergyImported:build_test_report_data(
504+
mock_device, 1, cumulative_report_val_29
505+
)
506+
}
507+
)
508+
test.socket.capability:__expect_send(
509+
mock_device:generate_test_message("main", capabilities.energyMeter.energy({ value = 29.0, unit = "Wh" }))
510+
)
511+
test.wait_for_events()
512+
test.mock_time.advance_time(1500)
513+
test.socket.matter:__queue_receive(
514+
{
515+
mock_device.id,
516+
clusters.ElectricalEnergyMeasurement.server.attributes.CumulativeEnergyImported:build_test_report_data(
517+
mock_device, 1, cumulative_report_val_39
518+
)
519+
}
520+
)
521+
test.socket.capability:__expect_send(
522+
mock_device:generate_test_message("main", capabilities.energyMeter.energy({ value = 39.0, unit = "Wh" }))
523+
)
524+
test.socket.capability:__expect_send(
525+
mock_device:generate_test_message("main", capabilities.powerConsumptionReport.powerConsumption({
526+
start = "1970-01-01T00:15:01Z",
527+
["end"] = "1970-01-01T00:40:00Z",
528+
deltaEnergy = 20.0,
529+
energy = 39.0
530+
}))
531+
)
532+
end, { test_init = test_init_electrical_sensor }
533+
)
534+
377535
test.run_registered_tests()

0 commit comments

Comments
 (0)