From a915a698866ef4e5ad248dd79ef4a03d819ef33d Mon Sep 17 00:00:00 2001 From: Shay Levy Date: Sat, 7 Feb 2026 19:46:28 +0200 Subject: [PATCH] Add coverage for Shelly init (#162497) --- homeassistant/components/shelly/__init__.py | 2 ++ tests/components/shelly/test_init.py | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/shelly/__init__.py b/homeassistant/components/shelly/__init__.py index 8e4480f92d7..f5cff59a2e9 100644 --- a/homeassistant/components/shelly/__init__.py +++ b/homeassistant/components/shelly/__init__.py @@ -175,6 +175,7 @@ async def _async_setup_block_entry( ) # https://github.com/home-assistant/core/pull/48076 if device_entry and entry.entry_id not in device_entry.config_entries: + LOGGER.debug("Detected first time setup for device %s", entry.title) device_entry = None sleep_period = entry.data.get(CONF_SLEEP_PERIOD) @@ -288,6 +289,7 @@ async def _async_setup_rpc_entry(hass: HomeAssistant, entry: ShellyConfigEntry) ) # https://github.com/home-assistant/core/pull/48076 if device_entry and entry.entry_id not in device_entry.config_entries: + LOGGER.debug("Detected first time setup for device %s", entry.title) device_entry = None sleep_period = entry.data.get(CONF_SLEEP_PERIOD) diff --git a/tests/components/shelly/test_init.py b/tests/components/shelly/test_init.py index 8457354351f..70f005e5934 100644 --- a/tests/components/shelly/test_init.py +++ b/tests/components/shelly/test_init.py @@ -37,12 +37,18 @@ from homeassistant.const import ( ) from homeassistant.core import HomeAssistant from homeassistant.helpers import issue_registry as ir -from homeassistant.helpers.device_registry import DeviceRegistry, format_mac +from homeassistant.helpers.device_registry import ( + CONNECTION_NETWORK_MAC, + DeviceRegistry, + format_mac, +) from homeassistant.helpers.entity_registry import EntityRegistry from homeassistant.setup import async_setup_component from . import MOCK_MAC, init_integration, mutate_rpc_device_status, register_sub_device +from tests.common import MockConfigEntry + async def test_custom_coap_port( hass: HomeAssistant, mock_block_device: Mock, caplog: pytest.LogCaptureFixture @@ -126,7 +132,15 @@ async def test_shared_device_mac( caplog: pytest.LogCaptureFixture, ) -> None: """Test first time shared device with another domain.""" + other_entry = MockConfigEntry(domain="other_domain", unique_id=MOCK_MAC) + other_entry.add_to_hass(hass) + device_registry.async_get_or_create( + config_entry_id=other_entry.entry_id, + connections={(CONNECTION_NETWORK_MAC, MOCK_MAC)}, + ) + await init_integration(hass, gen, sleep_period=1000) + assert "Detected first time setup for device" in caplog.text assert "will resume when device is online" in caplog.text