Store runtime data inside the config entry in Speedtest.net (#116802)
This commit is contained in:
parent
65120e5789
commit
55ffc82be1
6 changed files with 29 additions and 29 deletions
|
@ -10,6 +10,9 @@ from homeassistant.components.speedtestdotnet.const import (
|
|||
CONF_SERVER_NAME,
|
||||
DOMAIN,
|
||||
)
|
||||
from homeassistant.components.speedtestdotnet.coordinator import (
|
||||
SpeedTestDataCoordinator,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.const import STATE_UNAVAILABLE
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
@ -47,13 +50,12 @@ async def test_entry_lifecycle(hass: HomeAssistant, mock_api: MagicMock) -> None
|
|||
await hass.async_block_till_done()
|
||||
|
||||
assert entry.state is ConfigEntryState.LOADED
|
||||
assert hass.data[DOMAIN]
|
||||
assert isinstance(entry.runtime_data, SpeedTestDataCoordinator)
|
||||
|
||||
assert await hass.config_entries.async_unload(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert entry.state is ConfigEntryState.NOT_LOADED
|
||||
assert DOMAIN not in hass.data
|
||||
|
||||
|
||||
async def test_server_not_found(hass: HomeAssistant, mock_api: MagicMock) -> None:
|
||||
|
@ -67,7 +69,9 @@ async def test_server_not_found(hass: HomeAssistant, mock_api: MagicMock) -> Non
|
|||
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
assert hass.data[DOMAIN]
|
||||
|
||||
assert entry.state is ConfigEntryState.LOADED
|
||||
assert isinstance(entry.runtime_data, SpeedTestDataCoordinator)
|
||||
|
||||
mock_api.return_value.get_servers.side_effect = speedtest.NoMatchedServers
|
||||
async_fire_time_changed(
|
||||
|
@ -90,14 +94,16 @@ async def test_get_best_server_error(hass: HomeAssistant, mock_api: MagicMock) -
|
|||
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
assert hass.data[DOMAIN]
|
||||
|
||||
assert entry.state is ConfigEntryState.LOADED
|
||||
assert isinstance(entry.runtime_data, SpeedTestDataCoordinator)
|
||||
|
||||
mock_api.return_value.get_best_server.side_effect = (
|
||||
speedtest.SpeedtestBestServerFailure(
|
||||
"Unable to connect to servers to test latency."
|
||||
)
|
||||
)
|
||||
await hass.data[DOMAIN].async_refresh()
|
||||
await entry.runtime_data.async_refresh()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("sensor.speedtest_ping")
|
||||
assert state is not None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue