diff --git a/tests/components/knx/conftest.py b/tests/components/knx/conftest.py index a06206fd9829..f2feaac2f08d 100644 --- a/tests/components/knx/conftest.py +++ b/tests/components/knx/conftest.py @@ -29,6 +29,7 @@ from homeassistant.components.knx.const import ( ) from homeassistant.components.knx.project import STORAGE_KEY as KNX_PROJECT_STORAGE_KEY from homeassistant.core import HomeAssistant +from homeassistant.helpers.typing import ConfigType from homeassistant.setup import async_setup_component from tests.common import MockConfigEntry, load_fixture @@ -57,7 +58,9 @@ class KNXTestKit: for attribute, value in attributes.items(): assert test_state.attributes.get(attribute) == value - async def setup_integration(self, config): + async def setup_integration( + self, config: ConfigType, add_entry_to_hass: bool = True + ) -> None: """Create the KNX integration.""" async def patch_xknx_start(): @@ -87,12 +90,14 @@ class KNXTestKit: self.xknx = args[0] return DEFAULT + if add_entry_to_hass: + self.mock_config_entry.add_to_hass(self.hass) + with patch( "xknx.xknx.knx_interface_factory", return_value=knx_ip_interface_mock(), side_effect=fish_xknx, ): - self.mock_config_entry.add_to_hass(self.hass) await async_setup_component(self.hass, KNX_DOMAIN, {KNX_DOMAIN: config}) await self.hass.async_block_till_done() diff --git a/tests/components/knx/test_telegrams.py b/tests/components/knx/test_telegrams.py index d523a0d646af..be24b3cd3ec1 100644 --- a/tests/components/knx/test_telegrams.py +++ b/tests/components/knx/test_telegrams.py @@ -105,11 +105,12 @@ async def test_remove_telegam_history( ): """Test telegram history removal when configured to size 0.""" hass_storage["knx/telegrams_history.json"] = {"version": 1, "data": MOCK_TELEGRAMS} + knx.mock_config_entry.add_to_hass(hass) hass.config_entries.async_update_entry( knx.mock_config_entry, data=knx.mock_config_entry.data | {CONF_KNX_TELEGRAM_LOG_SIZE: 0}, ) - await knx.setup_integration({}) + await knx.setup_integration({}, add_entry_to_hass=False) # Store.async_remove() is mocked by hass_storage - check that data was removed. assert "knx/telegrams_history.json" not in hass_storage assert not hass.data[DOMAIN].telegrams.recent_telegrams