@@ -596,7 +596,7 @@ async def test_fail_non_numerical_number_settings(
596596 )
597597
598598
599- async def test_reload_when_labs_flag_changes (
599+ async def test_yaml_reload_when_labs_flag_changes (
600600 hass : HomeAssistant ,
601601 hass_ws_client : WebSocketGenerator ,
602602 hass_admin_user : MockUser ,
@@ -690,3 +690,67 @@ async def test_reload_when_labs_flag_changes(
690690 await hass .async_block_till_done ()
691691 assert hass .states .get ("sensor.bye" ).state == set_state
692692 last_state = set_state
693+
694+
695+ async def test_config_entry_reload_when_labs_flag_changes (
696+ hass : HomeAssistant ,
697+ hass_ws_client : WebSocketGenerator ,
698+ hass_admin_user : MockUser ,
699+ hass_read_only_user : MockUser ,
700+ ) -> None :
701+ """Test templates are reloaded when labs flag changes."""
702+ ws_client = await hass_ws_client (hass )
703+
704+ template_config_entry = MockConfigEntry (
705+ data = {},
706+ domain = DOMAIN ,
707+ options = {
708+ "name" : "hello" ,
709+ "template_type" : "sensor" ,
710+ "state" : "{{ 'foo' }}" ,
711+ },
712+ title = "My template" ,
713+ )
714+ template_config_entry .add_to_hass (hass )
715+ assert await hass .config_entries .async_setup (template_config_entry .entry_id )
716+ await hass .async_block_till_done ()
717+ assert await async_setup_component (hass , labs .DOMAIN , {})
718+
719+ assert hass .states .get ("sensor.hello" ) is not None
720+ assert hass .states .get ("sensor.hello" ).state == "foo"
721+
722+ # Check we reload whenever the labs flag is set, even if it's already enabled
723+ for enabled , set_state in (
724+ (True , "beer" ),
725+ (True , "is" ),
726+ (False , "very" ),
727+ (False , "good" ),
728+ ):
729+ hass .config_entries .async_update_entry (
730+ template_config_entry ,
731+ options = {
732+ "name" : "hello" ,
733+ "template_type" : "sensor" ,
734+ "state" : f"{{{{ '{ set_state } ' }}}}" ,
735+ },
736+ )
737+ with patch (
738+ "homeassistant.config.load_yaml_config_file" ,
739+ autospec = True ,
740+ return_value = {},
741+ ):
742+ await ws_client .send_json_auto_id (
743+ {
744+ "type" : "labs/update" ,
745+ "domain" : "automation" ,
746+ "preview_feature" : "new_triggers_conditions" ,
747+ "enabled" : enabled ,
748+ }
749+ )
750+
751+ msg = await ws_client .receive_json ()
752+ assert msg ["success" ]
753+ await hass .async_block_till_done ()
754+
755+ assert hass .states .get ("sensor.hello" ) is not None
756+ assert hass .states .get ("sensor.hello" ).state == set_state
0 commit comments