mobilityhouse / ocpp

Python implementation of the Open Charge Point Protocol (OCPP).
MIT License
744 stars 291 forks source link

TypeError: asdict() should be called on dataclass instances #645

Closed Nwangyh closed 1 month ago

Nwangyh commented 1 month ago

Hello, this is a great module! When I was testing the charging station program, I developed a CSMS test terminal, and there was such a problem: TypeError: asdict() should be called on dataclass instances.

I used debug mode to print log, and I'm pretty sure the json output from my charging station program is standard ocpp2.0.1 format: [2, "7647264a-e369- 4ce3 -9c47-322c3fd12f01", "FirmwareStatusNotification", {"status":"DownloadScheduled"}].

But I encountered problems like those mentioned above. I tried to print the type of response before asdfict, using type(), but it was obvious that the output type was nonetype. My ability is relatively limited, and I can't continue to investigate deeply, so I want to ask for help.

My CSMS processing code looks like this: @on("FirmwareStatusNotification") def on_firmware_status_notification(self, status, **kwargs): logging.info("Got a FirmwareStatusNotification : " + status) if status == "Installed": logging.info("Firmware Installed Successfully.") asyncio.create_task(self.CASE_B11_RESET()) I don't know where the problem is, it looks like parsing this type of message doesn't parse it, but I'm not sure.

And because my English is not good, I use a translator, so this paragraph may seem bad, very sorry~

Thank you very much! XD

ps:log is down~ abc.log

Nwangyh commented 1 month ago

I can confirm that everything I use is up to date, including Python 3.12 and the latest ocpp.

OrangeTux commented 1 month ago

It seems that on_firmware_status_notification() is not returning anything. Make sure to return the right call result, in this case call_result.FirmwareStatusNotification.

Nwangyh commented 1 month ago

Thank you very much for your reply! In fact, I'm sure I have a correct reply, because I tried before and made a call_result reply without any status information, but there is still this problem.

Nwangyh commented 1 month ago

Thank you very much for your help! The problem has been found, and indeed as you said I need a correct response to avoid this problem, although this response may be optional in OCPP2.0.1. Thank you again!