Speedtestdotnet code cleanup and type hints (#52533)
This commit is contained in:
parent
7768f53281
commit
1a450c2084
11 changed files with 287 additions and 237 deletions
|
@ -1,26 +1,28 @@
|
|||
"""Tests for SpeedTest sensors."""
|
||||
from unittest.mock import patch
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from homeassistant.components import speedtestdotnet
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||||
from homeassistant.components.speedtestdotnet.const import DEFAULT_NAME, SENSOR_TYPES
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import MOCK_RESULTS, MOCK_SERVERS, MOCK_STATES
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_speedtestdotnet_sensors(hass):
|
||||
async def test_speedtestdotnet_sensors(
|
||||
hass: HomeAssistant, mock_api: MagicMock
|
||||
) -> None:
|
||||
"""Test sensors created for speedtestdotnet integration."""
|
||||
entry = MockConfigEntry(domain=speedtestdotnet.DOMAIN, data={})
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
with patch("speedtest.Speedtest") as mock_api:
|
||||
mock_api.return_value.get_best_server.return_value = MOCK_SERVERS[1][0]
|
||||
mock_api.return_value.results.dict.return_value = MOCK_RESULTS
|
||||
mock_api.return_value.get_best_server.return_value = MOCK_SERVERS[1][0]
|
||||
mock_api.return_value.results.dict.return_value = MOCK_RESULTS
|
||||
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 3
|
||||
|
||||
|
@ -28,4 +30,5 @@ async def test_speedtestdotnet_sensors(hass):
|
|||
sensor = hass.states.get(
|
||||
f"sensor.{DEFAULT_NAME}_{SENSOR_TYPES[sensor_type][0]}"
|
||||
)
|
||||
assert sensor
|
||||
assert sensor.state == MOCK_STATES[sensor_type]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue