From 8d97fafb2dd917ba15ba072267ca0a00052b4d76 Mon Sep 17 00:00:00 2001 From: "Mr. Bubbles" Date: Wed, 21 Aug 2024 14:03:40 +0200 Subject: [PATCH] Add tests for IronOS integration (#123078) Add tests --- tests/components/iron_os/test_init.py | 34 +++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/components/iron_os/test_init.py b/tests/components/iron_os/test_init.py index fb0a782ea36..f7db2a813ec 100644 --- a/tests/components/iron_os/test_init.py +++ b/tests/components/iron_os/test_init.py @@ -11,6 +11,40 @@ from homeassistant.core import HomeAssistant from tests.common import MockConfigEntry +@pytest.mark.usefixtures("mock_pynecil", "ble_device") +async def test_setup_and_unload( + hass: HomeAssistant, + config_entry: MockConfigEntry, +) -> None: + """Test integration setup and unload.""" + + config_entry.add_to_hass(hass) + await hass.config_entries.async_setup(config_entry.entry_id) + await hass.async_block_till_done() + + assert config_entry.state is ConfigEntryState.LOADED + + await hass.config_entries.async_unload(config_entry.entry_id) + await hass.async_block_till_done() + + assert config_entry.state is ConfigEntryState.NOT_LOADED + + +@pytest.mark.usefixtures("ble_device") +async def test_update_data_config_entry_not_ready( + hass: HomeAssistant, + config_entry: MockConfigEntry, + mock_pynecil: AsyncMock, +) -> None: + """Test config entry not ready.""" + mock_pynecil.get_live_data.side_effect = CommunicationError + config_entry.add_to_hass(hass) + await hass.config_entries.async_setup(config_entry.entry_id) + await hass.async_block_till_done() + + assert config_entry.state is ConfigEntryState.SETUP_RETRY + + @pytest.mark.usefixtures("ble_device") async def test_setup_config_entry_not_ready( hass: HomeAssistant,