diff --git a/drivers/SmartThings/matter-energy/src/init.lua b/drivers/SmartThings/matter-energy/src/init.lua index c6e44008d6..6ee3eeac7a 100644 --- a/drivers/SmartThings/matter-energy/src/init.lua +++ b/drivers/SmartThings/matter-energy/src/init.lua @@ -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 ) @@ -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 @@ -474,10 +474,10 @@ 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' @@ -485,7 +485,7 @@ local function report_power_consumption_to_st_energy(device, component, latest_t 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 diff --git a/drivers/SmartThings/matter-energy/src/test/test_battery_storage.lua b/drivers/SmartThings/matter-energy/src/test/test_battery_storage.lua index 329daa6bd7..4f077189a0 100644 --- a/drivers/SmartThings/matter-energy/src/test/test_battery_storage.lua +++ b/drivers/SmartThings/matter-energy/src/test/test_battery_storage.lua @@ -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" })) @@ -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" }))