Migrate internal ZHA data to a dataclasses (#100127)

* Cache device triggers on startup

* reorg zha init

* don't reuse gateway

* don't nuke yaml configuration

* review comments

* Add unit tests

* Do not cache device and entity registries

* [WIP] Wrap ZHA data in a dataclass

* [WIP] Get unit tests passing

* Use a helper function for getting the gateway object to fix annotations

* Remove `bridge_id`

* Fix typing issues with entity references in group websocket info

* Use `Platform` instead of `str` for entity platform matching

* Use `get_zha_gateway` in a few more places

* Fix flaky unit test

* Use `slots` for ZHA data

Co-authored-by: J. Nick Koston <nick@koston.org>

---------

Co-authored-by: David F. Mulcahey <david.mulcahey@icloud.com>
Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
puddly 2023-09-11 21:39:33 +02:00 committed by GitHub
parent 5c206de906
commit cbb28b6943
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
44 changed files with 317 additions and 288 deletions

View file

@ -35,11 +35,10 @@ from .core.const import (
CONF_ALARM_ARM_REQUIRES_CODE,
CONF_ALARM_FAILED_TRIES,
CONF_ALARM_MASTER_CODE,
DATA_ZHA,
SIGNAL_ADD_ENTITIES,
ZHA_ALARM_OPTIONS,
)
from .core.helpers import async_get_zha_config_value
from .core.helpers import async_get_zha_config_value, get_zha_data
from .core.registries import ZHA_ENTITIES
from .entity import ZhaEntity
@ -65,7 +64,8 @@ async def async_setup_entry(
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up the Zigbee Home Automation alarm control panel from config entry."""
entities_to_create = hass.data[DATA_ZHA][Platform.ALARM_CONTROL_PANEL]
zha_data = get_zha_data(hass)
entities_to_create = zha_data.platforms[Platform.ALARM_CONTROL_PANEL]
unsub = async_dispatcher_connect(
hass,