Skip to content

UnboundLocalError: local variable 'sum' referenced before assignment #95

@Rep-Hueman

Description

@Rep-Hueman

Version of the custom_component

OCPP version 0.3.2 21-07-2021

Configuration

Describe the bug

UnboundLocalError: local variable 'sum' referenced before assignment.

No problems with the test version for 3 phase - version 0.3.1 i test today.

Debug log


This error originated from a custom integration.

Logger: ocpp
Source: custom_components/ocpp/api.py:719
Integration: Open Charge Point Protocol (OCPP) (documentation, issues)
First occurred: 20:03:15 (1 occurrences)
Last logged: 20:03:15

Error while handling request '<Call - unique_id=18, action=MeterValues, payload={'connectorId': 1, 'transactionId': 1626878818, 'meterValue': [{'timestamp': '2021-07-21T17:42:42Z', 'sampledValue': [{'value': '1336750.000', 'context': 'Sample.Periodic', 'measurand': 'Energy.Active.Import.Register', 'location': 'Outlet', 'unit': 'Wh'}, {'value': '0.000', 'context': 'Sample.Periodic', 'measurand': 'Power.Active.Import', 'location': 'Outlet', 'unit': 'W'}, {'value': '0.000', 'context': 'Sample.Periodic', 'measurand': 'Power.Active.Import', 'location': 'Outlet', 'unit': 'W', 'phase': 'L1'}, {'value': '0.000', 'context': 'Sample.Periodic', 'measurand': 'Power.Active.Import', 'location': 'Outlet', 'unit': 'W', 'phase': 'L2'}, {'value': '0.000', 'context': 'Sample.Periodic', 'measurand': 'Power.Active.Import', 'location': 'Outlet', 'unit': 'W', 'phase': 'L3'}, {'value': '0.000', 'context': 'Sample.Periodic', 'measurand': 'Power.Factor', 'location': 'Outlet'}, {'value': '0.000', 'context': 'Sample.Periodic', 'measurand': 'Current.Import', 'location': 'Outlet', 'unit': 'A', 'phase': 'L1'}, {'value': '0.000', 'context': 'Sample.Periodic', 'measurand': 'Current.Import', 'location': 'Outlet', 'unit': 'A', 'phase': 'L2'}, {'value': '0.000', 'context': 'Sample.Periodic', 'measurand': 'Current.Import', 'location': 'Outlet', 'unit': 'A', 'phase': 'L3'}, {'value': '0.000', 'context': 'Sample.Periodic', 'measurand': 'Current.Offered', 'location': 'Outlet', 'unit': 'A'}, {'value': '224.700', 'context': 'Sample.Periodic', 'measurand': 'Voltage', 'location': 'Outlet', 'unit': 'V', 'phase': 'L1-N'}, {'value': '224.600', 'context': 'Sample.Periodic', 'measurand': 'Voltage', 'location': 'Outlet', 'unit': 'V', 'phase': 'L2-N'}, {'value': '226.500', 'context': 'Sample.Periodic', 'measurand': 'Voltage', 'location': 'Outlet', 'unit': 'V', 'phase': 'L3-N'}, {'value': '391.400', 'context': 'Sample.Periodic', 'measurand': 'Voltage', 'location': 'Outlet', 'unit': 'V', 'phase': 'L1-L2'}, {'value': '391.200', 'context': 'Sample.Periodic', 'measurand': 'Voltage', 'location': 'Outlet', 'unit': 'V', 'phase': 'L2-L3'}, {'value': '393.100', 'context': 'Sample.Periodic', 'measurand': 'Voltage', 'location': 'Outlet', 'unit': 'V', 'phase': 'L3-L1'}, {'value': '50.040', 'context': 'Sample.Periodic', 'measurand': 'Frequency', 'location': 'Outlet'}, {'value': '43.000', 'context': 'Sample.Periodic', 'measurand': 'Temperature', 'location': 'Body', 'unit': 'Celsius'}]}]}>'
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/ocpp/charge_point.py", line 185, in _handle_call
    response = handler(**snake_case_payload)
  File "/usr/local/lib/python3.9/site-packages/ocpp/routing.py", line 47, in inner
    return func(*args, **kwargs)
  File "/config/custom_components/ocpp/api.py", line 754, in on_meter_values
    self.process_phases(unprocessed)
  File "/config/custom_components/ocpp/api.py", line 719, in process_phases
    self._metrics[metric] = round(sum, 1)
UnboundLocalError: local variable 'sum' referenced before assignment

2021-07-21 20:00:05 INFO (MainThread) [ocpp] RepHome-1: send [4,"15","InternalError","An unexpected error occurred.",{}]
2021-07-21 20:01:23 INFO (MainThread) [ocpp] RepHome-1: receive message [2,"16","MeterValues",{"connectorId":1,"transactionId":1626878818,"meterValue":[{"timestamp":"2021-07-21T17:42:42Z","sampledValue":[{"value":"1336750.000","context":"Sample.Periodic","measurand":"Energy.Active.Import.Register","location":"Outlet","unit":"Wh"},{"value":"0.000","context":"Sample.Periodic","measurand":"Power.Active.Import","location":"Outlet","unit":"W"},{"value":"0.000","context":"Sample.Periodic","measurand":"Power.Active.Import","location":"Outlet","unit":"W","phase":"L1"},{"value":"0.000","context":"Sample.Periodic","measurand":"Power.Active.Import","location":"Outlet","unit":"W","phase":"L2"},{"value":"0.000","context":"Sample.Periodic","measurand":"Power.Active.Import","location":"Outlet","unit":"W","phase":"L3"},{"value":"0.000","context":"Sample.Periodic","measurand":"Power.Factor","location":"Outlet"},{"value":"0.000","context":"Sample.Periodic","measurand":"Current.Import","location":"Outlet","unit":"A","phase":"L1"},{"value":"0.000","context":"Sample.Periodic","measurand":"Current.Import","location":"Outlet","unit":"A","phase":"L2"},{"value":"0.000","context":"Sample.Periodic","measurand":"Current.Import","location":"Outlet","unit":"A","phase":"L3"},{"value":"0.000","context":"Sample.Periodic","measurand":"Current.Offered","location":"Outlet","unit":"A"},{"value":"224.700","context":"Sample.Periodic","measurand":"Voltage","location":"Outlet","unit":"V","phase":"L1-N"},{"value":"224.600","context":"Sample.Periodic","measurand":"Voltage","location":"Outlet","unit":"V","phase":"L2-N"},{"value":"226.500","context":"Sample.Periodic","measurand":"Voltage","location":"Outlet","unit":"V","phase":"L3-N"},{"value":"391.400","context":"Sample.Periodic","measurand":"Voltage","location":"Outlet","unit":"V","phase":"L1-L2"},{"value":"391.200","context":"Sample.Periodic","measurand":"Voltage","location":"Outlet","unit":"V","phase":"L2-L3"},{"value":"393.100","context":"Sample.Periodic","measurand":"Voltage","location":"Outlet","unit":"V","phase":"L3-L1"},{"value":"50.040","context":"Sample.Periodic","measurand":"Frequency","location":"Outlet"},{"value":"43.000","context":"Sample.Periodic","measurand":"Temperature","location":"Body","unit":"Celsius"}]}]}]
2021-07-21 20:01:23 ERROR (MainThread) [ocpp] Error while handling request '<Call - unique_id=16, action=MeterValues, payload={'connectorId': 1, 'transactionId': 1626878818, 'meterValue': [{'timestamp': '2021-07-21T17:42:42Z', 'sampledValue': [{'value': '1336750.000', 'context': 'Sample.Periodic', 'measurand': 'Energy.Active.Import.Register', 'location': 'Outlet', 'unit': 'Wh'}, {'value': '0.000', 'context': 'Sample.Periodic', 'measurand': 'Power.Active.Import', 'location': 'Outlet', 'unit': 'W'}, {'value': '0.000', 'context': 'Sample.Periodic', 'measurand': 'Power.Active.Import', 'location': 'Outlet', 'unit': 'W', 'phase': 'L1'}, {'value': '0.000', 'context': 'Sample.Periodic', 'measurand': 'Power.Active.Import', 'location': 'Outlet', 'unit': 'W', 'phase': 'L2'}, {'value': '0.000', 'context': 'Sample.Periodic', 'measurand': 'Power.Active.Import', 'location': 'Outlet', 'unit': 'W', 'phase': 'L3'}, {'value': '0.000', 'context': 'Sample.Periodic', 'measurand': 'Power.Factor', 'location': 'Outlet'}, {'value': '0.000', 'context': 'Sample.Periodic', 'measurand': 'Current.Import', 'location': 'Outlet', 'unit': 'A', 'phase': 'L1'}, {'value': '0.000', 'context': 'Sample.Periodic', 'measurand': 'Current.Import', 'location': 'Outlet', 'unit': 'A', 'phase': 'L2'}, {'value': '0.000', 'context': 'Sample.Periodic', 'measurand': 'Current.Import', 'location': 'Outlet', 'unit': 'A', 'phase': 'L3'}, {'value': '0.000', 'context': 'Sample.Periodic', 'measurand': 'Current.Offered', 'location': 'Outlet', 'unit': 'A'}, {'value': '224.700', 'context': 'Sample.Periodic', 'measurand': 'Voltage', 'location': 'Outlet', 'unit': 'V', 'phase': 'L1-N'}, {'value': '224.600', 'context': 'Sample.Periodic', 'measurand': 'Voltage', 'location': 'Outlet', 'unit': 'V', 'phase': 'L2-N'}, {'value': '226.500', 'context': 'Sample.Periodic', 'measurand': 'Voltage', 'location': 'Outlet', 'unit': 'V', 'phase': 'L3-N'}, {'value': '391.400', 'context': 'Sample.Periodic', 'measurand': 'Voltage', 'location': 'Outlet', 'unit': 'V', 'phase': 'L1-L2'}, {'value': '391.200', 'context': 'Sample.Periodic', 'measurand': 'Voltage', 'location': 'Outlet', 'unit': 'V', 'phase': 'L2-L3'}, {'value': '393.100', 'context': 'Sample.Periodic', 'measurand': 'Voltage', 'location': 'Outlet', 'unit': 'V', 'phase': 'L3-L1'}, {'value': '50.040', 'context': 'Sample.Periodic', 'measurand': 'Frequency', 'location': 'Outlet'}, {'value': '43.000', 'context': 'Sample.Periodic', 'measurand': 'Temperature', 'location': 'Body', 'unit': 'Celsius'}]}]}>'
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/ocpp/charge_point.py", line 185, in _handle_call
response = handler(**snake_case_payload)
File "/usr/local/lib/python3.9/site-packages/ocpp/routing.py", line 47, in inner
return func(*args, **kwargs)
File "/config/custom_components/ocpp/api.py", line 754, in on_meter_values
self.process_phases(unprocessed)
File "/config/custom_components/ocpp/api.py", line 719, in process_phases
self._metrics[metric] = round(sum, 1)
UnboundLocalError: local variable 'sum' referenced before assignment
2021-07-21 20:01:23 INFO (MainThread) [ocpp] RepHome-1: send [4,"16","InternalError","An unexpected error occurred.",{}]
2021-07-21 20:02:59 INFO (MainThread) [ocpp] RepHome-1: send [2,"d4d75964-4789-4d40-80b2-bb1fbdb5e389","GetConfiguration",{"key":["SupportedFeatureProfiles"]}]
2021-07-21 20:02:59 INFO (MainThread) [ocpp] RepHome-1: receive message [3,"d4d75964-4789-4d40-80b2-bb1fbdb5e389",{"configurationKey":[{"key":"SupportedFeatureProfiles","readonly":true,"value":"Core,FirmwareManagement,Reservation,LocalAuthListManagement,RemoteTrigger,SmartCharging"}]}]
2021-07-21 20:02:59 INFO (MainThread) [ocpp] RepHome-1: send [2,"99879625-a021-41ca-b2f6-ab4fda0757d6","TriggerMessage",{"requestedMessage":"BootNotification"}]
2021-07-21 20:02:59 INFO (MainThread) [ocpp] RepHome-1: receive message [3,"99879625-a021-41ca-b2f6-ab4fda0757d6",{"status":"Accepted"}]
2021-07-21 20:02:59 INFO (MainThread) [ocpp] RepHome-1: send [2,"bf7b6202-9180-44fa-b4c6-06956f2c6493","TriggerMessage",{"requestedMessage":"StatusNotification"}]
2021-07-21 20:02:59 INFO (MainThread) [ocpp] RepHome-1: receive message [3,"bf7b6202-9180-44fa-b4c6-06956f2c6493",{"status":"Accepted"}]
2021-07-21 20:02:59 INFO (MainThread) [ocpp] RepHome-1: send [2,"6381e53c-3d40-4595-8eee-be9bbb40468e","ChangeAvailability",{"connectorId":0,"type":"Operative"}]
2021-07-21 20:03:00 INFO (MainThread) [ocpp] RepHome-1: receive message [3,"6381e53c-3d40-4595-8eee-be9bbb40468e",{"status":"Accepted"}]
2021-07-21 20:03:00 INFO (MainThread) [ocpp] RepHome-1: send [2,"6ca8c631-258e-4ae9-8b88-3da434d9becc","GetConfiguration",{"key":["HeartbeatInterval"]}]
2021-07-21 20:03:00 INFO (MainThread) [ocpp] RepHome-1: receive message [3,"6ca8c631-258e-4ae9-8b88-3da434d9becc",{"configurationKey":[{"key":"HeartbeatInterval","readonly":false,"value":"30"}]}]
2021-07-21 20:03:00 INFO (MainThread) [ocpp] RepHome-1: send [2,"f45723ab-9f65-4db8-931a-e9be5e80d241","GetConfiguration",{"key":["WebSocketPingInterval"]}]
2021-07-21 20:03:00 INFO (MainThread) [ocpp] RepHome-1: receive message [3,"f45723ab-9f65-4db8-931a-e9be5e80d241",{"configurationKey":[{"key":"WebSocketPingInterval","readonly":false,"value":"60"}]}]
2021-07-21 20:03:00 INFO (MainThread) [ocpp] RepHome-1: send [2,"86b765fe-ac66-4587-80c3-1e60de3c132e","GetConfiguration",{"key":["MeterValuesSampledData"]}]
2021-07-21 20:03:00 INFO (MainThread) [ocpp] RepHome-1: receive message [3,"86b765fe-ac66-4587-80c3-1e60de3c132e",{"configurationKey":[{"key":"MeterValuesSampledData","readonly":false,"value":"Energy.Active.Import.Register,Power.Active.Import,Power.Factor,Current.Import,Current.Offered,Voltage,Frequency,Temperature"}]}]
2021-07-21 20:03:00 INFO (MainThread) [ocpp] RepHome-1: send [2,"e3e1b761-e043-45d3-8251-0e7e3655dde9","GetConfiguration",{"key":["MeterValueSampleInterval"]}]
2021-07-21 20:03:00 INFO (MainThread) [ocpp] RepHome-1: receive message [3,"e3e1b761-e043-45d3-8251-0e7e3655dde9",{"configurationKey":[{"key":"MeterValueSampleInterval","readonly":false,"value":"60"}]}]
2021-07-21 20:03:00 INFO (MainThread) [ocpp] RepHome-1: send [2,"04e578a5-b41d-49a0-895f-b1625249b4ce","GetConfiguration",{"key":["NumberOfConnectors"]}]
2021-07-21 20:03:00 INFO (MainThread) [ocpp] RepHome-1: receive message [3,"04e578a5-b41d-49a0-895f-b1625249b4ce",{"configurationKey":[{"key":"NumberOfConnectors","readonly":true,"value":"1"}]}]
2021-07-21 20:03:04 INFO (MainThread) [ocpp] RepHome-1: receive message [2,"17","BootNotification",{"chargePointVendor":"Alfen BV","chargePointModel":"NG910-60023","chargePointSerialNumber":"ace0025893","chargeBoxSerialNumber":"RepHome-1","firmwareVersion":"4.15.0-3910"}]
2021-07-21 20:03:04 INFO (MainThread) [ocpp] RepHome-1: send [3,"17",{"currentTime":"2021-07-21T18:03:04.791874+00:00","interval":30,"status":"Accepted"}]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions