Skip to content

Commit

Permalink
Remove deprecate service in speedtestdotnet (home-assistant#80938)
Browse files Browse the repository at this point in the history
Remove deprecate service
  • Loading branch information
engrbm87 authored Oct 25, 2022
1 parent 13e2bb1 commit d3ada34
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 78 deletions.
30 changes: 1 addition & 29 deletions homeassistant/components/speedtestdotnet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_SCAN_INTERVAL, EVENT_HOMEASSISTANT_STARTED
from homeassistant.core import CoreState, HomeAssistant, ServiceCall
from homeassistant.core import CoreState, HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed

from .const import (
Expand All @@ -20,7 +19,6 @@
DEFAULT_SERVER,
DOMAIN,
PLATFORMS,
SPEED_TEST_SERVICE,
)

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -58,8 +56,6 @@ async def _enable_scheduled_speedtests(*_):

async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
"""Unload SpeedTest Entry from config_entry."""
hass.services.async_remove(DOMAIN, SPEED_TEST_SERVICE)

unload_ok = await hass.config_entries.async_unload_platforms(
config_entry, PLATFORMS
)
Expand Down Expand Up @@ -141,30 +137,6 @@ async def async_setup(self) -> None:
except speedtest.SpeedtestException as err:
raise ConfigEntryNotReady from err

async def request_update(call: ServiceCall) -> None:
"""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()

self.hass.services.async_register(DOMAIN, SPEED_TEST_SERVICE, request_update)

self.config_entry.async_on_unload(
self.config_entry.add_update_listener(options_updated_listener)
)
Expand Down
2 changes: 0 additions & 2 deletions homeassistant/components/speedtestdotnet/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

DOMAIN: Final = "speedtestdotnet"

SPEED_TEST_SERVICE: Final = "speedtest"


@dataclass
class SpeedtestSensorEntityDescription(SensorEntityDescription):
Expand Down
3 changes: 0 additions & 3 deletions homeassistant/components/speedtestdotnet/services.yaml

This file was deleted.

13 changes: 0 additions & 13 deletions homeassistant/components/speedtestdotnet/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,5 @@
}
}
}
},
"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."
}
}
}
}
}
}
31 changes: 0 additions & 31 deletions tests/components/speedtestdotnet/test_init.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
"""Tests for SpeedTest integration."""

from collections.abc import Awaitable
from datetime import timedelta
from typing import Callable
from unittest.mock import MagicMock

from aiohttp import ClientWebSocketResponse
import speedtest

from homeassistant.components.speedtestdotnet.const import (
CONF_MANUAL,
CONF_SERVER_ID,
CONF_SERVER_NAME,
DOMAIN,
SPEED_TEST_SERVICE,
)
from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import CONF_SCAN_INTERVAL, STATE_UNAVAILABLE
from homeassistant.core import HomeAssistant
import homeassistant.util.dt as dt_util

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:
Expand All @@ -43,7 +38,6 @@ async def test_successful_config_entry(hass: HomeAssistant) -> None:

assert entry.state == ConfigEntryState.LOADED
assert hass.data[DOMAIN]
assert hass.services.has_service(DOMAIN, SPEED_TEST_SERVICE)


async def test_setup_failed(hass: HomeAssistant, mock_api: MagicMock) -> None:
Expand Down Expand Up @@ -125,28 +119,3 @@ async def test_get_best_server_error(hass: HomeAssistant, mock_api: MagicMock) -
state = hass.states.get("sensor.speedtest_ping")
assert state is not None
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"

0 comments on commit d3ada34

Please sign in to comment.