From ee9fba8e8c4459607c95bf5972d90761c9a0afd3 Mon Sep 17 00:00:00 2001 From: Erik Date: Mon, 8 Apr 2024 09:56:23 +0200 Subject: [PATCH 1/3] Adapt config flow to changes in HA Core 2024.2.0 --- custom_components/hacs/config_flow.py | 28 ++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/custom_components/hacs/config_flow.py b/custom_components/hacs/config_flow.py index 583f0f0946d..431e01e4608 100644 --- a/custom_components/hacs/config_flow.py +++ b/custom_components/hacs/config_flow.py @@ -36,6 +36,8 @@ ) from .utils.logger import LOGGER +MINIMUM_HA_VERSION_SHOW_PROGRESS_TASK = "2024.2.0" + if TYPE_CHECKING: from homeassistant.core import HomeAssistant @@ -52,6 +54,7 @@ class HacsFlowHandler(ConfigFlow, domain=DOMAIN): _registration: GitHubLoginDeviceModel | None = None _activation: GitHubLoginOauthModel | None = None _reauth: bool = False + _use_progress_task: bool = False def __init__(self) -> None: """Initialize.""" @@ -60,6 +63,8 @@ def __init__(self) -> None: async def async_step_user(self, user_input): """Handle a flow initialized by the user.""" + self._use_progress_task = AwesomeVersion(HAVERSION) >= MINIMUM_HA_VERSION_SHOW_PROGRESS_TASK + self._errors = {} if self._async_current_entries(): return self.async_abort(reason="single_instance_allowed") @@ -80,7 +85,12 @@ async def async_step_user(self, user_input): @callback def async_remove(self): - """Cleanup.""" + """Cleanup. + + Needed in old Home Assistant versions which don't support show progress taks. + """ + if self._use_progress_task: + return if self.activation_task and not self.activation_task.done(): self.activation_task.cancel() @@ -97,7 +107,8 @@ async def _progress(): with suppress(UnknownFlow): await self.hass.config_entries.flow.async_configure(flow_id=self.flow_id) - self.hass.async_create_task(_progress()) + if not self._use_progress_task: + self.hass.async_create_task(_progress()) if not self.device: integration = await async_get_integration(self.hass, DOMAIN) @@ -122,14 +133,17 @@ async def _progress(): return self.async_show_progress_done(next_step_id="could_not_register") return self.async_show_progress_done(next_step_id="device_done") - return self.async_show_progress( - step_id="device", - progress_action="wait_for_device", - description_placeholders={ + show_progress_kwargs = { + "step_id": "device", + "progress_action": "wait_for_device", + "description_placeholders": { "url": OAUTH_USER_LOGIN, "code": self._registration.user_code, }, - ) + } + if self._use_progress_task: + show_progress_kwargs["progress_task"] = self.activation_task + return self.async_show_progress(**show_progress_kwargs) async def _show_config_form(self, user_input): """Show the configuration form to edit location data.""" From 0265bfb4489451320c5080a172369a7a668dc9ba Mon Sep 17 00:00:00 2001 From: Erik Date: Wed, 10 Apr 2024 17:38:29 +0200 Subject: [PATCH 2/3] Update allowed number of seen issues --- tests/conftest.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 6097078e636..132873a49b2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -321,9 +321,8 @@ def response_mocker() -> ResponseMocker: async def setup_integration(hass: HomeAssistant, check_report_issue: None) -> None: ## Assert the string to ensure the format did not change if AwesomeVersion(HA_VERSION) >= "2023.11.0": - # Issues may be created because hacs accesses hass.components, hass.helpers and - # calls async_show_progress without passing a progress task - assert len(_async_suggest_report_issue_mock_call_tracker) in [0, 1, 2, 3] + # Issues may be created because hacs accesses hass.components and hass.helpers + assert len(_async_suggest_report_issue_mock_call_tracker) in [0, 1, 2] _async_suggest_report_issue_mock_call_tracker.clear() assert ( loader.async_suggest_report_issue( @@ -352,9 +351,8 @@ 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] + # Issues may be created because hacs accesses hass.components and hass.helpers + allowed = [0, 1, 2] 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" From 5a8fa3f524aadd9ef16db68a96f03dd30057be86 Mon Sep 17 00:00:00 2001 From: Erik Date: Thu, 11 Apr 2024 15:33:10 +0200 Subject: [PATCH 3/3] Fix typo --- custom_components/hacs/config_flow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/hacs/config_flow.py b/custom_components/hacs/config_flow.py index 431e01e4608..37c64228506 100644 --- a/custom_components/hacs/config_flow.py +++ b/custom_components/hacs/config_flow.py @@ -87,7 +87,7 @@ async def async_step_user(self, user_input): def async_remove(self): """Cleanup. - Needed in old Home Assistant versions which don't support show progress taks. + Needed in old Home Assistant versions which don't support show progress tasks. """ if self._use_progress_task: return