Skip to content

Commit 90a14ca

Browse files
committed
Add get entry subentry method
1 parent 6443a29 commit 90a14ca

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

homeassistant_api/models/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
ConfigEntryDisabler,
77
ConfigEntryState,
88
ConfigFlowContext,
9+
ConfigSubEntry,
910
DisableEnableResult,
1011
DiscoveryKey,
1112
FlowContext,
@@ -43,4 +44,5 @@
4344
"ConfigEntryDisabler",
4445
"ConfigEntryState",
4546
"ConfigEntry",
47+
"ConfigSubEntry",
4648
)

homeassistant_api/models/config_entries.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import asyncio
44
from enum import Enum
5-
from typing import Any, Container, Dict, Tuple, Union
5+
from typing import Any, Container, Dict, Optional, Tuple, Union
66

77
from .base import BaseModel
88

@@ -134,3 +134,12 @@ class ConfigEntry(BaseModel):
134134
error_reason_translation_key: str | None
135135
error_reason_translation_placeholders: dict[str, Any] | None
136136
num_subentries: int
137+
138+
139+
class ConfigSubEntry(BaseModel):
140+
"""A configuration sub-entry. This is the model that Home Assistant returns, but not what is used internally."""
141+
142+
subentry_id: str
143+
subentry_type: str
144+
title: str
145+
unique_id: Optional[str]

homeassistant_api/websocket.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from homeassistant_api.models import (
77
ConfigEntry,
8+
ConfigSubEntry,
89
DisableEnableResult,
910
Domain,
1011
Entity,
@@ -266,6 +267,24 @@ def get_config_entries(
266267
)
267268
)
268269

270+
# TODO: config_entries/subscribe
271+
272+
# UNTESTED
273+
def get_entry_subentries(self, entry_id: str) -> Tuple[ConfigSubEntry, ...]:
274+
"""Get an entry's sub-entries."""
275+
return tuple(
276+
ConfigSubEntry.from_json(sub_entry)
277+
for sub_entry in cast(
278+
list[dict[str, JSONType]],
279+
cast(
280+
ResultResponse,
281+
self.recv(
282+
self.send("config_entries/subentries/list", entry_id=entry_id)
283+
),
284+
).result,
285+
)
286+
)
287+
269288
def trigger_service(
270289
self,
271290
domain: str,

0 commit comments

Comments
 (0)