From 888e5ebc3bb6cb26dcddc6311c8fba4cc33dc55d Mon Sep 17 00:00:00 2001 From: Rami Mousleh Date: Sun, 17 Dec 2023 08:14:22 +0000 Subject: [PATCH 1/7] Issue warning if glances server version is 2 --- homeassistant/components/glances/__init__.py | 13 ++++++++- homeassistant/components/glances/strings.json | 6 +++++ tests/components/glances/test_init.py | 27 ++++++++++++++++++- 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/glances/__init__.py b/homeassistant/components/glances/__init__.py index bda1baf797af55..6bc689cac87b7c 100644 --- a/homeassistant/components/glances/__init__.py +++ b/homeassistant/components/glances/__init__.py @@ -8,8 +8,9 @@ from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv from homeassistant.helpers.httpx_client import get_async_client +from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue -from .const import DOMAIN +from .const import CONF_VERSION, DOMAIN from .coordinator import GlancesDataUpdateCoordinator PLATFORMS = [Platform.SENSOR] @@ -27,6 +28,16 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS) + if config_entry.data[CONF_VERSION] == 2: + async_create_issue( + hass, + DOMAIN, + "deprecated_version", + is_fixable=False, + severity=IssueSeverity.WARNING, + translation_key="deprecated_version", + ) + return True diff --git a/homeassistant/components/glances/strings.json b/homeassistant/components/glances/strings.json index 1bab098d65f785..2cc776189346dc 100644 --- a/homeassistant/components/glances/strings.json +++ b/homeassistant/components/glances/strings.json @@ -30,5 +30,11 @@ "already_configured": "[%key:common::config_flow::abort::already_configured_device%]", "reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]" } + }, + "issues": { + "deprecated_version": { + "title": "Glances servers with version 2 is deprecated", + "description": "Glances servers with version 2 is deprecated and will not be supported in future versions of HA. It is recommended to update to version 3." + } } } diff --git a/tests/components/glances/test_init.py b/tests/components/glances/test_init.py index 61cbc610060950..265555a6b9dbcf 100644 --- a/tests/components/glances/test_init.py +++ b/tests/components/glances/test_init.py @@ -10,6 +10,10 @@ from homeassistant.components.glances.const import DOMAIN from homeassistant.config_entries import ConfigEntryState from homeassistant.core import HomeAssistant +from homeassistant.helpers.issue_registry import ( + IssueSeverity, + async_get as async_get_issue_registry, +) from . import MOCK_USER_INPUT @@ -17,7 +21,7 @@ async def test_successful_config_entry(hass: HomeAssistant) -> None: - """Test that Glances is configured successfully.""" + """Test that Glances is configu red successfully.""" entry = MockConfigEntry(domain=DOMAIN, data=MOCK_USER_INPUT) entry.add_to_hass(hass) @@ -27,6 +31,27 @@ async def test_successful_config_entry(hass: HomeAssistant) -> None: assert entry.state == ConfigEntryState.LOADED +async def test_entry_deprecated_version(hass: HomeAssistant) -> None: + """Test creating an issue if glances server is version 2.""" + registry = async_get_issue_registry(hass) + issue = registry.async_get_issue(DOMAIN, "deprecated_version") + assert issue is None + + v2_config_entry = MOCK_USER_INPUT.copy() + v2_config_entry["version"] = 2 + + entry = MockConfigEntry(domain=DOMAIN, data=v2_config_entry) + entry.add_to_hass(hass) + + await hass.config_entries.async_setup(entry.entry_id) + + assert entry.state == ConfigEntryState.LOADED + + issue = registry.async_get_issue(DOMAIN, "deprecated_version") + assert issue is not None + assert issue.severity == IssueSeverity.WARNING + + @pytest.mark.parametrize( ("error", "entry_state"), [ From 76d51b86b8dd5616c30b45f1f8ecc9edd6ba480a Mon Sep 17 00:00:00 2001 From: Rami Mousleh Date: Thu, 28 Dec 2023 08:55:18 +0000 Subject: [PATCH 2/7] Auto detect api version --- homeassistant/components/glances/__init__.py | 60 +++++++++++++++---- .../components/glances/config_flow.py | 20 ++----- homeassistant/components/glances/const.py | 3 - homeassistant/components/glances/strings.json | 3 +- tests/components/glances/__init__.py | 1 - tests/components/glances/test_init.py | 36 +++++------ 6 files changed, 71 insertions(+), 52 deletions(-) diff --git a/homeassistant/components/glances/__init__.py b/homeassistant/components/glances/__init__.py index 6bc689cac87b7c..94152b0611eb6c 100644 --- a/homeassistant/components/glances/__init__.py +++ b/homeassistant/components/glances/__init__.py @@ -1,11 +1,23 @@ """The Glances component.""" +import logging from typing import Any from glances_api import Glances +from glances_api.exceptions import ( + GlancesApiAuthorizationError, + GlancesApiError, + GlancesApiNoDataAvailable, +) from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_NAME, CONF_VERIFY_SSL, Platform from homeassistant.core import HomeAssistant +from homeassistant.exceptions import ( + ConfigEntryAuthFailed, + ConfigEntryError, + ConfigEntryNotReady, + HomeAssistantError, +) import homeassistant.helpers.config_validation as cv from homeassistant.helpers.httpx_client import get_async_client from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue @@ -17,10 +29,19 @@ CONFIG_SCHEMA = cv.removed(DOMAIN, raise_if_present=False) +_LOGGER = logging.getLogger(__name__) + async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool: """Set up Glances from config entry.""" - api = get_api(hass, dict(config_entry.data)) + try: + api = await get_api(hass, dict(config_entry.data)) + except GlancesApiAuthorizationError as err: + raise ConfigEntryAuthFailed from err + except GlancesApiError as err: + raise ConfigEntryNotReady from err + except UnknownError as err: + raise ConfigEntryError(err) from err coordinator = GlancesDataUpdateCoordinator(hass, config_entry, api) await coordinator.async_config_entry_first_refresh() @@ -28,16 +49,6 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS) - if config_entry.data[CONF_VERSION] == 2: - async_create_issue( - hass, - DOMAIN, - "deprecated_version", - is_fixable=False, - severity=IssueSeverity.WARNING, - translation_key="deprecated_version", - ) - return True @@ -50,8 +61,31 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: return unload_ok -def get_api(hass: HomeAssistant, entry_data: dict[str, Any]) -> Glances: +async def get_api(hass: HomeAssistant, entry_data: dict[str, Any]) -> Glances: """Return the api from glances_api.""" entry_data.pop(CONF_NAME, None) + entry_data.pop(CONF_VERSION, None) + httpx_client = get_async_client(hass, verify_ssl=entry_data[CONF_VERIFY_SSL]) - return Glances(httpx_client=httpx_client, **entry_data) + for version in (3, 2): + api = Glances(httpx_client=httpx_client, version=version, **entry_data) + try: + await api.get_ha_sensor_data() + _LOGGER.debug("Connected to Glances API v%s", version) + if version == 2: + async_create_issue( + hass, + DOMAIN, + "deprecated_version", + is_fixable=False, + severity=IssueSeverity.WARNING, + translation_key="deprecated_version", + ) + return api + except GlancesApiNoDataAvailable as err: + _LOGGER.debug("Failed to connect to Glances API v%s: %s", version, err) + raise UnknownError("Could not connect to Glances API") + + +class UnknownError(HomeAssistantError): + """Raise exception if we fail to connect to Glances API.""" diff --git a/homeassistant/components/glances/config_flow.py b/homeassistant/components/glances/config_flow.py index 72555b629d7ccd..b4df8156f4228d 100644 --- a/homeassistant/components/glances/config_flow.py +++ b/homeassistant/components/glances/config_flow.py @@ -21,15 +21,8 @@ ) from homeassistant.data_entry_flow import FlowResult -from . import get_api -from .const import ( - CONF_VERSION, - DEFAULT_HOST, - DEFAULT_PORT, - DEFAULT_VERSION, - DOMAIN, - SUPPORTED_VERSIONS, -) +from . import UnknownError, get_api +from .const import DEFAULT_HOST, DEFAULT_PORT, DOMAIN DATA_SCHEMA = vol.Schema( { @@ -37,7 +30,6 @@ vol.Optional(CONF_USERNAME): str, vol.Optional(CONF_PASSWORD): str, vol.Required(CONF_PORT, default=DEFAULT_PORT): int, - vol.Required(CONF_VERSION, default=DEFAULT_VERSION): vol.In(SUPPORTED_VERSIONS), vol.Optional(CONF_SSL, default=False): bool, vol.Optional(CONF_VERIFY_SSL, default=False): bool, } @@ -65,12 +57,11 @@ async def async_step_reauth_confirm( assert self._reauth_entry if user_input is not None: user_input = {**self._reauth_entry.data, **user_input} - api = get_api(self.hass, user_input) try: - await api.get_ha_sensor_data() + await get_api(self.hass, user_input) except GlancesApiAuthorizationError: errors["base"] = "invalid_auth" - except GlancesApiConnectionError: + except (GlancesApiConnectionError, UnknownError): errors["base"] = "cannot_connect" else: self.hass.config_entries.async_update_entry( @@ -101,9 +92,8 @@ async def async_step_user( self._async_abort_entries_match( {CONF_HOST: user_input[CONF_HOST], CONF_PORT: user_input[CONF_PORT]} ) - api = get_api(self.hass, user_input) try: - await api.get_ha_sensor_data() + await get_api(self.hass, user_input) except GlancesApiAuthorizationError: errors["base"] = "invalid_auth" except GlancesApiConnectionError: diff --git a/homeassistant/components/glances/const.py b/homeassistant/components/glances/const.py index 37da60bdea80ec..f0477a30463844 100644 --- a/homeassistant/components/glances/const.py +++ b/homeassistant/components/glances/const.py @@ -8,9 +8,6 @@ DEFAULT_HOST = "localhost" DEFAULT_PORT = 61208 -DEFAULT_VERSION = 3 DEFAULT_SCAN_INTERVAL = timedelta(seconds=60) -SUPPORTED_VERSIONS = [2, 3] - CPU_ICON = f"mdi:cpu-{64 if sys.maxsize > 2**32 else 32}-bit" diff --git a/homeassistant/components/glances/strings.json b/homeassistant/components/glances/strings.json index 2cc776189346dc..d0dd1b0b393665 100644 --- a/homeassistant/components/glances/strings.json +++ b/homeassistant/components/glances/strings.json @@ -7,7 +7,6 @@ "username": "[%key:common::config_flow::data::username%]", "password": "[%key:common::config_flow::data::password%]", "port": "[%key:common::config_flow::data::port%]", - "version": "Glances API Version (2 or 3)", "ssl": "[%key:common::config_flow::data::ssl%]", "verify_ssl": "[%key:common::config_flow::data::verify_ssl%]" }, @@ -34,7 +33,7 @@ "issues": { "deprecated_version": { "title": "Glances servers with version 2 is deprecated", - "description": "Glances servers with version 2 is deprecated and will not be supported in future versions of HA. It is recommended to update to version 3." + "description": "Glances servers with version 2 is deprecated and will not be supported in future versions of HA. It is recommended to update to version 3 then reload the config entry." } } } diff --git a/tests/components/glances/__init__.py b/tests/components/glances/__init__.py index 41f2675c41ccee..fc9d43b546446c 100644 --- a/tests/components/glances/__init__.py +++ b/tests/components/glances/__init__.py @@ -6,7 +6,6 @@ "host": "0.0.0.0", "username": "username", "password": "password", - "version": 3, "port": 61208, "ssl": False, "verify_ssl": True, diff --git a/tests/components/glances/test_init.py b/tests/components/glances/test_init.py index 265555a6b9dbcf..764426c6276fa9 100644 --- a/tests/components/glances/test_init.py +++ b/tests/components/glances/test_init.py @@ -1,27 +1,25 @@ """Tests for Glances integration.""" -from unittest.mock import MagicMock +from unittest.mock import AsyncMock, MagicMock from glances_api.exceptions import ( GlancesApiAuthorizationError, GlancesApiConnectionError, + GlancesApiNoDataAvailable, ) import pytest from homeassistant.components.glances.const import DOMAIN from homeassistant.config_entries import ConfigEntryState from homeassistant.core import HomeAssistant -from homeassistant.helpers.issue_registry import ( - IssueSeverity, - async_get as async_get_issue_registry, -) +from homeassistant.helpers import issue_registry as ir -from . import MOCK_USER_INPUT +from . import HA_SENSOR_DATA, MOCK_USER_INPUT from tests.common import MockConfigEntry async def test_successful_config_entry(hass: HomeAssistant) -> None: - """Test that Glances is configu red successfully.""" + """Test that Glances is configured successfully.""" entry = MockConfigEntry(domain=DOMAIN, data=MOCK_USER_INPUT) entry.add_to_hass(hass) @@ -31,25 +29,26 @@ async def test_successful_config_entry(hass: HomeAssistant) -> None: assert entry.state == ConfigEntryState.LOADED -async def test_entry_deprecated_version(hass: HomeAssistant) -> None: +async def test_entry_deprecated_version( + hass: HomeAssistant, issue_registry: ir.IssueRegistry, mock_api: AsyncMock +) -> None: """Test creating an issue if glances server is version 2.""" - registry = async_get_issue_registry(hass) - issue = registry.async_get_issue(DOMAIN, "deprecated_version") - assert issue is None - - v2_config_entry = MOCK_USER_INPUT.copy() - v2_config_entry["version"] = 2 - - entry = MockConfigEntry(domain=DOMAIN, data=v2_config_entry) + entry = MockConfigEntry(domain=DOMAIN, data=MOCK_USER_INPUT) entry.add_to_hass(hass) + mock_api.return_value.get_ha_sensor_data.side_effect = [ + GlancesApiNoDataAvailable("endpoint: 'all' is not valid"), + HA_SENSOR_DATA, + HA_SENSOR_DATA, + ] + await hass.config_entries.async_setup(entry.entry_id) assert entry.state == ConfigEntryState.LOADED - issue = registry.async_get_issue(DOMAIN, "deprecated_version") + issue = issue_registry.async_get_issue(DOMAIN, "deprecated_version") assert issue is not None - assert issue.severity == IssueSeverity.WARNING + assert issue.severity == ir.IssueSeverity.WARNING @pytest.mark.parametrize( @@ -57,6 +56,7 @@ async def test_entry_deprecated_version(hass: HomeAssistant) -> None: [ (GlancesApiAuthorizationError, ConfigEntryState.SETUP_ERROR), (GlancesApiConnectionError, ConfigEntryState.SETUP_RETRY), + (GlancesApiNoDataAvailable, ConfigEntryState.SETUP_ERROR), ], ) async def test_setup_error( From 37e157981284b163bd107e39531f506a38677c53 Mon Sep 17 00:00:00 2001 From: Rami Mousleh Date: Fri, 29 Dec 2023 06:36:10 +0000 Subject: [PATCH 3/7] Apply suggestions --- homeassistant/components/glances/__init__.py | 58 ++++++++++++------- .../components/glances/config_flow.py | 4 +- homeassistant/components/glances/strings.json | 2 +- 3 files changed, 39 insertions(+), 25 deletions(-) diff --git a/homeassistant/components/glances/__init__.py b/homeassistant/components/glances/__init__.py index 94152b0611eb6c..463ee3f0a2f10c 100644 --- a/homeassistant/components/glances/__init__.py +++ b/homeassistant/components/glances/__init__.py @@ -10,7 +10,15 @@ ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import CONF_NAME, CONF_VERIFY_SSL, Platform +from homeassistant.const import ( + CONF_HOST, + CONF_PASSWORD, + CONF_PORT, + CONF_SSL, + CONF_USERNAME, + CONF_VERIFY_SSL, + Platform, +) from homeassistant.core import HomeAssistant from homeassistant.exceptions import ( ConfigEntryAuthFailed, @@ -22,7 +30,7 @@ from homeassistant.helpers.httpx_client import get_async_client from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue -from .const import CONF_VERSION, DOMAIN +from .const import DOMAIN from .coordinator import GlancesDataUpdateCoordinator PLATFORMS = [Platform.SENSOR] @@ -40,7 +48,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b raise ConfigEntryAuthFailed from err except GlancesApiError as err: raise ConfigEntryNotReady from err - except UnknownError as err: + except ServerVersionMismatch as err: raise ConfigEntryError(err) from err coordinator = GlancesDataUpdateCoordinator(hass, config_entry, api) await coordinator.async_config_entry_first_refresh() @@ -63,29 +71,35 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async def get_api(hass: HomeAssistant, entry_data: dict[str, Any]) -> Glances: """Return the api from glances_api.""" - entry_data.pop(CONF_NAME, None) - entry_data.pop(CONF_VERSION, None) - httpx_client = get_async_client(hass, verify_ssl=entry_data[CONF_VERIFY_SSL]) for version in (3, 2): - api = Glances(httpx_client=httpx_client, version=version, **entry_data) + api = Glances( + host=entry_data[CONF_HOST], + port=entry_data[CONF_PORT], + version=version, + ssl=entry_data[CONF_SSL], + username=entry_data.get(CONF_USERNAME), + password=entry_data.get(CONF_PASSWORD), + httpx_client=httpx_client, + ) try: await api.get_ha_sensor_data() - _LOGGER.debug("Connected to Glances API v%s", version) - if version == 2: - async_create_issue( - hass, - DOMAIN, - "deprecated_version", - is_fixable=False, - severity=IssueSeverity.WARNING, - translation_key="deprecated_version", - ) - return api except GlancesApiNoDataAvailable as err: _LOGGER.debug("Failed to connect to Glances API v%s: %s", version, err) - raise UnknownError("Could not connect to Glances API") - - -class UnknownError(HomeAssistantError): + continue + if version == 2: + async_create_issue( + hass, + DOMAIN, + "deprecated_version", + is_fixable=False, + severity=IssueSeverity.WARNING, + translation_key="deprecated_version", + ) + _LOGGER.debug("Connected to Glances API v%s", version) + return api + raise ServerVersionMismatch("Could not connect to Glances API version 2 or 3") + + +class ServerVersionMismatch(HomeAssistantError): """Raise exception if we fail to connect to Glances API.""" diff --git a/homeassistant/components/glances/config_flow.py b/homeassistant/components/glances/config_flow.py index b4df8156f4228d..8f02d715c285ab 100644 --- a/homeassistant/components/glances/config_flow.py +++ b/homeassistant/components/glances/config_flow.py @@ -21,7 +21,7 @@ ) from homeassistant.data_entry_flow import FlowResult -from . import UnknownError, get_api +from . import ServerVersionMismatch, get_api from .const import DEFAULT_HOST, DEFAULT_PORT, DOMAIN DATA_SCHEMA = vol.Schema( @@ -61,7 +61,7 @@ async def async_step_reauth_confirm( await get_api(self.hass, user_input) except GlancesApiAuthorizationError: errors["base"] = "invalid_auth" - except (GlancesApiConnectionError, UnknownError): + except (GlancesApiConnectionError, ServerVersionMismatch): errors["base"] = "cannot_connect" else: self.hass.config_entries.async_update_entry( diff --git a/homeassistant/components/glances/strings.json b/homeassistant/components/glances/strings.json index d0dd1b0b393665..a63620a9d6912a 100644 --- a/homeassistant/components/glances/strings.json +++ b/homeassistant/components/glances/strings.json @@ -33,7 +33,7 @@ "issues": { "deprecated_version": { "title": "Glances servers with version 2 is deprecated", - "description": "Glances servers with version 2 is deprecated and will not be supported in future versions of HA. It is recommended to update to version 3 then reload the config entry." + "description": "Glances servers with version 2 is deprecated and will not be supported in future versions of HA. It is recommended to update your server to Glances version 3 then reload the config entry." } } } From 029e4a99c1fe5ff077a2331fecc52729357cbb49 Mon Sep 17 00:00:00 2001 From: Rami Mousleh Date: Fri, 29 Dec 2023 06:45:21 +0000 Subject: [PATCH 4/7] Add HA version deprecation --- homeassistant/components/glances/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/homeassistant/components/glances/__init__.py b/homeassistant/components/glances/__init__.py index 463ee3f0a2f10c..e199ed60feb38f 100644 --- a/homeassistant/components/glances/__init__.py +++ b/homeassistant/components/glances/__init__.py @@ -92,6 +92,7 @@ async def get_api(hass: HomeAssistant, entry_data: dict[str, Any]) -> Glances: hass, DOMAIN, "deprecated_version", + breaks_in_ha_version="2024.6.1", is_fixable=False, severity=IssueSeverity.WARNING, translation_key="deprecated_version", From 11dab60d661275cc424f32342ca791916cc72e0e Mon Sep 17 00:00:00 2001 From: Martin Hjelmare Date: Sat, 30 Dec 2023 01:52:53 +0100 Subject: [PATCH 5/7] Apply suggestions from code review --- homeassistant/components/glances/__init__.py | 2 +- homeassistant/components/glances/strings.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/glances/__init__.py b/homeassistant/components/glances/__init__.py index e199ed60feb38f..3f13bfe84f1bce 100644 --- a/homeassistant/components/glances/__init__.py +++ b/homeassistant/components/glances/__init__.py @@ -92,7 +92,7 @@ async def get_api(hass: HomeAssistant, entry_data: dict[str, Any]) -> Glances: hass, DOMAIN, "deprecated_version", - breaks_in_ha_version="2024.6.1", + breaks_in_ha_version="2024.8.1", is_fixable=False, severity=IssueSeverity.WARNING, translation_key="deprecated_version", diff --git a/homeassistant/components/glances/strings.json b/homeassistant/components/glances/strings.json index a63620a9d6912a..7e69e7f7912f6c 100644 --- a/homeassistant/components/glances/strings.json +++ b/homeassistant/components/glances/strings.json @@ -33,7 +33,7 @@ "issues": { "deprecated_version": { "title": "Glances servers with version 2 is deprecated", - "description": "Glances servers with version 2 is deprecated and will not be supported in future versions of HA. It is recommended to update your server to Glances version 3 then reload the config entry." + "description": "Glances servers with version 2 is deprecated and will not be supported in future versions of HA. It is recommended to update your server to Glances version 3 then reload the integration." } } } From 629f1019b30e5310f89e86ccb95e34499eb0cf55 Mon Sep 17 00:00:00 2001 From: Rami Mousleh Date: Sat, 30 Dec 2023 09:25:39 +0000 Subject: [PATCH 6/7] update config flow tests --- homeassistant/components/glances/config_flow.py | 4 ++-- tests/components/glances/test_config_flow.py | 10 +++------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/glances/config_flow.py b/homeassistant/components/glances/config_flow.py index 8f02d715c285ab..81d3a1187290f5 100644 --- a/homeassistant/components/glances/config_flow.py +++ b/homeassistant/components/glances/config_flow.py @@ -61,7 +61,7 @@ async def async_step_reauth_confirm( await get_api(self.hass, user_input) except GlancesApiAuthorizationError: errors["base"] = "invalid_auth" - except (GlancesApiConnectionError, ServerVersionMismatch): + except GlancesApiConnectionError: errors["base"] = "cannot_connect" else: self.hass.config_entries.async_update_entry( @@ -96,7 +96,7 @@ async def async_step_user( await get_api(self.hass, user_input) except GlancesApiAuthorizationError: errors["base"] = "invalid_auth" - except GlancesApiConnectionError: + except (GlancesApiConnectionError, ServerVersionMismatch): errors["base"] = "cannot_connect" else: return self.async_create_entry( diff --git a/tests/components/glances/test_config_flow.py b/tests/components/glances/test_config_flow.py index 87ec80da057b45..8d590317c619df 100644 --- a/tests/components/glances/test_config_flow.py +++ b/tests/components/glances/test_config_flow.py @@ -4,6 +4,7 @@ from glances_api.exceptions import ( GlancesApiAuthorizationError, GlancesApiConnectionError, + GlancesApiNoDataAvailable, ) import pytest @@ -47,6 +48,7 @@ async def test_form(hass: HomeAssistant) -> None: [ (GlancesApiAuthorizationError, "invalid_auth"), (GlancesApiConnectionError, "cannot_connect"), + (GlancesApiNoDataAvailable, "cannot_connect"), ], ) async def test_form_fails( @@ -54,7 +56,7 @@ async def test_form_fails( ) -> None: """Test flow fails when api exception is raised.""" - mock_api.return_value.get_ha_sensor_data.side_effect = [error, HA_SENSOR_DATA] + mock_api.return_value.get_ha_sensor_data.side_effect = error result = await hass.config_entries.flow.async_init( glances.DOMAIN, context={"source": config_entries.SOURCE_USER} ) @@ -65,12 +67,6 @@ async def test_form_fails( assert result["type"] == FlowResultType.FORM assert result["errors"] == {"base": message} - result = await hass.config_entries.flow.async_configure( - result["flow_id"], user_input=MOCK_USER_INPUT - ) - - assert result["type"] == FlowResultType.CREATE_ENTRY - async def test_form_already_configured(hass: HomeAssistant) -> None: """Test host is already configured.""" From 1f94a1f444877744d59686ef77aecb9cfc41825e Mon Sep 17 00:00:00 2001 From: Martin Hjelmare Date: Wed, 3 Jan 2024 20:50:01 +0100 Subject: [PATCH 7/7] Fix breaks in ha version --- homeassistant/components/glances/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/glances/__init__.py b/homeassistant/components/glances/__init__.py index 3f13bfe84f1bce..1c03f8c1dbfe04 100644 --- a/homeassistant/components/glances/__init__.py +++ b/homeassistant/components/glances/__init__.py @@ -92,7 +92,7 @@ async def get_api(hass: HomeAssistant, entry_data: dict[str, Any]) -> Glances: hass, DOMAIN, "deprecated_version", - breaks_in_ha_version="2024.8.1", + breaks_in_ha_version="2024.8.0", is_fixable=False, severity=IssueSeverity.WARNING, translation_key="deprecated_version",