Remove deprecated speedtest service from Fast.com (#119780)
* Remove deprecated speedtest service from Fast.com * Remove not needed tests
This commit is contained in:
parent
d1d21811fa
commit
8556f3e7c8
7 changed files with 0 additions and 204 deletions
|
@ -6,24 +6,13 @@ import logging
|
|||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.start import async_at_started
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .const import DOMAIN, PLATFORMS
|
||||
from .coordinator import FastdotcomDataUpdateCoordinator
|
||||
from .services import async_setup_services
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up the Fastdotcom component."""
|
||||
async_setup_services(hass)
|
||||
return True
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up Fast.com from a config entry."""
|
||||
|
|
|
@ -5,8 +5,5 @@
|
|||
"default": "mdi:speedometer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"services": {
|
||||
"speedtest": "mdi:speedometer"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
"""Services for the Fastdotcom integration."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import issue_registry as ir
|
||||
|
||||
from .const import DOMAIN, SERVICE_NAME
|
||||
from .coordinator import FastdotcomDataUpdateCoordinator
|
||||
|
||||
|
||||
def async_setup_services(hass: HomeAssistant) -> None:
|
||||
"""Set up the service for the Fastdotcom integration."""
|
||||
|
||||
@callback
|
||||
def collect_coordinator() -> FastdotcomDataUpdateCoordinator:
|
||||
"""Collect the coordinator Fastdotcom."""
|
||||
config_entries = hass.config_entries.async_entries(DOMAIN)
|
||||
if not config_entries:
|
||||
raise HomeAssistantError("No Fast.com config entries found")
|
||||
|
||||
for config_entry in config_entries:
|
||||
if config_entry.state != ConfigEntryState.LOADED:
|
||||
raise HomeAssistantError(f"{config_entry.title} is not loaded")
|
||||
coordinator: FastdotcomDataUpdateCoordinator = hass.data[DOMAIN][
|
||||
config_entry.entry_id
|
||||
]
|
||||
break
|
||||
return coordinator
|
||||
|
||||
async def async_perform_service(call: ServiceCall) -> None:
|
||||
"""Perform a service call to manually run Fastdotcom."""
|
||||
ir.async_create_issue(
|
||||
hass,
|
||||
DOMAIN,
|
||||
"service_deprecation",
|
||||
breaks_in_ha_version="2024.7.0",
|
||||
is_fixable=True,
|
||||
is_persistent=True,
|
||||
severity=ir.IssueSeverity.WARNING,
|
||||
translation_key="service_deprecation",
|
||||
)
|
||||
coordinator = collect_coordinator()
|
||||
await coordinator.async_request_refresh()
|
||||
|
||||
hass.services.async_register(
|
||||
DOMAIN,
|
||||
SERVICE_NAME,
|
||||
async_perform_service,
|
||||
)
|
|
@ -1 +0,0 @@
|
|||
speedtest:
|
|
@ -15,24 +15,5 @@
|
|||
"name": "Download"
|
||||
}
|
||||
}
|
||||
},
|
||||
"services": {
|
||||
"speedtest": {
|
||||
"name": "Speed test",
|
||||
"description": "Immediately executes a speed test with Fast.com."
|
||||
}
|
||||
},
|
||||
"issues": {
|
||||
"service_deprecation": {
|
||||
"title": "Fast.com speedtest service is being removed",
|
||||
"fix_flow": {
|
||||
"step": {
|
||||
"confirm": {
|
||||
"title": "[%key:component::fastdotcom::issues::service_deprecation::title%]",
|
||||
"description": "Use `homeassistant.update_entity` instead to update the data.\n\nPlease replace this service and adjust your automations and scripts and select **submit** to fix this issue."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ from homeassistant.components.fastdotcom.const import DEFAULT_NAME, DOMAIN
|
|||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.const import EVENT_HOMEASSISTANT_STARTED, STATE_UNKNOWN
|
||||
from homeassistant.core import CoreState, HomeAssistant
|
||||
from homeassistant.helpers import issue_registry as ir
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
@ -70,32 +69,3 @@ async def test_delayed_speedtest_during_startup(
|
|||
assert state.state == "5.0"
|
||||
|
||||
assert config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
|
||||
async def test_service_deprecated(
|
||||
hass: HomeAssistant, issue_registry: ir.IssueRegistry
|
||||
) -> None:
|
||||
"""Test deprecated service."""
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
unique_id="UNIQUE_TEST_ID",
|
||||
title=DEFAULT_NAME,
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
with patch(
|
||||
"homeassistant.components.fastdotcom.coordinator.fast_com", return_value=5.0
|
||||
):
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
"speedtest",
|
||||
{},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
issue = issue_registry.async_get_issue(DOMAIN, "service_deprecation")
|
||||
assert issue
|
||||
assert issue.is_fixable is True
|
||||
assert issue.translation_key == "service_deprecation"
|
||||
|
|
|
@ -1,88 +0,0 @@
|
|||
"""Test Fastdotcom service."""
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.fastdotcom.const import DEFAULT_NAME, DOMAIN, SERVICE_NAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_service(hass: HomeAssistant) -> None:
|
||||
"""Test the Fastdotcom service."""
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
unique_id="UNIQUE_TEST_ID",
|
||||
title=DEFAULT_NAME,
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.fastdotcom.coordinator.fast_com", return_value=0
|
||||
):
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("sensor.fast_com_download")
|
||||
assert state is not None
|
||||
assert state.state == "0"
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.fastdotcom.coordinator.fast_com", return_value=5.0
|
||||
):
|
||||
await hass.services.async_call(DOMAIN, SERVICE_NAME, blocking=True)
|
||||
|
||||
state = hass.states.get("sensor.fast_com_download")
|
||||
assert state is not None
|
||||
assert state.state == "5.0"
|
||||
|
||||
|
||||
async def test_service_unloaded_entry(hass: HomeAssistant) -> None:
|
||||
"""Test service called when config entry unloaded."""
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
unique_id="UNIQUE_TEST_ID",
|
||||
title=DEFAULT_NAME,
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.fastdotcom.coordinator.fast_com", return_value=0
|
||||
):
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert config_entry
|
||||
await hass.config_entries.async_unload(config_entry.entry_id)
|
||||
|
||||
with pytest.raises(HomeAssistantError) as exc:
|
||||
await hass.services.async_call(DOMAIN, SERVICE_NAME, blocking=True)
|
||||
|
||||
assert "Fast.com is not loaded" in str(exc)
|
||||
|
||||
|
||||
async def test_service_removed_entry(hass: HomeAssistant) -> None:
|
||||
"""Test service called when config entry was removed and HA was not restarted yet."""
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
unique_id="UNIQUE_TEST_ID",
|
||||
title=DEFAULT_NAME,
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.fastdotcom.coordinator.fast_com", return_value=0
|
||||
):
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert config_entry
|
||||
await hass.config_entries.async_remove(config_entry.entry_id)
|
||||
|
||||
with pytest.raises(HomeAssistantError) as exc:
|
||||
await hass.services.async_call(DOMAIN, SERVICE_NAME, blocking=True)
|
||||
|
||||
assert "No Fast.com config entries found" in str(exc)
|
Loading…
Add table
Add a link
Reference in a new issue