From 88d718271d9b2865e32343e5cd05b5b76ad93451 Mon Sep 17 00:00:00 2001 From: Mike Degatano Date: Tue, 30 Jan 2024 06:21:02 -0500 Subject: [PATCH] Fix serialization issue adding error to job (#4853) --- supervisor/jobs/__init__.py | 5 ++++- tests/jobs/test_job_manager.py | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/supervisor/jobs/__init__.py b/supervisor/jobs/__init__.py index fd5ee6cfc..432a4bd6f 100644 --- a/supervisor/jobs/__init__.py +++ b/supervisor/jobs/__init__.py @@ -201,8 +201,11 @@ class JobManager(FileConfiguration, CoreSysAttributes): self, job: SupervisorJob, attribute: Attribute, value: Any ) -> None: """Notify Home Assistant of a change to a job and bus on job start/end.""" + if attribute.name == "errors": + value = [err.as_dict() for err in value] + self.sys_homeassistant.websocket.supervisor_event( - WSEvent.JOB, job.as_dict() | {attribute.alias: value} + WSEvent.JOB, job.as_dict() | {attribute.name: value} ) if attribute.name == "done": diff --git a/tests/jobs/test_job_manager.py b/tests/jobs/test_job_manager.py index a85a712de..d6fd38591 100644 --- a/tests/jobs/test_job_manager.py +++ b/tests/jobs/test_job_manager.py @@ -175,6 +175,32 @@ async def test_notify_on_change(coresys: CoreSys): } ) + job.capture_error() + await asyncio.sleep(0) + coresys.homeassistant.websocket._client.async_send_command.assert_called_with( + { + "type": "supervisor/event", + "data": { + "event": "job", + "data": { + "name": TEST_JOB, + "reference": "test", + "uuid": ANY, + "progress": 50, + "stage": "test", + "done": False, + "parent_id": None, + "errors": [ + { + "type": "HassioError", + "message": "Unknown error, see supervisor logs", + } + ], + }, + }, + } + ) + await asyncio.sleep(0) coresys.homeassistant.websocket._client.async_send_command.assert_called_with( { @@ -189,7 +215,12 @@ async def test_notify_on_change(coresys: CoreSys): "stage": "test", "done": True, "parent_id": None, - "errors": [], + "errors": [ + { + "type": "HassioError", + "message": "Unknown error, see supervisor logs", + } + ], }, }, }