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 YAML configuration #3565

Merged
merged 5 commits into from
May 24, 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
34 changes: 1 addition & 33 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,42 +149,10 @@ jobs:
retention-days: 3


validate-homeassistant:
emontnemery marked this conversation as resolved.
Show resolved Hide resolved
needs:
- "preflight"
runs-on: ubuntu-latest
name: With Home Assistant ${{ matrix.channel }}
strategy:
matrix:
channel:
- "stable"
- "beta"
- "dev"
- "2023.6.0"
steps:
- name: Checkout the repository
uses: actions/checkout@v4.1.6

- name: Copy sample configuration for Home Assistant
run: |
mkdir ./test_configuration
bash scripts/install/frontend
cp -r ./custom_components ./test_configuration
echo "default_config:" >> ./test_configuration/configuration.yaml
echo "hacs:" >> ./test_configuration/configuration.yaml
echo " token: CHANGE_ME" >> ./test_configuration/configuration.yaml

- name: Setup Home Assistant
id: homeassistant
uses: ludeeus/setup-homeassistant@main
with:
tag: ${{ matrix.channel }}
config-dir: test_configuration

notify_on_failure:
runs-on: ubuntu-latest
name: Trigger Discord notification when jobs fail
needs: ["preflight","validate-hassfest", "validate-hacs", "validate-homeassistant"]
needs: ["preflight","validate-hassfest", "validate-hacs"]
steps:
- name: Send notification
if: ${{ always() && contains(join(needs.*.result, ','), 'failure') && github.event_name == 'schedule' }}
Expand Down
72 changes: 15 additions & 57 deletions custom_components/hacs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from __future__ import annotations

import os
from typing import Any

from aiogithubapi import AIOGitHubAPIException, GitHub, GitHubAPI
from aiogithubapi.const import ACCEPT_HEADERS
Expand All @@ -20,7 +19,6 @@
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.discovery import async_load_platform
from homeassistant.helpers.event import async_call_later
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
from homeassistant.helpers.start import async_at_start
from homeassistant.loader import async_get_integration
import voluptuous as vol
Expand All @@ -30,48 +28,33 @@
from .data_client import HacsDataClient
from .enums import ConfigurationType, HacsDisabledReason, HacsStage, LovelaceMode
from .frontend import async_register_frontend
from .utils.configuration_schema import hacs_config_combined
from .utils.data import HacsData
from .utils.logger import LOGGER
from .utils.queue_manager import QueueManager
from .utils.version import version_left_higher_or_equal_then_right
from .websocket import async_register_websocket_commands

CONFIG_SCHEMA = vol.Schema({DOMAIN: hacs_config_combined()}, extra=vol.ALLOW_EXTRA)
ludeeus marked this conversation as resolved.
Show resolved Hide resolved


async def async_initialize_integration(
async def _async_initialize_integration(
hass: HomeAssistant,
*,
config_entry: ConfigEntry | None = None,
config: dict[str, Any] | None = None,
config_entry: ConfigEntry,
) -> bool:
"""Initialize the integration"""
hass.data[DOMAIN] = hacs = HacsBase()
hacs.enable_hacs()

if config is not None:
hacs.configuration.update_from_dict(
{
"config_type": ConfigurationType.YAML,
**config[DOMAIN],
"config": config[DOMAIN],
}
)

if config_entry is not None:
if config_entry.source == SOURCE_IMPORT:
hass.async_create_task(hass.config_entries.async_remove(config_entry.entry_id))
return False
if config_entry.source == SOURCE_IMPORT:
# Import is not supported
hass.async_create_task(hass.config_entries.async_remove(config_entry.entry_id))
return False

hacs.configuration.update_from_dict(
{
"config_entry": config_entry,
"config_type": ConfigurationType.CONFIG_ENTRY,
**config_entry.data,
**config_entry.options,
}
)
hacs.configuration.update_from_dict(
{
"config_entry": config_entry,
"config_type": ConfigurationType.CONFIG_ENTRY,
**config_entry.data,
**config_entry.options,
}
)

integration = await async_get_integration(hass, DOMAIN)

Expand Down Expand Up @@ -213,35 +196,10 @@ async def async_try_startup(_=None):
return True


async def async_setup(hass: HomeAssistant, config: dict[str, Any]) -> bool:
"""Set up this integration using yaml."""
if DOMAIN not in config:
return True

async_create_issue(
hass,
DOMAIN,
"deprecated_yaml_configuration",
is_fixable=False,
issue_domain=DOMAIN,
severity=IssueSeverity.WARNING,
translation_key="deprecated_yaml_configuration",
learn_more_url="https://hacs.xyz/docs/configuration/options",
)
LOGGER.warning(
"YAML configuration of HACS is deprecated and will be "
"removed in version 2.0.0, there will be no automatic "
"import of this. "
"Please remove it from your configuration, "
"restart Home Assistant and use the UI to configure it instead."
)
return await async_initialize_integration(hass=hass, config=config)


async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
"""Set up this integration using UI."""
config_entry.async_on_unload(config_entry.add_update_listener(async_reload_entry))
setup_result = await async_initialize_integration(hass=hass, config_entry=config_entry)
setup_result = await _async_initialize_integration(hass=hass, config_entry=config_entry)
hacs: HacsBase = hass.data[DOMAIN]
return setup_result and not hacs.system.disabled

Expand Down
3 changes: 1 addition & 2 deletions custom_components/hacs/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from .base import HacsBase
from .const import DOMAIN
from .utils.configuration_schema import TOKEN


async def async_get_config_entry_diagnostics(
Expand Down Expand Up @@ -79,4 +78,4 @@ async def async_get_config_entry_diagnostics(
except GitHubException as exception:
data["rate_limit"] = str(exception)

return async_redact_data(data, (TOKEN,))
return async_redact_data(data, ("token",))
4 changes: 0 additions & 4 deletions custom_components/hacs/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@
"removed": {
"title": "Repository removed from HACS",
"description": "Because {reason}, `{name}` has been removed from HACS. Please visit the [HACS Panel](/hacs/repository/{repositry_id}) to remove it."
},
"deprecated_yaml_configuration": {
"title": "YAML configuration is deprecated",
"description": "YAML configuration of HACS is deprecated and will be removed in version 2.0.0, there will be no automatic import of this.\nPlease remove it from your configuration, restart Home Assistant and use the UI to configure it instead."
}
}
}
61 changes: 0 additions & 61 deletions custom_components/hacs/utils/configuration_schema.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
"""HACS Configuration Schemas."""
# pylint: disable=dangerous-default-value
import voluptuous as vol

from ..const import LOCALE

# Configuration:
TOKEN = "token"
SIDEPANEL_TITLE = "sidepanel_title"
SIDEPANEL_ICON = "sidepanel_icon"
FRONTEND_REPO = "frontend_repo"
FRONTEND_REPO_URL = "frontend_repo_url"
APPDAEMON = "appdaemon"
NETDAEMON = "netdaemon"

Expand All @@ -18,57 +11,3 @@
DEBUG = "debug"
RELEASE_LIMIT = "release_limit"
EXPERIMENTAL = "experimental"

# Config group
PATH_OR_URL = "frontend_repo_path_or_url"


def hacs_base_config_schema(config: dict = {}) -> dict:
"""Return a shcema configuration dict for HACS."""
if not config:
config = {
TOKEN: "xxxxxxxxxxxxxxxxxxxxxxxxxxx",
}
return {
vol.Required(TOKEN, default=config.get(TOKEN)): str,
}


def hacs_config_option_schema(options: dict = {}) -> dict:
"""Return a shcema for HACS configuration options."""
if not options:
options = {
APPDAEMON: False,
COUNTRY: "ALL",
DEBUG: False,
EXPERIMENTAL: False,
NETDAEMON: False,
RELEASE_LIMIT: 5,
SIDEPANEL_ICON: "hacs:hacs",
SIDEPANEL_TITLE: "HACS",
FRONTEND_REPO: "",
FRONTEND_REPO_URL: "",
}
return {
vol.Optional(SIDEPANEL_TITLE, default=options.get(SIDEPANEL_TITLE)): str,
vol.Optional(SIDEPANEL_ICON, default=options.get(SIDEPANEL_ICON)): str,
vol.Optional(RELEASE_LIMIT, default=options.get(RELEASE_LIMIT)): int,
vol.Optional(COUNTRY, default=options.get(COUNTRY)): vol.In(LOCALE),
vol.Optional(APPDAEMON, default=options.get(APPDAEMON)): bool,
vol.Optional(NETDAEMON, default=options.get(NETDAEMON)): bool,
vol.Optional(DEBUG, default=options.get(DEBUG)): bool,
vol.Optional(EXPERIMENTAL, default=options.get(EXPERIMENTAL)): bool,
vol.Exclusive(FRONTEND_REPO, PATH_OR_URL): str,
vol.Exclusive(FRONTEND_REPO_URL, PATH_OR_URL): str,
}


def hacs_config_combined() -> dict:
"""Combine the configuration options."""
base = hacs_base_config_schema()
options = hacs_config_option_schema()

for option in options:
base[option] = options[option]

return base
5 changes: 2 additions & 3 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
from custom_components.hacs.const import DOMAIN
from custom_components.hacs.enums import HacsCategory
from custom_components.hacs.repositories.base import HacsManifest, HacsRepository
from custom_components.hacs.utils.configuration_schema import TOKEN as CONF_TOKEN
from custom_components.hacs.utils.logger import LOGGER

TOKEN = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
Expand Down Expand Up @@ -875,7 +874,7 @@ def create_config_entry(
minor_version=0,
domain=DOMAIN,
title="",
data={CONF_TOKEN: TOKEN, **(data or {})},
data={"token": TOKEN, **(data or {})},
source="user",
options={**(options or {})},
unique_id="12345",
Expand All @@ -885,7 +884,7 @@ def create_config_entry(
version=1,
domain=DOMAIN,
title="",
data={CONF_TOKEN: TOKEN, **(data or {})},
data={"token": TOKEN, **(data or {})},
source="user",
options={**(options or {})},
unique_id="12345",
Expand Down
Loading