Skip to content

Commit abf67f9

Browse files
authored
Merge pull request #226 from GrandMoff100/copilot/fix-error-responses-bug
Fix optional translation fields in websocket Error model
2 parents 21fecd8 + 41cc4b6 commit abf67f9

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

homeassistant_api/models/websocket.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +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
48+
translation_key: Optional[str] = None
49+
translation_placeholders: Optional[dict[str, str]] = None
50+
translation_domain: Optional[str] = None
5151

5252

5353
class ErrorResponse(BaseModel):

tests/test_errors.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
UnauthorizedError,
2424
UnexpectedStatusCodeError,
2525
)
26+
from homeassistant_api.models.websocket import Error
2627
from homeassistant_api.processing import Processing
2728
from homeassistant_api.utils import prepare_entity_id
2829
from homeassistant_api.websocket import WebsocketClient
@@ -220,3 +221,12 @@ def test_exception_unexpected_status_code() -> None:
220221
def test_unkown_scheme() -> None:
221222
with pytest.raises(ValueError):
222223
Client("ftp://example.com", "token")
224+
225+
226+
def test_error_model_without_optional_fields() -> None:
227+
"""Tests that Error model accepts responses missing optional translation fields."""
228+
error = Error(code="invalid_format", message="required key not provided")
229+
assert error.code == "invalid_format"
230+
assert error.translation_key is None
231+
assert error.translation_placeholders is None
232+
assert error.translation_domain is None

0 commit comments

Comments
 (0)