mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Remove deprecated v2 api from glances (#131427)
This commit is contained in:
parent
9b8316df3f
commit
2a52de48c5
@ -28,9 +28,7 @@ from homeassistant.exceptions import (
|
||||
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]
|
||||
@ -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],
|
||||
@ -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):
|
||||
|
@ -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."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
@ -10,14 +10,14 @@ from glances_api.exceptions import (
|
||||
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)
|
||||
@ -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"
|
||||
@ -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
|
||||
@ -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
|
||||
@ -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)
|
||||
@ -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]
|
||||
|
@ -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,
|
||||
@ -12,9 +12,8 @@ import pytest
|
||||
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
|
||||
|
||||
@ -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"),
|
||||
[
|
||||
|
Loading…
x
Reference in New Issue
Block a user