From c06ec1f78fb1fafa4d3da0737f7cc779514c8b57 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Sun, 26 Mar 2023 23:46:52 +0200 Subject: [PATCH] Improve onewire test coverage (#90184) --- tests/components/onewire/test_init.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/components/onewire/test_init.py b/tests/components/onewire/test_init.py index 5a69fb95e16..01c1841d178 100644 --- a/tests/components/onewire/test_init.py +++ b/tests/components/onewire/test_init.py @@ -1,4 +1,5 @@ """Tests for 1-Wire config flow.""" +from copy import deepcopy from unittest.mock import MagicMock, patch import aiohttp @@ -74,6 +75,27 @@ async def test_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> N assert not hass.data.get(DOMAIN) +async def test_update_options( + hass: HomeAssistant, config_entry: ConfigEntry, owproxy: MagicMock +) -> None: + """Test update options triggers reload.""" + await hass.config_entries.async_setup(config_entry.entry_id) + await hass.async_block_till_done() + + assert len(hass.config_entries.async_entries(DOMAIN)) == 1 + assert config_entry.state is ConfigEntryState.LOADED + assert owproxy.call_count == 1 + + new_options = deepcopy(dict(config_entry.options)) + new_options["device_options"].clear() + hass.config_entries.async_update_entry(config_entry, options=new_options) + await hass.async_block_till_done() + + assert len(hass.config_entries.async_entries(DOMAIN)) == 1 + assert config_entry.state is ConfigEntryState.LOADED + assert owproxy.call_count == 2 + + @patch("homeassistant.components.onewire.PLATFORMS", [Platform.SENSOR]) async def test_registry_cleanup( hass: HomeAssistant,