From d039bf51e6019f59eec40fd5fff70b7c1bbcdb32 Mon Sep 17 00:00:00 2001 From: ludeeus Date: Wed, 28 Feb 2024 05:27:20 +0000 Subject: [PATCH 1/6] Replace deprecated hass.components usage --- custom_components/hacs/__init__.py | 3 ++- custom_components/hacs/base.py | 5 ++--- custom_components/hacs/frontend.py | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/custom_components/hacs/__init__.py b/custom_components/hacs/__init__.py index 755ec25d9ed..8ec7b2015c0 100644 --- a/custom_components/hacs/__init__.py +++ b/custom_components/hacs/__init__.py @@ -12,6 +12,7 @@ from aiogithubapi import AIOGitHubAPIException, GitHub, GitHubAPI from aiogithubapi.const import ACCEPT_HEADERS from awesomeversion import AwesomeVersion +from homeassistant.components.frontend import async_remove_panel from homeassistant.components.lovelace.system_health import system_health_info from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry from homeassistant.const import Platform, __version__ as HAVERSION @@ -269,7 +270,7 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> try: if hass.data.get("frontend_panels", {}).get("hacs"): hacs.log.info("Removing sidepanel") - hass.components.frontend.async_remove_panel("hacs") + async_remove_panel(hass, "hacs") except AttributeError: pass diff --git a/custom_components/hacs/base.py b/custom_components/hacs/base.py index 76c7785cd20..e485d7a474d 100644 --- a/custom_components/hacs/base.py +++ b/custom_components/hacs/base.py @@ -24,6 +24,7 @@ from aiogithubapi.objects.repository import AIOGitHubAPIRepository from aiohttp.client import ClientSession, ClientTimeout from awesomeversion import AwesomeVersion +from homeassistant.components.persistent_notification import create as create_persistent_notification from homeassistant.config_entries import ConfigEntry, ConfigEntryState from homeassistant.const import EVENT_HOMEASSISTANT_FINAL_WRITE, Platform from homeassistant.core import HomeAssistant, callback @@ -620,9 +621,7 @@ async def startup_tasks(self, _=None) -> None: for repo in critical: if not repo["acknowledged"]: self.log.critical("URGENT!: Check the HACS panel!") - self.hass.components.persistent_notification.create( - title="URGENT!", message="**Check the HACS panel!**" - ) + create_persistent_notification(self.hass, title="URGENT!", message="**Check the HACS panel!**") break if not self.configuration.experimental: diff --git a/custom_components/hacs/frontend.py b/custom_components/hacs/frontend.py index 6557517db9a..02b9a9d4c20 100644 --- a/custom_components/hacs/frontend.py +++ b/custom_components/hacs/frontend.py @@ -5,6 +5,7 @@ from typing import TYPE_CHECKING from homeassistant.core import HomeAssistant, callback +from homeassistant.components.frontend import async_register_built_in_panel from .const import DOMAIN, URL_BASE from .hacs_frontend import VERSION as FE_VERSION, locate_dir @@ -65,7 +66,7 @@ def async_register_frontend(hass: HomeAssistant, hacs: HacsBase) -> None: # Add to sidepanel if needed if DOMAIN not in hass.data.get("frontend_panels", {}): - hass.components.frontend.async_register_built_in_panel( + async_register_built_in_panel(hass, component_name="custom", sidebar_title=hacs.configuration.sidepanel_title, sidebar_icon=hacs.configuration.sidepanel_icon, From 24ff225fee90c2cf0a33a7ed6d1c2d4aaea9c43c Mon Sep 17 00:00:00 2001 From: ludeeus Date: Wed, 28 Feb 2024 05:30:11 +0000 Subject: [PATCH 2/6] lint --- custom_components/hacs/base.py | 8 ++++++-- custom_components/hacs/frontend.py | 5 +++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/custom_components/hacs/base.py b/custom_components/hacs/base.py index e485d7a474d..cce87c1dc60 100644 --- a/custom_components/hacs/base.py +++ b/custom_components/hacs/base.py @@ -24,7 +24,9 @@ from aiogithubapi.objects.repository import AIOGitHubAPIRepository from aiohttp.client import ClientSession, ClientTimeout from awesomeversion import AwesomeVersion -from homeassistant.components.persistent_notification import create as create_persistent_notification +from homeassistant.components.persistent_notification import ( + create as create_persistent_notification, +) from homeassistant.config_entries import ConfigEntry, ConfigEntryState from homeassistant.const import EVENT_HOMEASSISTANT_FINAL_WRITE, Platform from homeassistant.core import HomeAssistant, callback @@ -621,7 +623,9 @@ async def startup_tasks(self, _=None) -> None: for repo in critical: if not repo["acknowledged"]: self.log.critical("URGENT!: Check the HACS panel!") - create_persistent_notification(self.hass, title="URGENT!", message="**Check the HACS panel!**") + create_persistent_notification( + self.hass, title="URGENT!", message="**Check the HACS panel!**" + ) break if not self.configuration.experimental: diff --git a/custom_components/hacs/frontend.py b/custom_components/hacs/frontend.py index 02b9a9d4c20..c1db4928961 100644 --- a/custom_components/hacs/frontend.py +++ b/custom_components/hacs/frontend.py @@ -4,8 +4,8 @@ import os from typing import TYPE_CHECKING -from homeassistant.core import HomeAssistant, callback from homeassistant.components.frontend import async_register_built_in_panel +from homeassistant.core import HomeAssistant, callback from .const import DOMAIN, URL_BASE from .hacs_frontend import VERSION as FE_VERSION, locate_dir @@ -66,7 +66,8 @@ def async_register_frontend(hass: HomeAssistant, hacs: HacsBase) -> None: # Add to sidepanel if needed if DOMAIN not in hass.data.get("frontend_panels", {}): - async_register_built_in_panel(hass, + async_register_built_in_panel( + hass, component_name="custom", sidebar_title=hacs.configuration.sidepanel_title, sidebar_icon=hacs.configuration.sidepanel_icon, From 97172272111af3ce1e6ebd23e22d44d897a8a013 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Thu, 11 Apr 2024 15:14:14 +0200 Subject: [PATCH 3/6] Apply suggestions from code review Co-authored-by: Martin Hjelmare --- custom_components/hacs/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/custom_components/hacs/base.py b/custom_components/hacs/base.py index cce87c1dc60..2d9d41ecdda 100644 --- a/custom_components/hacs/base.py +++ b/custom_components/hacs/base.py @@ -25,7 +25,7 @@ from aiohttp.client import ClientSession, ClientTimeout from awesomeversion import AwesomeVersion from homeassistant.components.persistent_notification import ( - create as create_persistent_notification, + async_create as create_persistent_notification, ) from homeassistant.config_entries import ConfigEntry, ConfigEntryState from homeassistant.const import EVENT_HOMEASSISTANT_FINAL_WRITE, Platform @@ -623,7 +623,7 @@ async def startup_tasks(self, _=None) -> None: for repo in critical: if not repo["acknowledged"]: self.log.critical("URGENT!: Check the HACS panel!") - create_persistent_notification( + async_create_persistent_notification( self.hass, title="URGENT!", message="**Check the HACS panel!**" ) break From 05f977d7c2c23dfda0928353a279feb0d26947c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Thu, 11 Apr 2024 15:18:46 +0200 Subject: [PATCH 4/6] Update custom_components/hacs/base.py --- custom_components/hacs/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/hacs/base.py b/custom_components/hacs/base.py index e8bdde22bcc..4af0574d07f 100644 --- a/custom_components/hacs/base.py +++ b/custom_components/hacs/base.py @@ -25,7 +25,7 @@ from aiohttp.client import ClientSession, ClientTimeout from awesomeversion import AwesomeVersion from homeassistant.components.persistent_notification import ( - async_create as create_persistent_notification, + async_create as async_create_persistent_notification, ) from homeassistant.config_entries import ConfigEntry, ConfigEntryState from homeassistant.const import EVENT_HOMEASSISTANT_FINAL_WRITE, Platform From 19e3f1ac4507855effa14c28247123651e8647aa Mon Sep 17 00:00:00 2001 From: ludeeus Date: Thu, 11 Apr 2024 13:27:08 +0000 Subject: [PATCH 5/6] Restrict to 0 reported issues --- tests/conftest.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 05def2509e3..fefd2a28a22 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -360,10 +360,7 @@ async def setup_integration(hass: HomeAssistant, check_report_issue: None) -> No async def check_report_issue() -> None: """Finish things up.""" yield - # Issues may be created because hacs accesses hass.components, hass.helpers and - # calls async_show_progress without passing a progress task - allowed = [0, 1, 2, 3] if AwesomeVersion(HA_VERSION) > "2023.6.0" else [0] - if (times := len(_async_suggest_report_issue_mock_call_tracker)) not in allowed: + if (times := len(_async_suggest_report_issue_mock_call_tracker)) != 0: raise AssertionError( f"homeassistant.loader.async_suggest_report_issue has been called {times} times" ) From 630dde26bb413331a3830b295a08eacc03b78c2f Mon Sep 17 00:00:00 2001 From: ludeeus Date: Thu, 11 Apr 2024 13:29:39 +0000 Subject: [PATCH 6/6] Revert "Restrict to 0 reported issues" This reverts commit 19e3f1ac4507855effa14c28247123651e8647aa. --- tests/conftest.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index fefd2a28a22..05def2509e3 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -360,7 +360,10 @@ async def setup_integration(hass: HomeAssistant, check_report_issue: None) -> No async def check_report_issue() -> None: """Finish things up.""" yield - if (times := len(_async_suggest_report_issue_mock_call_tracker)) != 0: + # Issues may be created because hacs accesses hass.components, hass.helpers and + # calls async_show_progress without passing a progress task + allowed = [0, 1, 2, 3] if AwesomeVersion(HA_VERSION) > "2023.6.0" else [0] + if (times := len(_async_suggest_report_issue_mock_call_tracker)) not in allowed: raise AssertionError( f"homeassistant.loader.async_suggest_report_issue has been called {times} times" )