Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
9 changes: 5 additions & 4 deletions custom_components/hacs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,11 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->

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

hacs.set_stage(None)
hacs.disable_hacs(HacsDisabledReason.REMOVED)

hass.data.pop(DOMAIN, None)
# Only clean up if unload was successful
if unload_ok:
hacs.set_stage(None)
hacs.disable_hacs(HacsDisabledReason.REMOVED)
hass.data.pop(DOMAIN, None)

return unload_ok

Expand Down
5 changes: 4 additions & 1 deletion custom_components/hacs/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ async def async_setup_entry(
async_add_entities: AddEntitiesCallback,
) -> None:
"""Setup switch platform."""
hacs: HacsBase = hass.data[DOMAIN]
if (hacs := hass.data.get(DOMAIN)) is None:
# HACS is not properly initialized
return

async_add_entities(
HacsRepositoryPreReleaseSwitchEntity(hacs=hacs, repository=repository)
for repository in hacs.repositories.list_downloaded
Expand Down
5 changes: 4 additions & 1 deletion custom_components/hacs/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None:
"""Setup update platform."""
hacs: HacsBase = hass.data[DOMAIN]
if (hacs := hass.data.get(DOMAIN)) is None:
# HACS is not properly initialized
return

async_add_entities(
HacsRepositoryUpdateEntity(hacs=hacs, repository=repository)
for repository in hacs.repositories.list_downloaded
Expand Down
29 changes: 24 additions & 5 deletions custom_components/hacs/websocket/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ async def hacs_repositories_list(
msg: dict[str, Any],
) -> None:
"""List repositories."""
hacs: HacsBase = hass.data.get(DOMAIN)
if (hacs := hass.data.get(DOMAIN)) is None:
# HACS is not properly initialized
connection.send_error(msg["id"], "hacs_not_initialized", "HACS is not properly initialized")
return

connection.send_message(
websocket_api.result_message(
msg["id"],
Expand Down Expand Up @@ -91,7 +95,10 @@ async def hacs_repositories_clear_new(
msg: dict[str, Any],
) -> None:
"""Clear new repositories for specific categories."""
hacs: HacsBase = hass.data.get(DOMAIN)
if (hacs := hass.data.get(DOMAIN)) is None:
# HACS is not properly initialized
connection.send_error(msg["id"], "hacs_not_initialized", "HACS is not properly initialized")
return

if repo := msg.get("repository"):
repository = hacs.repositories.get_by_id(repo)
Expand Down Expand Up @@ -123,7 +130,11 @@ async def hacs_repositories_removed(
msg: dict[str, Any],
) -> None:
"""Get information about removed repositories."""
hacs: HacsBase = hass.data.get(DOMAIN)
if (hacs := hass.data.get(DOMAIN)) is None:
# HACS is not properly initialized
connection.send_error(msg["id"], "hacs_not_initialized", "HACS is not properly initialized")
return

content = []
for repo in hacs.repositories.list_removed:
if repo.repository not in hacs.common.ignored_repositories:
Expand All @@ -146,7 +157,11 @@ async def hacs_repositories_add(
msg: dict[str, Any],
) -> None:
"""Add custom repositoriy."""
hacs: HacsBase = hass.data.get(DOMAIN)
if (hacs := hass.data.get(DOMAIN)) is None:
# HACS is not properly initialized
connection.send_error(msg["id"], "hacs_not_initialized", "HACS is not properly initialized")
return

repository = regex.extract_repository_from_url(msg["repository"])
category = msg["category"]

Expand Down Expand Up @@ -207,7 +222,11 @@ async def hacs_repositories_remove(
msg: dict[str, Any],
) -> None:
"""Remove custom repositoriy."""
hacs: HacsBase = hass.data.get(DOMAIN)
if (hacs := hass.data.get(DOMAIN)) is None:
# HACS is not properly initialized
connection.send_error(msg["id"], "hacs_not_initialized", "HACS is not properly initialized")
return

repository = hacs.repositories.get_by_id(msg["repository"])

repository.remove()
Expand Down
Loading