Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions homeassistant_api/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@
__all__ = (
"BaseModel",
"DatetimeIsoField",
"TranslationPlaceholders",
)

DatetimeIsoField = Annotated[
datetime,
PlainSerializer(lambda x: x.isoformat(), return_type=str, when_used="json"),
]

# Home Assistant placeholder values are not guaranteed to be strings.
TranslationPlaceholders = dict[str, Any]


class BaseModel(PydanticBaseModel):
"""Base model that all Library Models inherit from."""
Expand Down
20 changes: 13 additions & 7 deletions homeassistant_api/models/config_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Any

from .base import BaseModel
from .base import TranslationPlaceholders


class FlowResultType(StrEnum):
Expand All @@ -30,6 +31,7 @@ class DiscoveryKey(BaseModel):
class FlowContext(BaseModel):
"""Base flow context"""

# No longer sent since Home Assistant 2026.11, only populated by older servers.
show_advanced_options: bool | None = None
source: str

Expand All @@ -39,10 +41,12 @@ class ConfigFlowContext(FlowContext):

alternative_domain: str | None = None
configuration_url: str | None = None
# No longer sent since Home Assistant 2026.11, only populated by older servers.
confirm_only: bool | None = None
discovery_key: DiscoveryKey
discovery_key: DiscoveryKey | None = None
dismiss_protected: bool | None = None
entry_id: str | None = None
title_placeholders: dict[str, str] | None = None
title_placeholders: TranslationPlaceholders | None = None
unique_id: str | None = None


Expand All @@ -52,7 +56,7 @@ class FlowResult(BaseModel):
context: ConfigFlowContext
data_schema: Any | None = None
data: dict[str, Any] | None = None
description_placeholders: dict[str, str] | None = None
description_placeholders: TranslationPlaceholders | None = None
description: str | None = None
errors: dict[str, str] | None = None
extra: str | None = None
Expand All @@ -66,6 +70,7 @@ class FlowResult(BaseModel):
reason: str | None = None
required: bool | None = None
result: Any | None = None
sort: bool | None = None
step_id: str | None = None
title: str | None = None
translation_domain: str | None = None
Expand Down Expand Up @@ -128,10 +133,11 @@ class ConfigEntry(BaseModel):
supported_subentry_types: dict[str, dict[str, bool]]
pref_disable_new_entities: bool
pref_disable_polling: bool
disabled_by: ConfigEntryDisabler | None
reason: str | None
error_reason_translation_key: str | None
error_reason_translation_placeholders: dict[str, Any] | None
disabled_by: ConfigEntryDisabler | None = None
reason: str | None = None
error_reason_translation_domain: str | None = None
error_reason_translation_key: str | None = None
error_reason_translation_placeholders: TranslationPlaceholders | None = None
num_subentries: int


Expand Down
23 changes: 17 additions & 6 deletions homeassistant_api/models/entity_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ class EntityCategory(StrEnum):
DIAGNOSTIC = "diagnostic"


class NextNamePart(StrEnum):
"""Next registry entry whose name is used to build the full entity name."""

AREA = "area"
DEVICE = "device"
PARENT_DEVICE = "parent_device"


class EntityRegistryEntry(BaseModel):
"""An entity registry entry as returned by ``config/entity_registry/list``."""

Expand All @@ -47,13 +55,15 @@ class EntityRegistryEntry(BaseModel):
disabled_by: EntityDisabledBy | None = None
entity_category: EntityCategory | None = None
entity_id: str
has_entity_name: bool
# No longer sent since Home Assistant 2026.11, only populated by older servers.
has_entity_name: bool | None = None
hidden_by: EntityHiddenBy | None = None
icon: str | None = None
id: str
labels: set[str] = Field(default_factory=set)
modified_at: DatetimeIsoField
name: str | None = None
next_name_part: NextNamePart | None = None
options: dict[str, Any] = Field(default_factory=dict)
original_name: str | None = None
platform: str
Expand All @@ -64,7 +74,8 @@ class EntityRegistryEntry(BaseModel):
class EntityRegistryEntryExtended(EntityRegistryEntry):
"""Extended entity registry entry as returned by ``config/entity_registry/get``."""

aliases: list[str] | tuple[None] = Field(default_factory=list)
# ``None`` represents the computed entity name.
aliases: list[str | None] = Field(default_factory=list)
capabilities: dict[str, Any] | None = None
device_class: str | None = None
original_device_class: str | None = None
Expand All @@ -82,11 +93,11 @@ class EntityRegistryUpdateResult(BaseModel):
class EntityRegistryUpdateParams(TypedDict):
"""Parameters used in ``config/entity_registry/update``."""

aliases: NotRequired[list[str]]
aliases: NotRequired[list[str | None]]
area_id: NotRequired[str | None]
categories: NotRequired[dict[str, str]]
categories: NotRequired[dict[str, str | None]]
device_class: NotRequired[str | None]
disabled_by: NotRequired[EntityHiddenBy | None]
disabled_by: NotRequired[EntityDisabledBy | None]
entity_id: str
hidden_by: NotRequired[EntityHiddenBy | None]
icon: NotRequired[str | None]
Expand All @@ -95,4 +106,4 @@ class EntityRegistryUpdateParams(TypedDict):
new_entity_id: NotRequired[str]
# options and options_domain are inclusive, meaning only both or none of them have to be defined
options_domain: NotRequired[str]
options: NotRequired[dict[str, Any]]
options: NotRequired[dict[str, Any] | None]
3 changes: 2 additions & 1 deletion homeassistant_api/models/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from .base import BaseModel
from .base import DatetimeIsoField
from .base import TranslationPlaceholders
from .config_entries import ConfigEntryEvent
from .states import Context

Expand Down Expand Up @@ -47,7 +48,7 @@ class Error(BaseModel):
code: str
message: str
translation_key: str | None = None
translation_placeholders: dict[str, str] | None = None
translation_placeholders: TranslationPlaceholders | None = None
translation_domain: str | None = None


Expand Down
Original file line number Diff line number Diff line change
@@ -1,53 +1,44 @@
{
"nimax_version": "1.0.0",
"http_interactions": [],
"websocket_sessions": [
{
"uri": "ws://localhost:8123/api/websocket",
"handshake_recorded_at": "2026-04-21T02:58:30.337336+00:00",
"protocol": null,
"frames": [
{
"direction": "recv",
"type": "text",
"payload": "{\"type\":\"auth_required\",\"ha_version\":\"2026.4.3\"}",
"offset_ms": 0
"payload": "{\"type\":\"auth_required\",\"ha_version\":\"2026.11.3\"}"
},
{
"direction": "send",
"type": "text",
"payload": "{\"access_token\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJkMDE4YjQ4YzMyZTE0ODNhYjY2ZWQzOTZmYzg3ZDAyNiIsImlhdCI6MTY3ODU3NDUwMSwiZXhwIjoxOTkzOTM0NTAxfQ.fyhnfwpont4uE0gn46_Ut_pPmyn4QWv0MDaVAei2PPk\", \"type\": \"auth\"}",
"offset_ms": 0
"payload": "{\"access_token\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJkMDE4YjQ4YzMyZTE0ODNhYjY2ZWQzOTZmYzg3ZDAyNiIsImlhdCI6MTY3ODU3NDUwMSwiZXhwIjoxOTkzOTM0NTAxfQ.fyhnfwpont4uE0gn46_Ut_pPmyn4QWv0MDaVAei2PPk\", \"type\": \"auth\"}"
},
{
"direction": "recv",
"type": "text",
"payload": "{\"type\":\"auth_ok\",\"ha_version\":\"2026.4.3\"}",
"offset_ms": 0
"payload": "{\"type\":\"auth_ok\",\"ha_version\":\"2026.11.3\"}"
},
{
"direction": "send",
"type": "text",
"payload": "{\"features\": {}, \"id\": 1, \"type\": \"supported_features\"}",
"offset_ms": 1
"payload": "{\"features\": {}, \"id\": 1, \"type\": \"supported_features\"}"
},
{
"direction": "recv",
"type": "text",
"payload": "{\"id\":1,\"type\":\"result\",\"success\":true,\"result\":null}",
"offset_ms": 1
"payload": "{\"id\":1,\"type\":\"result\",\"success\":true,\"result\":null}"
},
{
"direction": "send",
"type": "text",
"payload": "{\"id\": 2, \"type\": \"ping\"}",
"offset_ms": 1
"payload": "{\"id\": 2, \"type\": \"ping\"}"
},
{
"direction": "recv",
"type": "text",
"payload": "{\"id\":2,\"type\":\"pong\"}",
"offset_ms": 1
"payload": "{\"id\":2,\"type\":\"pong\"}"
}
]
}
Expand Down
11 changes: 3 additions & 8 deletions tests/cassettes/test_client/test_custom_async_session.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"nimax_version": "1.0.0",
"http_interactions": [
{
"request": {
Expand Down Expand Up @@ -30,22 +29,18 @@
"SAMEORIGIN"
],
"Content-Length": [
"34"
],
"Content-Encoding": [
"deflate"
"26"
],
"Date": [
"Tue, 21 Apr 2026 02:58:30 GMT"
"Thu, 03 Dec 2026 10:10:11 GMT"
]
},
"body": {
"string": "{\"message\":\"API running.\"}"
},
"protocol": null,
"url": "http://localhost:8123/api/"
},
"recorded_at": "2026-04-21T02:58:30.320437+00:00"
}
}
],
"websocket_sessions": []
Expand Down
11 changes: 3 additions & 8 deletions tests/cassettes/test_client/test_custom_session.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"nimax_version": "1.0.0",
"http_interactions": [
{
"request": {
Expand Down Expand Up @@ -30,22 +29,18 @@
"SAMEORIGIN"
],
"Content-Length": [
"34"
],
"Content-Encoding": [
"deflate"
"26"
],
"Date": [
"Tue, 21 Apr 2026 02:58:30 GMT"
"Thu, 03 Dec 2026 10:10:11 GMT"
]
},
"body": {
"string": "{\"message\":\"API running.\"}"
},
"protocol": null,
"url": "http://localhost:8123/api/"
},
"recorded_at": "2026-04-21T02:58:30.308844+00:00"
}
}
],
"websocket_sessions": []
Expand Down
11 changes: 3 additions & 8 deletions tests/cassettes/test_client/test_default_async_session.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"nimax_version": "1.0.0",
"http_interactions": [
{
"request": {
Expand Down Expand Up @@ -30,22 +29,18 @@
"SAMEORIGIN"
],
"Content-Length": [
"34"
],
"Content-Encoding": [
"deflate"
"26"
],
"Date": [
"Tue, 21 Apr 2026 02:58:30 GMT"
"Thu, 03 Dec 2026 10:10:11 GMT"
]
},
"body": {
"string": "{\"message\":\"API running.\"}"
},
"protocol": null,
"url": "http://localhost:8123/api/"
},
"recorded_at": "2026-04-21T02:58:30.324739+00:00"
}
}
],
"websocket_sessions": []
Expand Down
11 changes: 3 additions & 8 deletions tests/cassettes/test_client/test_default_session.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"nimax_version": "1.0.0",
"http_interactions": [
{
"request": {
Expand Down Expand Up @@ -30,22 +29,18 @@
"SAMEORIGIN"
],
"Content-Length": [
"34"
],
"Content-Encoding": [
"deflate"
"26"
],
"Date": [
"Tue, 21 Apr 2026 02:58:30 GMT"
"Thu, 03 Dec 2026 10:10:11 GMT"
]
},
"body": {
"string": "{\"message\":\"API running.\"}"
},
"protocol": null,
"url": "http://localhost:8123/api/"
},
"recorded_at": "2026-04-21T02:58:30.313718+00:00"
}
}
],
"websocket_sessions": []
Expand Down
Loading
Loading