From adf0d0cf308a6cd3a57462d691f335a32665b75d Mon Sep 17 00:00:00 2001 From: Benjamin Auquite Date: Wed, 26 Apr 2023 21:10:52 -0500 Subject: [PATCH] Auto reload YAML config changes (#573) * Update __init__.py * Update __init__.py * skip installing codecov * remove in CI * test 2023.4.6 --------- Co-authored-by: Bas Nijholt --- .github/workflows/install_dependencies/action.yml | 2 ++ .github/workflows/pytest.yaml | 2 +- custom_components/adaptive_lighting/__init__.py | 12 +++++++++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/workflows/install_dependencies/action.yml b/.github/workflows/install_dependencies/action.yml index df0bee8a..3041698b 100644 --- a/.github/workflows/install_dependencies/action.yml +++ b/.github/workflows/install_dependencies/action.yml @@ -36,6 +36,8 @@ runs: run: | echo "::warning::### WARNING! Deprecation warnings muted with option '--use-pep517' please address this at some point in pytest.yaml. ###" pip install -r core/requirements.txt --use-pep517 + # because they decided to pull codecov the package from PyPI... + sed -i '/codecov/d' core/requirements_test.txt pip install -r core/requirements_test.txt --use-pep517 pip install -e core/ --use-pep517 pip install ulid-transform # this is in Adaptive-lighting's manifest.json diff --git a/.github/workflows/pytest.yaml b/.github/workflows/pytest.yaml index cea75602..394acef3 100644 --- a/.github/workflows/pytest.yaml +++ b/.github/workflows/pytest.yaml @@ -14,7 +14,7 @@ jobs: fail-fast: false matrix: python-version: ["3.10"] - core-version: ["2023.2.5", "2023.3.6", "2023.4.0", "dev"] + core-version: ["2023.2.5", "2023.3.6", "2023.4.6", "dev"] steps: - name: Check out code from GitHub uses: actions/checkout@v3 diff --git a/custom_components/adaptive_lighting/__init__.py b/custom_components/adaptive_lighting/__init__.py index dc928a6b..07a0a758 100755 --- a/custom_components/adaptive_lighting/__init__.py +++ b/custom_components/adaptive_lighting/__init__.py @@ -6,7 +6,6 @@ from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry from homeassistant.const import CONF_SOURCE from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.reload import async_setup_reload_service import voluptuous as vol from .const import ( @@ -36,10 +35,13 @@ CONFIG_SCHEMA = vol.Schema( ) +async def reload_configuration_yaml(event: dict, hass: HomeAssistant): + """Reload configuration.yaml.""" + await hass.services.async_call("homeassistant", "check_config", {}) + + async def async_setup(hass: HomeAssistant, config: dict[str, Any]): """Import integration from config.""" - # This will reload any changes the user made to any YAML configurations. - await async_setup_reload_service(hass, DOMAIN, PLATFORMS) if DOMAIN in config: for entry in config[DOMAIN]: @@ -55,6 +57,10 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry): """Set up the component.""" data = hass.data.setdefault(DOMAIN, {}) + # This will reload any changes the user made to any YAML configurations. + # Called during 'quick reload' or hass.reload_config_entry + hass.bus.async_listen("hass.config.entry_updated", reload_configuration_yaml) + undo_listener = config_entry.add_update_listener(async_update_options) data[config_entry.entry_id] = {UNDO_UPDATE_LISTENER: undo_listener} for platform in PLATFORMS: