4343_LOGGER = logging .getLogger (__name__ )
4444
4545
46+ @pytest .mark .parametrize ("config" , [{}])
4647async def test_entry_setup_and_unload (
4748 hass : HomeAssistant ,
49+ setup_lovelace_ui ,
4850 mock_lock_config_entry ,
4951 lock_code_manager_config_entry ,
5052):
@@ -202,13 +204,15 @@ async def test_reauth(hass: HomeAssistant, lock_code_manager_config_entry):
202204 )
203205
204206
205- async def test_resource_already_loaded (
207+ @pytest .mark .parametrize ("config" , [{}])
208+ async def test_resource_already_loaded_ui (
206209 hass : HomeAssistant ,
210+ setup_lovelace_ui ,
207211 mock_lock_config_entry ,
208212 caplog : pytest .LogCaptureFixture ,
209213 monkeypatch : pytest .MonkeyPatch ,
210214):
211- """Test when strategy resource is already loaded."""
215+ """Test when strategy resource is already loaded in UI mode ."""
212216 resources = hass .data [LL_DOMAIN ].get ("resources" )
213217 assert resources
214218 await resources .async_load ()
@@ -231,3 +235,61 @@ async def test_resource_already_loaded(
231235 assert "already registered" in caplog .text
232236
233237 await hass .config_entries .async_unload (config_entry .entry_id )
238+
239+
240+ @pytest .mark .parametrize (
241+ "config" ,
242+ [{"mode" : "yaml" , "resources" : [{"type" : "module" , "url" : STRATEGY_PATH }]}],
243+ )
244+ async def test_resource_already_loaded_yaml (
245+ hass : HomeAssistant ,
246+ setup_lovelace_ui ,
247+ mock_lock_config_entry ,
248+ monkeypatch : pytest .MonkeyPatch ,
249+ caplog : pytest .LogCaptureFixture ,
250+ ):
251+ """Test when strategy resource is already loaded in YAML mode."""
252+ monkeypatch .setattr (
253+ "custom_components.lock_code_manager.helpers.INTEGRATIONS_CLASS_MAP" ,
254+ {"test" : MockLCMLock },
255+ )
256+
257+ config_entry = MockConfigEntry (
258+ domain = DOMAIN , data = BASE_CONFIG , unique_id = "Mock Title"
259+ )
260+ config_entry .add_to_hass (hass )
261+ await hass .config_entries .async_setup (config_entry .entry_id )
262+ await hass .async_block_till_done ()
263+
264+ assert "already registered" in caplog .text
265+
266+ await hass .config_entries .async_unload (config_entry .entry_id )
267+
268+
269+ @pytest .mark .parametrize (
270+ "config" ,
271+ [{"mode" : "yaml" , "resources" : [{"type" : "module" , "url" : "fake_module.js" }]}],
272+ )
273+ async def test_resource_not_loaded_yaml (
274+ hass : HomeAssistant ,
275+ setup_lovelace_ui ,
276+ mock_lock_config_entry ,
277+ monkeypatch : pytest .MonkeyPatch ,
278+ caplog : pytest .LogCaptureFixture ,
279+ ):
280+ """Test when strategy resource is not loaded in YAML mode."""
281+ monkeypatch .setattr (
282+ "custom_components.lock_code_manager.helpers.INTEGRATIONS_CLASS_MAP" ,
283+ {"test" : MockLCMLock },
284+ )
285+
286+ config_entry = MockConfigEntry (
287+ domain = DOMAIN , data = BASE_CONFIG , unique_id = "Mock Title"
288+ )
289+ config_entry .add_to_hass (hass )
290+ await hass .config_entries .async_setup (config_entry .entry_id )
291+ await hass .async_block_till_done ()
292+
293+ assert "module can't automatically be registered" in caplog .text
294+
295+ await hass .config_entries .async_unload (config_entry .entry_id )
0 commit comments