11"""Tests for the SolarEdge integration."""
22
3- from unittest .mock import AsyncMock , Mock
3+ from unittest .mock import AsyncMock , Mock , patch
44
55from aiohttp import ClientError
66
1515from tests .common import MockConfigEntry
1616
1717
18+ @patch (
19+ "homeassistant.config_entries.ConfigEntries.async_unload_platforms" ,
20+ return_value = True ,
21+ )
1822async def test_setup_unload_api_key (
19- recorder_mock : Recorder , hass : HomeAssistant , solaredge_api : Mock
23+ mock_unload_platforms : AsyncMock ,
24+ recorder_mock : Recorder ,
25+ hass : HomeAssistant ,
26+ solaredge_api : Mock ,
2027) -> None :
2128 """Test successful setup and unload of a config entry with API key."""
2229 entry = MockConfigEntry (
@@ -33,11 +40,21 @@ async def test_setup_unload_api_key(
3340
3441 assert await hass .config_entries .async_unload (entry .entry_id )
3542 await hass .async_block_till_done ()
43+
44+ # Unloading should be attempted because sensors were set up.
45+ mock_unload_platforms .assert_awaited_once ()
3646 assert entry .state is ConfigEntryState .NOT_LOADED
3747
3848
49+ @patch (
50+ "homeassistant.config_entries.ConfigEntries.async_unload_platforms" ,
51+ return_value = True ,
52+ )
3953async def test_setup_unload_web_login (
40- recorder_mock : Recorder , hass : HomeAssistant , solaredge_web_api : AsyncMock
54+ mock_unload_platforms : AsyncMock ,
55+ recorder_mock : Recorder ,
56+ hass : HomeAssistant ,
57+ solaredge_web_api : AsyncMock ,
4158) -> None :
4259 """Test successful setup and unload of a config entry with web login."""
4360 entry = MockConfigEntry (
@@ -59,10 +76,18 @@ async def test_setup_unload_web_login(
5976
6077 assert await hass .config_entries .async_unload (entry .entry_id )
6178 await hass .async_block_till_done ()
79+
80+ # Unloading should NOT be attempted because sensors were not set up.
81+ mock_unload_platforms .assert_not_called ()
6282 assert entry .state is ConfigEntryState .NOT_LOADED
6383
6484
85+ @patch (
86+ "homeassistant.config_entries.ConfigEntries.async_unload_platforms" ,
87+ return_value = True ,
88+ )
6589async def test_setup_unload_both (
90+ mock_unload_platforms : AsyncMock ,
6691 recorder_mock : Recorder ,
6792 hass : HomeAssistant ,
6893 solaredge_api : Mock ,
@@ -90,6 +115,8 @@ async def test_setup_unload_both(
90115
91116 assert await hass .config_entries .async_unload (entry .entry_id )
92117 await hass .async_block_till_done ()
118+
119+ mock_unload_platforms .assert_awaited_once ()
93120 assert entry .state is ConfigEntryState .NOT_LOADED
94121
95122
0 commit comments