Merge pull request #322011 from kkoniuszy/add-home-assistant-custom-components-spook

home-assistant-custom-components.spook: init at 3.0.1
This commit is contained in:
Martin Weinelt 2024-06-23 22:24:14 +02:00 committed by GitHub
commit 242807e0e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 163 additions and 4 deletions

View File

@ -10618,6 +10618,11 @@
github = "kkharji";
githubId = 65782666;
};
kkoniuszy = {
name = "Kacper Koniuszy";
github = "kkoniuszy";
githubId = 120419423;
};
klden = {
name = "Kenzyme Le";
email = "kl@kenzymele.com";

View File

@ -518,8 +518,9 @@ in {
# recreate symlinks for desired components
declare -a components=(${escapeShellArgs cfg.customComponents})
for component in "''${components[@]}"; do
path="$(dirname $(find "$component" -name "manifest.json"))"
ln -fns "$path" "${cfg.configDir}/custom_components/"
readarray -t manifests < <(find "$component" -name manifest.json)
readarray -t paths < <(dirname "''${manifests[@]}")
ln -fns "''${paths[@]}" "${cfg.configDir}/custom_components/"
done
'';
in

View File

@ -44,6 +44,8 @@ in {
# test loading custom components
customComponents = with pkgs.home-assistant-custom-components; [
prometheus_sensor
# tests loading multiple components from a single package
spook
];
# test loading lovelace modules
@ -179,7 +181,8 @@ in {
with subtest("Check that custom components get installed"):
hass.succeed("test -f ${configDir}/custom_components/prometheus_sensor/manifest.json")
hass.wait_until_succeeds("journalctl -u home-assistant.service | grep -q 'We found a custom integration prometheus_sensor which has not been tested by Home Assistant'")
for integration in ("prometheus_sensor", "spook", "spook_inverse"):
hass.wait_until_succeeds(f"journalctl -u home-assistant.service | grep -q 'We found a custom integration {integration} which has not been tested by Home Assistant'")
with subtest("Check that lovelace modules are referenced and fetchable"):
hass.succeed("grep -q 'mini-graph-card-bundle.js' '${configDir}/configuration.yaml'")
@ -228,7 +231,8 @@ in {
cursor = get_journal_cursor()
hass.succeed("${system}/specialisation/removeCustomThings/bin/switch-to-configuration test")
hass.fail("grep -q 'mini-graph-card-bundle.js' '${configDir}/ui-lovelace.yaml'")
hass.fail("test -f ${configDir}/custom_components/prometheus_sensor/manifest.json")
for integration in ("prometheus_sensor", "spook", "spook_inverse"):
hass.fail(f"test -f ${configDir}/custom_components/{integration}/manifest.json")
wait_for_homeassistant(cursor)
with subtest("Check that no errors were logged"):

View File

@ -48,6 +48,8 @@
smartthinq-sensors = callPackage ./smartthinq-sensors {};
spook = callPackage ./spook {};
tuya_local = callPackage ./tuya_local {};
waste_collection_schedule = callPackage ./waste_collection_schedule {};

View File

@ -0,0 +1,38 @@
{
lib,
buildHomeAssistantComponent,
fetchFromGitHub,
pillow,
fnv-hash-fast,
psutil-home-assistant,
sqlalchemy,
}:
buildHomeAssistantComponent rec {
owner = "frenck";
domain = "spook";
version = "3.0.1";
src = fetchFromGitHub {
inherit owner;
repo = domain;
rev = "refs/tags/v${version}";
hash = "sha256-ChHsevryWuim8BEFqXVkCOW9fGMrt5vol+B2SreMUws=";
};
patches = [./remove-sub-integration-symlink-hack.patch];
dependencies = [
pillow
fnv-hash-fast
psutil-home-assistant
sqlalchemy
];
meta = {
changelog = "https://github.com/frenck/spook/releases/tag/v${version}";
description = "Toolbox for Home Assistant";
homepage = "https://spook.boo/";
license = lib.licenses.mit;
maintainers = with lib.maintainers; [kkoniuszy];
};
}

View File

@ -0,0 +1,109 @@
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.