Skip to content

Commit

Permalink
Merge branch 'main' into cleanup_final_write_listener
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus authored Apr 11, 2024
2 parents 4a74d12 + 1a1b2eb commit 1d0f348
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 25 deletions.
42 changes: 20 additions & 22 deletions custom_components/hacs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ async def async_initialize_integration(
hacs.enable_hacs()

if config is not None:
if DOMAIN not in config:
return True
if hacs.configuration.config_type == ConfigurationType.CONFIG_ENTRY:
return True
hacs.configuration.update_from_dict(
{
"config_type": ConfigurationType.YAML,
Expand Down Expand Up @@ -219,24 +215,26 @@ async def async_try_startup(_=None):

async def async_setup(hass: HomeAssistant, config: dict[str, Any]) -> bool:
"""Set up this integration using yaml."""
if DOMAIN in config:
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."
)
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)


Expand Down
7 changes: 6 additions & 1 deletion custom_components/hacs/system_health.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Provide info to system health."""
from typing import Any

from aiogithubapi.common.const import BASE_API_URL
from homeassistant.components import system_health
from homeassistant.core import HomeAssistant, callback
Expand All @@ -17,8 +19,11 @@ def async_register(hass: HomeAssistant, register: system_health.SystemHealthRegi
register.async_register_info(system_health_info, "/hacs")


async def system_health_info(hass):
async def system_health_info(hass: HomeAssistant) -> dict[str, Any]:
"""Get info for the info page."""
if DOMAIN not in hass.data:
return {"Disabled": "HACS is not loaded, but HA still requests this information..."}

hacs: HacsBase = hass.data[DOMAIN]
response = await hacs.githubapi.rate_limit()

Expand Down
3 changes: 3 additions & 0 deletions tests/snapshots/system_health/system_health_after_unload.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Disabled": "HACS is not loaded, but HA still requests this information..."
}
6 changes: 4 additions & 2 deletions tests/test_system_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,17 @@ async def test_system_health(
async def test_system_health_after_unload(
hacs: HacsBase,
hass: HomeAssistant,
snapshots: SnapshotFixture,
) -> None:
"""Test HACS system health."""
await hass.config_entries.async_unload(hacs.configuration.config_entry.entry_id)

assert await async_setup_component(hass, "system_health", {})
await hass.async_block_till_done()

with pytest.raises(KeyError, match="hacs"):
await get_system_health_info(hass, HACS_SYSTEM_HEALTH_DOMAIN)
info = await get_system_health_info(hass, HACS_SYSTEM_HEALTH_DOMAIN)

snapshots.assert_match(safe_json_dumps(info), "system_health/system_health_after_unload.json")


async def test_system_health_no_hacs(
Expand Down

0 comments on commit 1d0f348

Please sign in to comment.