Deprecate speedtest service (#77261)

deprecate speedtest service
This commit is contained in:
Rami Mosleh 2022-08-26 21:57:43 +03:00 committed by GitHub
parent 5af015dd7d
commit b36321988f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 77 additions and 0 deletions

View File

@ -6,6 +6,8 @@ import logging
import speedtest import speedtest
from homeassistant.components.repairs.issue_handler import async_create_issue
from homeassistant.components.repairs.models import IssueSeverity
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_SCAN_INTERVAL, EVENT_HOMEASSISTANT_STARTED from homeassistant.const import CONF_SCAN_INTERVAL, EVENT_HOMEASSISTANT_STARTED
from homeassistant.core import CoreState, HomeAssistant, ServiceCall from homeassistant.core import CoreState, HomeAssistant, ServiceCall
@ -142,6 +144,24 @@ class SpeedTestDataCoordinator(DataUpdateCoordinator):
async def request_update(call: ServiceCall) -> None: async def request_update(call: ServiceCall) -> None:
"""Request update.""" """Request update."""
async_create_issue(
self.hass,
DOMAIN,
"deprecated_service",
breaks_in_ha_version="2022.11.0",
is_fixable=True,
is_persistent=True,
severity=IssueSeverity.WARNING,
translation_key="deprecated_service",
)
_LOGGER.warning(
(
'The "%s" service is deprecated and will be removed in "2022.11.0"; '
'use the "homeassistant.update_entity" service and pass it a target Speedtest entity_id'
),
SPEED_TEST_SERVICE,
)
await self.async_request_refresh() await self.async_request_refresh()
self.hass.services.async_register(DOMAIN, SPEED_TEST_SERVICE, request_update) self.hass.services.async_register(DOMAIN, SPEED_TEST_SERVICE, request_update)

View File

@ -3,6 +3,7 @@
"name": "Speedtest.net", "name": "Speedtest.net",
"config_flow": true, "config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/speedtestdotnet", "documentation": "https://www.home-assistant.io/integrations/speedtestdotnet",
"dependencies": ["repairs"],
"requirements": ["speedtest-cli==2.1.3"], "requirements": ["speedtest-cli==2.1.3"],
"codeowners": ["@rohankapoorcom", "@engrbm87"], "codeowners": ["@rohankapoorcom", "@engrbm87"],
"iot_class": "cloud_polling" "iot_class": "cloud_polling"

View File

@ -19,5 +19,18 @@
} }
} }
} }
},
"issues": {
"deprecated_service": {
"title": "The speedtest service is being removed",
"fix_flow": {
"step": {
"confirm": {
"title": "The speedtest service is being removed",
"description": "Update any automations or scripts that use this service to instead use the `homeassistant.update_entity` service with a target Speedtest entity_id. Then, click SUBMIT below to mark this issue as resolved."
}
}
}
}
} }
} }

View File

@ -9,6 +9,19 @@
} }
} }
}, },
"issues": {
"deprecated_service": {
"fix_flow": {
"step": {
"confirm": {
"description": "Update any automations or scripts that use this service to instead use the `homeassistant.update_entity` service with a target Speedtest entity_id. Then, click SUBMIT below to mark this issue as resolved.",
"title": "The speedtest service is being removed"
}
}
},
"title": "The speedtest service is being removed"
}
},
"options": { "options": {
"step": { "step": {
"init": { "init": {

View File

@ -1,7 +1,11 @@
"""Tests for SpeedTest integration.""" """Tests for SpeedTest integration."""
from collections.abc import Awaitable
from datetime import timedelta from datetime import timedelta
from typing import Callable
from unittest.mock import MagicMock from unittest.mock import MagicMock
from aiohttp import ClientWebSocketResponse
import speedtest import speedtest
from homeassistant.components.speedtestdotnet.const import ( from homeassistant.components.speedtestdotnet.const import (
@ -17,6 +21,7 @@ from homeassistant.core import HomeAssistant
import homeassistant.util.dt as dt_util import homeassistant.util.dt as dt_util
from tests.common import MockConfigEntry, async_fire_time_changed from tests.common import MockConfigEntry, async_fire_time_changed
from tests.components.repairs import get_repairs
async def test_successful_config_entry(hass: HomeAssistant) -> None: async def test_successful_config_entry(hass: HomeAssistant) -> None:
@ -120,3 +125,28 @@ async def test_get_best_server_error(hass: HomeAssistant, mock_api: MagicMock) -
state = hass.states.get("sensor.speedtest_ping") state = hass.states.get("sensor.speedtest_ping")
assert state is not None assert state is not None
assert state.state == STATE_UNAVAILABLE assert state.state == STATE_UNAVAILABLE
async def test_deprecated_service_alert(
hass: HomeAssistant,
hass_ws_client: Callable[[HomeAssistant], Awaitable[ClientWebSocketResponse]],
) -> None:
"""Test that an issue is raised if deprecated services is called."""
entry = MockConfigEntry(
domain=DOMAIN,
)
entry.add_to_hass(hass)
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
await hass.services.async_call(
DOMAIN,
"speedtest",
{},
blocking=True,
)
await hass.async_block_till_done()
issues = await get_repairs(hass, hass_ws_client)
assert len(issues) == 1
assert issues[0]["issue_id"] == "deprecated_service"