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
10 changes: 5 additions & 5 deletions drivers/SmartThings/matter-energy/src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ local function evse_supply_state_handler(driver, device, ib, response)
local evse_supply_state = ib.data.value

local latest_evse_state = device:get_latest_state(
device:endpoint_to_component(ib.endopint_id),
device:endpoint_to_component(ib.endpoint_id),
capabilities.evseState.ID,
capabilities.evseState.state.NAME
)
Expand Down Expand Up @@ -461,7 +461,7 @@ local function device_energy_mgmt_mode_attr_handler(driver, device, ib, response
end
end

local function report_power_consumption_to_st_energy(device, component, latest_total_imported_energy_wh)
local function report_power_consumption_to_st_energy(device, component, latest_total_energy_wh)
local current_time = os.time()

local last_report_timestamp_field = component.id == "exportedEnergy" and LAST_EXPORTED_REPORT_TIMESTAMP or LAST_IMPORTED_REPORT_TIMESTAMP
Expand All @@ -474,18 +474,18 @@ local function report_power_consumption_to_st_energy(device, component, latest_t

-- Calculate the energy delta between reports
local energy_delta_wh = 0.0
local previous_imported_report = device:get_latest_state("main", capabilities.powerConsumptionReport.ID,
local previous_imported_report = device:get_latest_state(component.id, capabilities.powerConsumptionReport.ID,
capabilities.powerConsumptionReport.powerConsumption.NAME)
if previous_imported_report and previous_imported_report.energy then
energy_delta_wh = math.max(latest_total_imported_energy_wh - previous_imported_report.energy, 0.0)
energy_delta_wh = math.max(latest_total_energy_wh - previous_imported_report.energy, 0.0)
end

-- Report the energy consumed during the time interval. The unit of these values should be 'Wh'
device:emit_component_event(component, capabilities.powerConsumptionReport.powerConsumption({
start = epoch_to_iso8601(last_time),
["end"] = epoch_to_iso8601(current_time - 1),
deltaEnergy = energy_delta_wh,
energy = latest_total_imported_energy_wh
energy = latest_total_energy_wh
}))
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ test.register_coroutine_test(
mock_device:generate_test_message("importedEnergy",
capabilities.powerConsumptionReport.powerConsumption({
energy = 200,
deltaEnergy = 0.0,
deltaEnergy = 100,
start = "1970-01-01T00:15:01Z",
["end"] = "1970-01-01T00:48:20Z"
}))
Expand All @@ -278,20 +278,20 @@ test.register_coroutine_test(
test.socket.matter:__queue_receive({ mock_device.id, clusters.ElectricalEnergyMeasurement.attributes
.CumulativeEnergyExported:build_test_report_data(mock_device,
BATTERY_STORAGE_EP,
clusters.ElectricalEnergyMeasurement.types.EnergyMeasurementStruct({ energy = 400000, start_timestamp = 0, end_timestamp = 0, start_systime = 0, end_systime = 0, apparent_energy = 0, reactive_energy = 0 })) }) --400Wh
clusters.ElectricalEnergyMeasurement.types.EnergyMeasurementStruct({ energy = 500000, start_timestamp = 0, end_timestamp = 0, start_systime = 0, end_systime = 0, apparent_energy = 0, reactive_energy = 0 })) }) --500Wh

test.socket.capability:__expect_send(
mock_device:generate_test_message("exportedEnergy",
capabilities.energyMeter.energy({
value = 400, unit = "Wh"
value = 500, unit = "Wh"
}))
)

test.socket.capability:__expect_send(
mock_device:generate_test_message("exportedEnergy",
capabilities.powerConsumptionReport.powerConsumption({
energy = 400,
deltaEnergy = 0.0,
energy = 500,
deltaEnergy = 100,
start = "1970-01-01T00:15:01Z",
["end"] = "1970-01-01T00:48:20Z"
}))
Expand Down
Loading