diff --git a/tests/common.py b/tests/common.py index 24b9134c32e..149fb057a97 100644 --- a/tests/common.py +++ b/tests/common.py @@ -934,7 +934,7 @@ class MockConfigEntry(config_entries.ConfigEntry): kwargs["state"] = state super().__init__(**kwargs) if reason is not None: - self.reason = reason + object.__setattr__(self, "reason", reason) def add_to_hass(self, hass: HomeAssistant) -> None: """Test helper to add entry to hass.""" diff --git a/tests/components/automation/test_blueprint.py b/tests/components/automation/test_blueprint.py index 2976886881d..5df33f9b4b8 100644 --- a/tests/components/automation/test_blueprint.py +++ b/tests/components/automation/test_blueprint.py @@ -47,7 +47,7 @@ async def test_notify_leaving_zone( ) -> None: """Test notifying leaving a zone blueprint.""" config_entry = MockConfigEntry(domain="fake_integration", data={}) - config_entry.state = config_entries.ConfigEntryState.LOADED + config_entry.mock_state(hass, config_entries.ConfigEntryState.LOADED) config_entry.add_to_hass(hass) device = device_registry.async_get_or_create( diff --git a/tests/components/automation/test_init.py b/tests/components/automation/test_init.py index 3a8c12f735a..e75f41ad36b 100644 --- a/tests/components/automation/test_init.py +++ b/tests/components/automation/test_init.py @@ -1601,7 +1601,7 @@ async def test_extraction_functions( ) -> None: """Test extraction functions.""" config_entry = MockConfigEntry(domain="fake_integration", data={}) - config_entry.state = config_entries.ConfigEntryState.LOADED + config_entry.mock_state(hass, config_entries.ConfigEntryState.LOADED) config_entry.add_to_hass(hass) condition_device = device_registry.async_get_or_create( diff --git a/tests/components/device_automation/test_init.py b/tests/components/device_automation/test_init.py index 457b7ccbf9b..9a7d54fb690 100644 --- a/tests/components/device_automation/test_init.py +++ b/tests/components/device_automation/test_init.py @@ -976,7 +976,7 @@ async def test_automation_with_dynamically_validated_action( module.async_validate_action_config = AsyncMock() config_entry = MockConfigEntry(domain="fake_integration", data={}) - config_entry.state = config_entries.ConfigEntryState.LOADED + config_entry.mock_state(hass, config_entries.ConfigEntryState.LOADED) config_entry.add_to_hass(hass) device_entry = device_registry.async_get_or_create( config_entry_id=config_entry.entry_id, @@ -1078,7 +1078,7 @@ async def test_automation_with_dynamically_validated_condition( module.async_validate_condition_config = AsyncMock() config_entry = MockConfigEntry(domain="fake_integration", data={}) - config_entry.state = config_entries.ConfigEntryState.LOADED + config_entry.mock_state(hass, config_entries.ConfigEntryState.LOADED) config_entry.add_to_hass(hass) device_entry = device_registry.async_get_or_create( config_entry_id=config_entry.entry_id, @@ -1192,7 +1192,7 @@ async def test_automation_with_dynamically_validated_trigger( module.async_validate_trigger_config = AsyncMock(wraps=lambda hass, config: config) config_entry = MockConfigEntry(domain="fake_integration", data={}) - config_entry.state = config_entries.ConfigEntryState.LOADED + config_entry.mock_state(hass, config_entries.ConfigEntryState.LOADED) config_entry.add_to_hass(hass) device_entry = device_registry.async_get_or_create( config_entry_id=config_entry.entry_id, @@ -1295,7 +1295,7 @@ async def test_automation_with_bad_action( ) -> None: """Test automation with bad device action.""" config_entry = MockConfigEntry(domain="fake_integration", data={}) - config_entry.state = config_entries.ConfigEntryState.LOADED + config_entry.mock_state(hass, config_entries.ConfigEntryState.LOADED) config_entry.add_to_hass(hass) device_registry.async_get_or_create( config_entry_id=config_entry.entry_id, @@ -1329,7 +1329,7 @@ async def test_automation_with_bad_condition_action( ) -> None: """Test automation with bad device action.""" config_entry = MockConfigEntry(domain="fake_integration", data={}) - config_entry.state = config_entries.ConfigEntryState.LOADED + config_entry.mock_state(hass, config_entries.ConfigEntryState.LOADED) config_entry.add_to_hass(hass) device_registry.async_get_or_create( config_entry_id=config_entry.entry_id, @@ -1362,7 +1362,7 @@ async def test_automation_with_bad_condition( ) -> None: """Test automation with bad device condition.""" config_entry = MockConfigEntry(domain="fake_integration", data={}) - config_entry.state = config_entries.ConfigEntryState.LOADED + config_entry.mock_state(hass, config_entries.ConfigEntryState.LOADED) config_entry.add_to_hass(hass) device_registry.async_get_or_create( config_entry_id=config_entry.entry_id, @@ -1527,7 +1527,7 @@ async def test_automation_with_bad_sub_condition( ) -> None: """Test automation with bad device condition under and/or conditions.""" config_entry = MockConfigEntry(domain="fake_integration", data={}) - config_entry.state = config_entries.ConfigEntryState.LOADED + config_entry.mock_state(hass, config_entries.ConfigEntryState.LOADED) config_entry.add_to_hass(hass) device_registry.async_get_or_create( config_entry_id=config_entry.entry_id, @@ -1565,7 +1565,7 @@ async def test_automation_with_bad_trigger( ) -> None: """Test automation with bad device trigger.""" config_entry = MockConfigEntry(domain="fake_integration", data={}) - config_entry.state = config_entries.ConfigEntryState.LOADED + config_entry.mock_state(hass, config_entries.ConfigEntryState.LOADED) config_entry.add_to_hass(hass) device_registry.async_get_or_create( config_entry_id=config_entry.entry_id, diff --git a/tests/components/powerwall/test_config_flow.py b/tests/components/powerwall/test_config_flow.py index c10d8374bff..2f5ccf8ab80 100644 --- a/tests/components/powerwall/test_config_flow.py +++ b/tests/components/powerwall/test_config_flow.py @@ -497,7 +497,7 @@ async def test_dhcp_discovery_updates_unique_id_when_entry_is_failed( unique_id="1.2.3.4", ) entry.add_to_hass(hass) - entry.state = config_entries.ConfigEntryState.SETUP_ERROR + entry.mock_state(hass, config_entries.ConfigEntryState.SETUP_ERROR) mock_powerwall = await _mock_powerwall_site_name(hass, "Some site") with patch( diff --git a/tests/components/script/test_blueprint.py b/tests/components/script/test_blueprint.py index b248a3d7650..6c9f17f29b7 100644 --- a/tests/components/script/test_blueprint.py +++ b/tests/components/script/test_blueprint.py @@ -47,7 +47,7 @@ async def test_confirmable_notification( ) -> None: """Test confirmable notification blueprint.""" config_entry = MockConfigEntry(domain="fake_integration", data={}) - config_entry.state = config_entries.ConfigEntryState.LOADED + config_entry.mock_state(hass, config_entries.ConfigEntryState.LOADED) config_entry.add_to_hass(hass) frodo = device_registry.async_get_or_create( diff --git a/tests/components/script/test_init.py b/tests/components/script/test_init.py index 5f8e04d527a..2d21dc924dd 100644 --- a/tests/components/script/test_init.py +++ b/tests/components/script/test_init.py @@ -718,7 +718,7 @@ async def test_extraction_functions( ) -> None: """Test extraction functions.""" config_entry = MockConfigEntry(domain="fake_integration", data={}) - config_entry.state = config_entries.ConfigEntryState.LOADED + config_entry.mock_state(hass, config_entries.ConfigEntryState.LOADED) config_entry.add_to_hass(hass) device_in_both = device_registry.async_get_or_create( diff --git a/tests/components/websocket_api/test_commands.py b/tests/components/websocket_api/test_commands.py index 9db74b9a857..88fa914f5a7 100644 --- a/tests/components/websocket_api/test_commands.py +++ b/tests/components/websocket_api/test_commands.py @@ -2435,7 +2435,7 @@ async def test_execute_script_with_dynamically_validated_action( ) config_entry = MockConfigEntry(domain="fake_integration", data={}) - config_entry.state = config_entries.ConfigEntryState.LOADED + config_entry.mock_state(hass, config_entries.ConfigEntryState.LOADED) config_entry.add_to_hass(hass) device_entry = device_registry.async_get_or_create( config_entry_id=config_entry.entry_id, diff --git a/tests/components/zha/test_config_flow.py b/tests/components/zha/test_config_flow.py index 883df4aba94..29a996d4477 100644 --- a/tests/components/zha/test_config_flow.py +++ b/tests/components/zha/test_config_flow.py @@ -1587,7 +1587,7 @@ async def test_options_flow_defaults( mock_async_unload.assert_called_once_with(entry.entry_id) # Unload it ourselves - entry.state = config_entries.ConfigEntryState.NOT_LOADED + entry.mock_state(hass, config_entries.ConfigEntryState.NOT_LOADED) # Reconfigure ZHA assert result1["step_id"] == "prompt_migrate_or_reconfigure" @@ -1770,7 +1770,7 @@ async def test_options_flow_restarts_running_zha_if_cancelled( flow["flow_id"], user_input={} ) - entry.state = config_entries.ConfigEntryState.NOT_LOADED + entry.mock_state(hass, config_entries.ConfigEntryState.NOT_LOADED) assert result1["step_id"] == "prompt_migrate_or_reconfigure" result2 = await hass.config_entries.options.async_configure( @@ -1825,7 +1825,7 @@ async def test_options_flow_migration_reset_old_adapter( flow["flow_id"], user_input={} ) - entry.state = config_entries.ConfigEntryState.NOT_LOADED + entry.mock_state(hass, config_entries.ConfigEntryState.NOT_LOADED) assert result1["step_id"] == "prompt_migrate_or_reconfigure" result2 = await hass.config_entries.options.async_configure( diff --git a/tests/components/zha/test_radio_manager.py b/tests/components/zha/test_radio_manager.py index 67f2d0164d3..5671c9cd465 100644 --- a/tests/components/zha/test_radio_manager.py +++ b/tests/components/zha/test_radio_manager.py @@ -224,7 +224,7 @@ async def test_migrate_matching_port_config_entry_not_loaded( title="Test", ) config_entry.add_to_hass(hass) - config_entry.state = config_entries.ConfigEntryState.SETUP_IN_PROGRESS + config_entry.mock_state(hass, config_entries.ConfigEntryState.SETUP_IN_PROGRESS) migration_data = { "new_discovery_info": { @@ -284,7 +284,7 @@ async def test_migrate_matching_port_retry( title="Test", ) config_entry.add_to_hass(hass) - config_entry.state = config_entries.ConfigEntryState.SETUP_IN_PROGRESS + config_entry.mock_state(hass, config_entries.ConfigEntryState.SETUP_IN_PROGRESS) migration_data = { "new_discovery_info": { @@ -389,7 +389,7 @@ async def test_migrate_initiate_failure( title="Test", ) config_entry.add_to_hass(hass) - config_entry.state = config_entries.ConfigEntryState.SETUP_IN_PROGRESS + config_entry.mock_state(hass, config_entries.ConfigEntryState.SETUP_IN_PROGRESS) migration_data = { "new_discovery_info": { diff --git a/tests/helpers/test_script.py b/tests/helpers/test_script.py index b2508dc7163..3dfe8fdbad9 100644 --- a/tests/helpers/test_script.py +++ b/tests/helpers/test_script.py @@ -4633,7 +4633,7 @@ async def test_validate_action_config( """Validate action config.""" config_entry = MockConfigEntry(domain="fake_integration", data={}) - config_entry.state = config_entries.ConfigEntryState.LOADED + config_entry.mock_state(hass, config_entries.ConfigEntryState.LOADED) config_entry.add_to_hass(hass) mock_device = device_registry.async_get_or_create(