Fix serialization issue adding error to job (#4853)

This commit is contained in:
Mike Degatano 2024-01-30 06:21:02 -05:00 committed by GitHub
parent 6ed26cdd1f
commit 88d718271d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 36 additions and 2 deletions

View File

@ -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":

View File

@ -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",
}
],
},
},
}