Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove code paths only used in non-experimental mode #3728

Merged
merged 5 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ repos:
args:
- --quiet-level=2
- --ignore-words-list=hass,ba,fo
- --skip=custom_components/hacs/utils/default.repositories
- --skip=tests/fixtures/*

- id: isort
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ venv

# Frontend are downloaded on release
custom_components/hacs/hacs_frontend
custom_components/hacs/hacs_frontend_experimental

# Translation files
custom_components/hacs/translations
Expand Down
15 changes: 4 additions & 11 deletions custom_components/hacs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
from .utils.version import version_left_higher_or_equal_then_right
from .websocket import async_register_websocket_commands

PLATFORMS = [Platform.UPDATE]


async def _async_initialize_integration(
hass: HomeAssistant,
Expand Down Expand Up @@ -134,17 +136,12 @@ async def async_startup():
hacs.disable_hacs(HacsDisabledReason.RESTORE)
return False

if not hacs.configuration.experimental:
can_update = await hacs.async_can_update()
hacs.log.debug("Can update %s repositories", can_update)

hacs.set_active_categories()

async_register_websocket_commands(hass)
await async_register_frontend(hass, hacs)

if hacs.configuration.experimental:
await hass.config_entries.async_forward_entry_setups(config_entry, [Platform.UPDATE])
await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)

hacs.set_stage(HacsStage.SETUP)
if hacs.system.disabled:
Expand Down Expand Up @@ -210,11 +207,7 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
except AttributeError:
pass

platforms = []
if hacs.configuration.experimental:
platforms.append("update")

unload_ok = await hass.config_entries.async_unload_platforms(config_entry, platforms)
unload_ok = await hass.config_entries.async_unload_platforms(config_entry, PLATFORMS)

hacs.set_stage(None)
hacs.disable_hacs(HacsDisabledReason.REMOVED)
Expand Down
170 changes: 26 additions & 144 deletions custom_components/hacs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
HomeAssistantCoreRepositoryException,
)
from .repositories import REPOSITORY_CLASSES
from .utils.decode import decode_content
from .utils.file_system import async_exists
from .utils.json import json_loads
from .utils.logger import LOGGER
Expand Down Expand Up @@ -122,7 +121,6 @@ class HacsConfiguration:
country: str = "ALL"
debug: bool = False
dev: bool = False
experimental: bool = True
frontend_repo_url: str = ""
frontend_repo: str = ""
netdaemon_path: str = "netdaemon/apps/"
Expand Down Expand Up @@ -493,18 +491,6 @@ async def async_can_update(self) -> int:

return 0

async def async_github_get_hacs_default_file(self, filename: str) -> list:
"""Get the content of a default file."""
response = await self.async_github_api_method(
method=self.githubapi.repos.contents.get,
repository=HacsGitHubRepo.DEFAULT,
path=filename,
)
if response is None:
return []

return json_loads(decode_content(response.data.content))

async def async_github_api_method(
self,
method: Callable[[], Awaitable[TV]],
Expand Down Expand Up @@ -633,27 +619,13 @@ async def startup_tasks(self, _=None) -> None:
)
break

if not self.configuration.experimental:
self.recurring_tasks.append(
async_track_time_interval(
self.hass, self.async_update_downloaded_repositories, timedelta(hours=48)
)
)
self.recurring_tasks.append(
async_track_time_interval(
self.hass,
self.async_update_all_repositories,
timedelta(hours=96),
)
)
else:
self.recurring_tasks.append(
async_track_time_interval(
self.hass,
self.async_load_hacs_from_github,
timedelta(hours=48),
)
self.recurring_tasks.append(
async_track_time_interval(
self.hass,
self.async_load_hacs_from_github,
timedelta(hours=48),
)
)
ludeeus marked this conversation as resolved.
Show resolved Hide resolved
ludeeus marked this conversation as resolved.
Show resolved Hide resolved

self.recurring_tasks.append(
async_track_time_interval(
Expand Down Expand Up @@ -693,7 +665,6 @@ async def startup_tasks(self, _=None) -> None:

await self.async_handle_removed_repositories()
await self.async_get_all_category_repositories()
await self.async_update_downloaded_repositories()

self.set_stage(HacsStage.RUNNING)

Expand Down Expand Up @@ -763,9 +734,6 @@ async def async_download_file(

async def async_recreate_entities(self) -> None:
"""Recreate entities."""
if not self.configuration.experimental:
return

platforms = [Platform.UPDATE]

await self.hass.config_entries.async_unload_platforms(
Expand All @@ -784,12 +752,9 @@ def async_dispatch(self, signal: HacsDispatchEvent, data: dict | None = None) ->
def set_active_categories(self) -> None:
"""Set the active categories."""
self.common.categories = set()
for category in (HacsCategory.INTEGRATION, HacsCategory.PLUGIN):
for category in (HacsCategory.INTEGRATION, HacsCategory.PLUGIN, HacsCategory.TEMPLATE):
ludeeus marked this conversation as resolved.
Show resolved Hide resolved
self.enable_hacs_category(HacsCategory(category))

if self.configuration.experimental:
self.enable_hacs_category(HacsCategory.TEMPLATE)

if (
HacsCategory.PYTHON_SCRIPT in self.hass.config.components
or self.repositories.category_downloaded(HacsCategory.PYTHON_SCRIPT)
Expand All @@ -814,7 +779,7 @@ def set_active_categories(self) -> None:

async def async_load_hacs_from_github(self, _=None) -> None:
"""Load HACS from GitHub."""
if self.configuration.experimental and self.status.inital_fetch_done:
if self.status.inital_fetch_done:
return

try:
Expand All @@ -826,7 +791,7 @@ async def async_load_hacs_from_github(self, _=None) -> None:
default=True,
)
repository = self.repositories.get_by_full_name(HacsGitHubRepo.INTEGRATION)
elif self.configuration.experimental and not self.status.startup:
elif not self.status.startup:
self.log.error("Scheduling update of hacs/integration")
self.queue.add(repository.common_update())
if repository is None:
Expand Down Expand Up @@ -856,8 +821,6 @@ async def async_get_all_category_repositories(self, _=None) -> None:
await asyncio.gather(
*[
self.async_get_category_repositories_experimental(category)
if self.configuration.experimental
else self.async_get_category_repositories(HacsCategory(category))
for category in self.common.categories or []
]
)
Expand Down Expand Up @@ -914,51 +877,6 @@ async def async_get_category_repositories_experimental(self, category: str) -> N
self.async_dispatch(HacsDispatchEvent.REPOSITORY, {})
self.coordinators[category].async_update_listeners()

async def async_get_category_repositories(self, category: HacsCategory) -> None:
"""Get repositories from category."""
if self.system.disabled:
return
try:
repositories = await self.async_github_get_hacs_default_file(category)
except HacsException:
return

for repo in repositories:
if self.common.renamed_repositories.get(repo):
repo = self.common.renamed_repositories[repo]
if self.repositories.is_removed(repo):
continue
if repo in self.common.archived_repositories:
continue
repository = self.repositories.get_by_full_name(repo)
if repository is not None:
self.repositories.mark_default(repository)
if self.status.new and self.configuration.dev:
# Force update for new installations
self.queue.add(repository.common_update())
continue

self.queue.add(
self.async_register_repository(
repository_full_name=repo,
category=category,
default=True,
)
)

async def async_update_all_repositories(self, _=None) -> None:
"""Update all repositories."""
if self.system.disabled:
return
self.log.debug("Starting recurring background task for all repositories")

for repository in self.repositories.list_all:
if repository.data.category in self.common.categories:
self.queue.add(repository.common_update())

self.async_dispatch(HacsDispatchEvent.REPOSITORY, {"action": "reload"})
self.log.debug("Recurring background task for all repositories done")

async def async_check_rate_limit(self, _=None) -> None:
"""Check rate limit."""
if not self.system.disabled or self.system.disabled_reason != HacsDisabledReason.RATE_LIMIT:
Expand Down Expand Up @@ -1011,12 +929,7 @@ async def async_handle_removed_repositories(self, _=None) -> None:
self.log.info("Loading removed repositories")

try:
if self.configuration.experimental:
removed_repositories = await self.data_client.get_data("removed", validate=True)
else:
removed_repositories = await self.async_github_get_hacs_default_file(
HacsCategory.REMOVED
)
removed_repositories = await self.data_client.get_data("removed", validate=True)
except HacsException:
return

Expand All @@ -1031,21 +944,20 @@ async def async_handle_removed_repositories(self, _=None) -> None:
continue
if repository.data.installed:
if removed.removal_type != "critical":
if self.configuration.experimental:
async_create_issue(
hass=self.hass,
domain=DOMAIN,
issue_id=f"removed_{repository.data.id}",
is_fixable=False,
issue_domain=DOMAIN,
severity=IssueSeverity.WARNING,
translation_key="removed",
translation_placeholders={
"name": repository.data.full_name,
"reason": removed.reason,
"repositry_id": repository.data.id,
},
)
async_create_issue(
hass=self.hass,
domain=DOMAIN,
issue_id=f"removed_{repository.data.id}",
is_fixable=False,
issue_domain=DOMAIN,
severity=IssueSeverity.WARNING,
translation_key="removed",
translation_placeholders={
"name": repository.data.full_name,
"reason": removed.reason,
"repositry_id": repository.data.id,
},
)
self.log.warning(
"You have '%s' installed with HACS "
"this repository has been removed from HACS, please consider removing it. "
Expand All @@ -1060,21 +972,9 @@ async def async_handle_removed_repositories(self, _=None) -> None:
if need_to_save:
await self.data.async_write()

async def async_update_downloaded_repositories(self, _=None) -> None:
"""Execute the task."""
if self.system.disabled or self.configuration.experimental:
return
self.log.info("Starting recurring background task for downloaded repositories")

for repository in self.repositories.list_downloaded:
if repository.data.category in self.common.categories:
self.queue.add(repository.update_repository(ignore_issues=True))

self.log.debug("Recurring background task for downloaded repositories done")

async def async_update_downloaded_custom_repositories(self, _=None) -> None:
"""Execute the task."""
if self.system.disabled or not self.configuration.experimental:
if self.system.disabled:
ludeeus marked this conversation as resolved.
Show resolved Hide resolved
return
self.log.info("Starting recurring background task for downloaded custom repositories")

Expand Down Expand Up @@ -1120,10 +1020,7 @@ async def async_handle_critical_repositories(self, _=None) -> None:
was_installed = False

try:
if self.configuration.experimental:
critical = await self.data_client.get_data("critical", validate=True)
else:
critical = await self.async_github_get_hacs_default_file("critical")
critical = await self.data_client.get_data("critical", validate=True)
except (GitHubNotModifiedException, HacsNotModifiedException):
return
except HacsException:
Expand Down Expand Up @@ -1199,18 +1096,3 @@ async def async_setup_frontend_endpoint_plugin(self) -> None:
)

self.status.active_frontend_endpoint_plugin = True

async def async_setup_frontend_endpoint_themes(self) -> None:
"""Setup the http endpoints for themes if its not already handled."""
if (
self.configuration.experimental
or self.status.active_frontend_endpoint_theme
or not await async_exists(self.hass, self.hass.config.path("themes"))
):
return

self.log.info("Setting up themes endpoint")
# Register themes
self.hass.http.register_static_path(f"{URL_BASE}/themes", self.hass.config.path("themes"))

self.status.active_frontend_endpoint_theme = True
1 change: 0 additions & 1 deletion custom_components/hacs/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ async def async_get_config_entry_diagnostics(
"country",
"debug",
"dev",
"experimental",
"netdaemon",
"python_script",
"release_limit",
Expand Down
3 changes: 0 additions & 3 deletions custom_components/hacs/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ def add_extra_js_url(hass: HomeAssistant, url: str, es5: bool = False) -> None:
async def async_register_frontend(hass: HomeAssistant, hacs: HacsBase) -> None:
"""Register the frontend."""

# Setup themes endpoint if needed
await hacs.async_setup_frontend_endpoint_themes()

# Register frontend
if hacs.configuration.dev and (frontend_path := os.getenv("HACS_FRONTEND_DIR")):
hacs.log.warning(
Expand Down
Loading
Loading