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 deprecated v2 api from glances #131427

Merged
merged 4 commits into from
Nov 25, 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
16 changes: 2 additions & 14 deletions homeassistant/components/glances/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
HomeAssistantError,
)
from homeassistant.helpers.httpx_client import get_async_client
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue

from .const import DOMAIN
from .coordinator import GlancesDataUpdateCoordinator

PLATFORMS = [Platform.SENSOR]
Expand Down Expand Up @@ -71,7 +69,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: GlancesConfigEntry) ->
async def get_api(hass: HomeAssistant, entry_data: dict[str, Any]) -> Glances:
"""Return the api from glances_api."""
httpx_client = get_async_client(hass, verify_ssl=entry_data[CONF_VERIFY_SSL])
for version in (4, 3, 2):
for version in (4, 3):
api = Glances(
host=entry_data[CONF_HOST],
port=entry_data[CONF_PORT],
Expand All @@ -86,19 +84,9 @@ async def get_api(hass: HomeAssistant, entry_data: dict[str, Any]) -> Glances:
except GlancesApiNoDataAvailable as err:
_LOGGER.debug("Failed to connect to Glances API v%s: %s", version, err)
continue
if version == 2:
async_create_issue(
hass,
DOMAIN,
"deprecated_version",
breaks_in_ha_version="2024.8.0",
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, 3 or 4")
raise ServerVersionMismatch("Could not connect to Glances API version 3 or 4")


class ServerVersionMismatch(HomeAssistantError):
Expand Down
6 changes: 0 additions & 6 deletions homeassistant/components/glances/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,5 @@
"name": "{sensor_label} TX"
}
}
},
"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 integration."
}
}
}
18 changes: 9 additions & 9 deletions tests/components/glances/test_config_flow.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Tests for Glances config flow."""

from unittest.mock import MagicMock
from unittest.mock import MagicMock, patch

from glances_api.exceptions import (
GlancesApiAuthorizationError,
Expand All @@ -10,14 +10,14 @@
import pytest

from homeassistant import config_entries
from homeassistant.components import glances
from homeassistant.components.glances.const import DOMAIN
from homeassistant.const import CONF_NAME, CONF_USERNAME
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType

from . import HA_SENSOR_DATA, MOCK_USER_INPUT

from tests.common import MockConfigEntry, patch
from tests.common import MockConfigEntry


@pytest.fixture(autouse=True)
Expand All @@ -31,7 +31,7 @@ async def test_form(hass: HomeAssistant) -> None:
"""Test config entry configured successfully."""

result = await hass.config_entries.flow.async_init(
glances.DOMAIN, context={"source": config_entries.SOURCE_USER}
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "user"
Expand Down Expand Up @@ -60,7 +60,7 @@ async def test_form_fails(

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}
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
result = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input=MOCK_USER_INPUT
Expand All @@ -72,11 +72,11 @@ async def test_form_fails(

async def test_form_already_configured(hass: HomeAssistant) -> None:
"""Test host is already configured."""
entry = MockConfigEntry(domain=glances.DOMAIN, data=MOCK_USER_INPUT)
entry = MockConfigEntry(domain=DOMAIN, data=MOCK_USER_INPUT)
entry.add_to_hass(hass)

result = await hass.config_entries.flow.async_init(
glances.DOMAIN, context={"source": config_entries.SOURCE_USER}
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
result = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input=MOCK_USER_INPUT
Expand All @@ -87,7 +87,7 @@ async def test_form_already_configured(hass: HomeAssistant) -> None:

async def test_reauth_success(hass: HomeAssistant) -> None:
"""Test we can reauth."""
entry = MockConfigEntry(domain=glances.DOMAIN, data=MOCK_USER_INPUT)
entry = MockConfigEntry(domain=DOMAIN, data=MOCK_USER_INPUT)
entry.add_to_hass(hass)

result = await entry.start_reauth_flow(hass)
Expand Down Expand Up @@ -120,7 +120,7 @@ async def test_reauth_fails(
hass: HomeAssistant, error: Exception, message: str, mock_api: MagicMock
) -> None:
"""Test we can reauth."""
entry = MockConfigEntry(domain=glances.DOMAIN, data=MOCK_USER_INPUT)
entry = MockConfigEntry(domain=DOMAIN, data=MOCK_USER_INPUT)
entry.add_to_hass(hass)

mock_api.return_value.get_ha_sensor_data.side_effect = [error, HA_SENSOR_DATA]
Expand Down
28 changes: 2 additions & 26 deletions tests/components/glances/test_init.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Tests for Glances integration."""

from unittest.mock import AsyncMock, MagicMock
from unittest.mock import MagicMock

from glances_api.exceptions import (
GlancesApiAuthorizationError,
Expand All @@ -12,9 +12,8 @@
from homeassistant.components.glances.const import DOMAIN
from homeassistant.config_entries import ConfigEntryState
from homeassistant.core import HomeAssistant
from homeassistant.helpers import issue_registry as ir

from . import HA_SENSOR_DATA, MOCK_USER_INPUT
from . import MOCK_USER_INPUT

from tests.common import MockConfigEntry

Expand All @@ -30,29 +29,6 @@ async def test_successful_config_entry(hass: HomeAssistant) -> None:
assert entry.state is ConfigEntryState.LOADED


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."""
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"), # fail v4
GlancesApiNoDataAvailable("endpoint: 'all' is not valid"), # fail v3
HA_SENSOR_DATA, # success v2
HA_SENSOR_DATA,
]

await hass.config_entries.async_setup(entry.entry_id)

assert entry.state is ConfigEntryState.LOADED

issue = issue_registry.async_get_issue(DOMAIN, "deprecated_version")
assert issue is not None
assert issue.severity == ir.IssueSeverity.WARNING


@pytest.mark.parametrize(
("error", "entry_state"),
[
Expand Down