delphiki/hass-pronote

State is not JSON serializable on punishments sensor

Closed this issue · 1 comments

Here's an anonymised excerpt from my logs on HA:

State is not JSON serializable: <state sensor.pronote_xxx_punishments=1; updated_at=2023-10-20T14:18:18.214254+02:00, punishments=[{'date': '2023-10-17', 'subject': False, 'reasons': ['XXX'], 'circumstances': 'XXX', 'nature': 'Retenue', 'duration': '0:00:00', 'homework': '', 'exclusion': False, 'during_lesson': False, 'homework_documents': [{'name': 'xxx.pdf', 'url': 'https://xxx.index-education.net/pronote/FichiersExternes/xx/xxx.pdf?Session=xxx', 'type': 1}], 'circumstance_documents': [], 'giver': 'X', 'schedule': [{'start': datetime.datetime(2023, 10, 18, 13, 35), 'duration': datetime.timedelta(0)}], 'schedulable': True}], friendly_name=pronote_xxx_punishments @ 2023-10-20T14:18:18.214264+02:00>: Type is not JSON serializable: datetime.timedelta

I guess the problem stems from pronotepy passing in a timedelta object for schedules of punishments and that type not being natively translatable to a JSON string.

If you think that would work in this context, I can try locally applying something like this to the timedelta object (or others from the same question) and send a PR once tested on my instance.

Corrigé avec la version 0.13.3 :)