|
25 | 25 | from homeassistant_api.models import State |
26 | 26 | from homeassistant_api.models.config_entries import DisableEnableResult |
27 | 27 | from homeassistant_api.models.config_entries import FlowResult |
| 28 | +from homeassistant_api.models.entity_registry import EntityRegistryEntry |
| 29 | +from homeassistant_api.models.entity_registry import EntityRegistryEntryExtended |
| 30 | +from homeassistant_api.models.entity_registry import EntityRegistryUpdateResult |
28 | 31 | from homeassistant_api.models.states import Context |
29 | 32 | from homeassistant_api.models.websocket import AuthInvalid |
30 | 33 | from homeassistant_api.models.websocket import AuthOk |
|
48 | 51 | class WebsocketClient(BaseWebsocketClient): |
49 | 52 | _conn: ws.ClientConnection | None |
50 | 53 |
|
51 | | - def __init__(self, api_url: str, token: str) -> None: |
52 | | - super().__init__(api_url, token) |
| 54 | + def __init__(self, api_url: str, token: str, *, max_size: int = 2**24) -> None: |
| 55 | + super().__init__(api_url, token, max_size=max_size) |
53 | 56 | self._conn = None |
54 | 57 |
|
55 | | - self._id_counter = 0 |
56 | | - self._result_responses: dict[int, ResultResponse | None] = {} # id -> response |
57 | | - self._event_responses: dict[ |
58 | | - int, |
59 | | - list[EventResponse], |
60 | | - ] = {} # id -> [response, ...] |
61 | | - self._ping_responses: dict[int, PingResponse] = {} # id -> (sent, received) |
62 | | - |
63 | 58 | def __repr__(self) -> str: |
64 | 59 | return f"{self.__class__.__name__}({self.api_url!r})" |
65 | 60 |
|
66 | 61 | def __enter__(self) -> Self: |
67 | | - self._conn = ws.connect(self.api_url) |
| 62 | + self._conn = ws.connect(self.api_url, max_size=self.max_size) |
68 | 63 | self._conn.__enter__() |
69 | 64 | okay = self.authentication_phase() |
70 | 65 | logger.info("Authenticated with Home Assistant (%s)", okay.ha_version) |
@@ -649,6 +644,61 @@ def delete_entry_subentry(self, entry_id: str, subentry_id: str) -> None: |
649 | 644 | ), |
650 | 645 | ) |
651 | 646 |
|
| 647 | + # ── Entity Registry ───────────────────────────────────────── |
| 648 | + |
| 649 | + def list_entity_registry(self) -> tuple[EntityRegistryEntry, ...]: |
| 650 | + """ |
| 651 | + List all entity registry entries. |
| 652 | +
|
| 653 | + Sends command :code:`{"type": "config/entity_registry/list", ...}`. |
| 654 | + """ |
| 655 | + return tuple( |
| 656 | + EntityRegistryEntry.from_json(entry) |
| 657 | + for entry in self.recv_result_list( |
| 658 | + self.send("config/entity_registry/list"), |
| 659 | + ) |
| 660 | + ) |
| 661 | + |
| 662 | + def get_entity_registry_entry(self, entity_id: str) -> EntityRegistryEntryExtended: |
| 663 | + """ |
| 664 | + Get a single entity registry entry. |
| 665 | +
|
| 666 | + Sends command :code:`{"type": "config/entity_registry/get", ...}`. |
| 667 | + """ |
| 668 | + result = self.recv_result_dict( |
| 669 | + self.send("config/entity_registry/get", entity_id=entity_id), |
| 670 | + ) |
| 671 | + return EntityRegistryEntryExtended.from_json(result) |
| 672 | + |
| 673 | + def update_entity_registry_entry( |
| 674 | + self, |
| 675 | + entity_id: str, |
| 676 | + **kwargs: Any, |
| 677 | + ) -> EntityRegistryUpdateResult: |
| 678 | + """ |
| 679 | + Update an entity registry entry. |
| 680 | +
|
| 681 | + Sends command :code:`{"type": "config/entity_registry/update", ...}`. |
| 682 | + """ |
| 683 | + result = self.recv_result_dict( |
| 684 | + self.send( |
| 685 | + "config/entity_registry/update", |
| 686 | + entity_id=entity_id, |
| 687 | + **kwargs, |
| 688 | + ), |
| 689 | + ) |
| 690 | + return EntityRegistryUpdateResult.from_json(result) |
| 691 | + |
| 692 | + def remove_entity_registry_entry(self, entity_id: str) -> None: |
| 693 | + """ |
| 694 | + Remove an entity from the entity registry. |
| 695 | +
|
| 696 | + Sends command :code:`{"type": "config/entity_registry/remove", ...}`. |
| 697 | + """ |
| 698 | + self.recv( |
| 699 | + self.send("config/entity_registry/remove", entity_id=entity_id), |
| 700 | + ) |
| 701 | + |
652 | 702 | @contextlib.contextmanager |
653 | 703 | def listen_config_entries( |
654 | 704 | self, |
|
0 commit comments