83627f9931
GitOrigin-RevId: 2893f56de08021cffd9b6b6dfc70fd9ccd51eb60
109 lines
4.3 KiB
Diff
109 lines
4.3 KiB
Diff
diff --git a/custom_components/spook/__init__.py b/custom_components/spook/__init__.py
|
|
index 213fb2c..c7dc299 100644
|
|
--- a/custom_components/spook/__init__.py
|
|
+++ b/custom_components/spook/__init__.py
|
|
@@ -23,8 +23,6 @@ from .templating import SpookTemplateFunctionManager
|
|
from .util import (
|
|
async_ensure_template_environments_exists,
|
|
async_forward_setup_entry,
|
|
- link_sub_integrations,
|
|
- unlink_sub_integrations,
|
|
)
|
|
|
|
if TYPE_CHECKING:
|
|
@@ -34,48 +32,6 @@ if TYPE_CHECKING:
|
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
"""Set up from a config entry."""
|
|
- # Symlink all sub integrations from Spook to the parent integrations folder
|
|
- # if one is missing, we have to restart Home Assistant.
|
|
- # This is a workaround for the fact that Home Assistant doesn't support
|
|
- # sub integrations.
|
|
- if await hass.async_add_executor_job(link_sub_integrations, hass):
|
|
- LOGGER.debug("Newly symlinked sub integrations, restarting Home Assistant")
|
|
-
|
|
- @callback
|
|
- def _restart(_: Event | None = None) -> None:
|
|
- """Restart Home Assistant."""
|
|
- hass.data["homeassistant_stop"] = asyncio.create_task(
|
|
- hass.async_stop(RESTART_EXIT_CODE),
|
|
- )
|
|
-
|
|
- # User asked to restart Home Assistant in the config flow.
|
|
- if hass.data.get(DOMAIN) == "Boo!":
|
|
- _restart()
|
|
- return False
|
|
-
|
|
- # Should be OK to restart. Better to do it before anything else started.
|
|
- if hass.state == CoreState.starting:
|
|
- _restart()
|
|
- return False
|
|
-
|
|
- # If all other fails, but we are not running yet... wait for it.
|
|
- if hass.state == CoreState.not_running:
|
|
- # Listen to both... just in case.
|
|
- hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, _restart)
|
|
- hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STARTED, _restart)
|
|
- return False
|
|
-
|
|
- LOGGER.info(
|
|
- "Home Assistant needs to be restarted in for Spook to complete setting up",
|
|
- )
|
|
- ir.async_create_issue(
|
|
- hass=hass,
|
|
- domain=DOMAIN,
|
|
- issue_id="restart_required",
|
|
- is_fixable=True,
|
|
- severity=ir.IssueSeverity.WARNING,
|
|
- translation_key="restart_required",
|
|
- )
|
|
|
|
# Ensure template environments exists
|
|
async_ensure_template_environments_exists(hass)
|
|
@@ -120,4 +76,3 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
|
|
async def async_remove_entry(hass: HomeAssistant, _: ConfigEntry) -> None:
|
|
"""Remove a config entry."""
|
|
- await hass.async_add_executor_job(unlink_sub_integrations, hass)
|
|
diff --git a/custom_components/spook/util.py b/custom_components/spook/util.py
|
|
index 32e9bd2..845d463 100644
|
|
--- a/custom_components/spook/util.py
|
|
+++ b/custom_components/spook/util.py
|
|
@@ -104,37 +104,6 @@ async def async_forward_platform_entry_setups_to_ectoplasm(
|
|
)
|
|
|
|
|
|
-def link_sub_integrations(hass: HomeAssistant) -> bool:
|
|
- """Link Spook sub integrations."""
|
|
- LOGGER.debug("Linking up Spook sub integrations")
|
|
-
|
|
- changes = False
|
|
- for manifest in Path(__file__).parent.rglob("integrations/*/manifest.json"):
|
|
- LOGGER.debug("Linking Spook sub integration: %s", manifest.parent.name)
|
|
- dest = Path(hass.config.config_dir) / "custom_components" / manifest.parent.name
|
|
- if not dest.exists():
|
|
- src = (
|
|
- Path(hass.config.config_dir)
|
|
- / "custom_components"
|
|
- / DOMAIN
|
|
- / "integrations"
|
|
- / manifest.parent.name
|
|
- )
|
|
- dest.symlink_to(src)
|
|
- changes = True
|
|
- return changes
|
|
-
|
|
-
|
|
-def unlink_sub_integrations(hass: HomeAssistant) -> None:
|
|
- """Unlink Spook sub integrations."""
|
|
- LOGGER.debug("Unlinking Spook sub integrations")
|
|
- for manifest in Path(__file__).parent.rglob("integrations/*/manifest.json"):
|
|
- LOGGER.debug("Unlinking Spook sub integration: %s", manifest.parent.name)
|
|
- dest = Path(hass.config.config_dir) / "custom_components" / manifest.parent.name
|
|
- if dest.exists():
|
|
- dest.unlink()
|
|
-
|
|
-
|
|
@callback
|
|
def async_ensure_template_environments_exists(hass: HomeAssistant) -> None:
|
|
"""Ensure default template environments exist.
|