Repository: home-assistant/core
File: tests/components/mastodon/test_init.py (Python)

Code before:
    # Check migration was successful
    assert config_entry.state is ConfigEntryState.LOADED
    assert config_entry.data == {
        CONF_BASE_URL: "https://mastodon.social",
        CONF_CLIENT_ID: "client_id",
        CONF_CLIENT_SECRET: "client_secret",
        CONF_ACCESS_TOKEN: "access_token",
    }
    assert config_entry.version == MastodonConfigFlow.VERSION
    assert config_entry.minor_version == MastodonConfigFlow.MINOR_VERSION
    assert config_entry.unique_id == "trwnh_mastodon_social"


async def test_coordinator_general_error(
    hass: HomeAssistant,
    mock_mastodon_client: AsyncMock,
    mock_config_entry: MockConfigEntry,
    freezer: FrozenDateTimeFactory,
) -> None:
    """Test general error during coordinator update makes entities unavailable."""
    await setup_integration(hass, mock_config_entry)
    assert mock_config_entry.state is ConfigEntryState.LOADED

    state = hass.states.get("binary_sensor.mastodon_trwnh_mastodon_social_bot")
    assert state is not None
    assert state.state == "on"

    mock_mastodon_client.account_verify_credentials.side_effect = MastodonError

    freezer.tick(timedelta(hours=1))
    async_fire_time_changed(hass)
    await hass.async_block_till_done()

    assert mock_config_entry.state is ConfigEntryState.LOADED

    state = hass.states.get("binary_sensor.mastodon_trwnh_mastodon_social_bot")
    assert state is not None
    assert state.state == "unavailable"

    # No reauth flow should be triggered (unlike auth errors)
    flows = hass.config_entries.flow.async_progress()
    assert len(flows) == 0


async def test_coordinator_auth_failure_triggers_reauth(
    hass: HomeAssistant,
    mock_mastodon_client: AsyncMock,
    mock_config_entry: MockConfigEntry,
    freezer: FrozenDateTimeFactory,
) -> None:
    """Test auth failure during coordinator update triggers reauth flow."""

Review comment (suggestion):
```suggestion
    assert state.state == STATE_ON
```

Code after:
        minor_version=1,
    )
    config_entry.add_to_hass(hass)
    assert await hass.config_entries.async_setup(config_entry.entry_id)
    await hass.async_block_till_done()

    # Check migration was successful
    assert config_entry.state is ConfigEntryState.LOADED
    assert config_entry.data == {
        CONF_BASE_URL: "https://mastodon.social",
        CONF_CLIENT_ID: "client_id",
        CONF_CLIENT_SECRET: "client_secret",
        CONF_ACCESS_TOKEN: "access_token",
    }
    assert config_entry.version == MastodonConfigFlow.VERSION
    assert config_entry.minor_version == MastodonConfigFlow.MINOR_VERSION
    assert config_entry.unique_id == "trwnh_mastodon_social"


async def test_coordinator_general_error(
    hass: HomeAssistant,
    mock_mastodon_client: AsyncMock,
    mock_config_entry: MockConfigEntry,
    freezer: FrozenDateTimeFactory,
) -> None:
    """Test general error during coordinator update makes entities unavailable."""
    await setup_integration(hass, mock_config_entry)
    assert mock_config_entry.state is ConfigEntryState.LOADED

    state = hass.states.get("binary_sensor.mastodon_trwnh_mastodon_social_bot")
    assert state is not None
    assert state.state == STATE_ON

    mock_mastodon_client.account_verify_credentials.side_effect = MastodonError

    freezer.tick(timedelta(hours=1))
    async_fire_time_changed(hass)
    await hass.async_block_till_done()

    assert mock_config_entry.state is ConfigEntryState.LOADED

    state = hass.states.get("binary_sensor.mastodon_trwnh_mastodon_social_bot")
    assert state is not None
    assert state.state == STATE_UNAVAILABLE

    # No reauth flow should be triggered (unlike auth errors)
    flows = hass.config_entries.flow.async_progress()
    assert len(flows) == 0


async def test_coordinator_auth_failure_triggers_reauth(