Skip to content

Commit

Permalink
Wait for config entry platforms in KNX (#77437)
Browse files Browse the repository at this point in the history
  • Loading branch information
farmio authored Aug 28, 2022
1 parent eab0ff5 commit 441d7c0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion homeassistant/components/knx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
create_knx_exposure(hass, knx_module.xknx, expose_config)
)

hass.config_entries.async_setup_platforms(
await hass.config_entries.async_forward_entry_setups(
entry,
[
platform
Expand Down
14 changes: 8 additions & 6 deletions tests/components/knx/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,21 @@ def assert_state(self, entity_id: str, state: str, **attributes) -> None:
async def setup_integration(self, config):
"""Create the KNX integration."""

def disable_rate_limiter():
"""Disable rate limiter for tests."""
async def patch_xknx_start():
"""Patch `xknx.start` for unittests."""
# after XKNX.__init__() to not overwrite it by the config entry again
# before StateUpdater starts to avoid slow down of tests
self.xknx.rate_limit = 0
# set XknxConnectionState.CONNECTED to avoid `unavailable` entities at startup
# and start StateUpdater. This would be awaited on normal startup too.
await self.xknx.connection_manager.connection_state_changed(
XknxConnectionState.CONNECTED
)

def knx_ip_interface_mock():
"""Create a xknx knx ip interface mock."""
mock = Mock()
mock.start = AsyncMock(side_effect=disable_rate_limiter)
mock.start = AsyncMock(side_effect=patch_xknx_start)
mock.stop = AsyncMock()
mock.send_telegram = AsyncMock(side_effect=self._outgoing_telegrams.put)
return mock
Expand All @@ -81,9 +86,6 @@ def fish_xknx(*args, **kwargs):
):
self.mock_config_entry.add_to_hass(self.hass)
await async_setup_component(self.hass, KNX_DOMAIN, {KNX_DOMAIN: config})
await self.xknx.connection_manager.connection_state_changed(
XknxConnectionState.CONNECTED
)
await self.hass.async_block_till_done()

########################
Expand Down

0 comments on commit 441d7c0

Please sign in to comment.