Skip to content

Commit d46fafd

Browse files
committed
Add new keys to Error model
1 parent 1236f1e commit d46fafd

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

homeassistant_api/models/websocket.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ class PingResponse(BaseModel):
4545
class Error(BaseModel):
4646
code: str
4747
message: str
48+
translation_key: str
49+
translation_placeholders: dict[str, str]
50+
translation_domain: str
4851

4952

5053
class ErrorResponse(BaseModel):

homeassistant_api/rawwebsocket.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,11 @@ def parse_response(self, data: dict[str, JSONType]) -> None:
136136
self._ping_responses[data_id].end = time.perf_counter_ns()
137137
elif data.get("type") == "result":
138138
logger.info("Received result message")
139-
self._result_responses[data_id] = ResultResponse.model_validate(data)
139+
if data.get("success"):
140+
self._result_responses[data_id] = ResultResponse.model_validate(data)
141+
else:
142+
error_resp = ErrorResponse.model_validate(data)
143+
raise RequestError(error_resp.error.code, error_resp.error.message)
140144
elif data.get("type") == "event":
141145
logger.info("Received event message %s", data["event"])
142146
self._event_responses[data_id].append(EventResponse.model_validate(data))

0 commit comments

Comments
 (0)