mirror of
https://github.com/home-assistant/core.git
synced 2026-12-03 12:21:04 -04:00
Allow removing a Marketplace theme without a known folder (#186926)
This commit is contained in:
@@ -58,6 +58,21 @@ class ThemeRepository(Repository):
|
||||
configuration = self.marketplace.configuration
|
||||
return f"{self.marketplace.core.config_path}/{configuration.theme_path}"
|
||||
|
||||
@override
|
||||
async def remove_local_directory(self) -> bool:
|
||||
"""Remove the theme, unless it is not known which folder holds it."""
|
||||
# The custom integration did not store the file name, and with the repository
|
||||
# gone from GitHub nothing tells it anymore. Guessing could hit another theme.
|
||||
if not self.directory:
|
||||
self.logger.warning(
|
||||
"%s Not known which folder in %s holds this theme, remove it by hand",
|
||||
self.string,
|
||||
self._category_directory(),
|
||||
)
|
||||
return True
|
||||
|
||||
return await super().remove_local_directory()
|
||||
|
||||
@override
|
||||
def _tree_of_the_content(self) -> list[GitHubGitTreeEntryModel]:
|
||||
"""Return the tree, or only the theme file when the root is the content."""
|
||||
|
||||
@@ -61,6 +61,27 @@ async def test_removing_a_theme_keeps_a_handwritten_theme(
|
||||
assert handwritten.exists()
|
||||
|
||||
|
||||
async def test_removing_a_theme_without_a_known_folder(
|
||||
marketplace: MarketplaceManager,
|
||||
config_dir: Path,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test a theme HACS stored without its file name can still be removed."""
|
||||
repository = marketplace.repositories.get_by_id(THEME_ID)
|
||||
repository.data.installed = True
|
||||
repository.data.file_name = ""
|
||||
repository.data.directory = None
|
||||
other_theme = config_dir / "themes/other/other.yaml"
|
||||
other_theme.parent.mkdir(parents=True)
|
||||
other_theme.write_text("Other Theme:\n primary-color: red\n")
|
||||
|
||||
await repository.uninstall()
|
||||
|
||||
assert not repository.data.installed
|
||||
assert other_theme.exists()
|
||||
assert "remove it by hand" in caplog.text
|
||||
|
||||
|
||||
async def test_template_refresh_keeps_the_installed_file_name(
|
||||
marketplace: MarketplaceManager,
|
||||
) -> None:
|
||||
|
||||
Reference in New Issue
Block a user