Speedtestdotnet - use server name to generate server list (#39775)

pull/40092/head
r4nd0mbr1ck 2020-09-15 15:50:44 +10:00 committed by GitHub
parent 903afb62d0
commit 11319ac479
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 6 deletions

View File

@ -143,9 +143,12 @@ class SpeedTestDataCoordinator(DataUpdateCoordinator):
self.servers[DEFAULT_SERVER] = {} self.servers[DEFAULT_SERVER] = {}
for server in sorted( for server in sorted(
server_list.values(), key=lambda server: server[0]["country"] server_list.values(),
key=lambda server: server[0]["country"] + server[0]["sponsor"],
): ):
self.servers[f"{server[0]['country']} - {server[0]['sponsor']}"] = server[0] self.servers[
f"{server[0]['country']} - {server[0]['sponsor']} - {server[0]['name']}"
] = server[0]
def update_data(self): def update_data(self):
"""Get the latest data from speedtest.net.""" """Get the latest data from speedtest.net."""

View File

@ -9,7 +9,7 @@ MOCK_SERVERS = {
"name": "Server1", "name": "Server1",
"country": "Country1", "country": "Country1",
"cc": "LL1", "cc": "LL1",
"sponsor": "Server1", "sponsor": "Sponsor1",
"id": "1", "id": "1",
"host": "server1:8080", "host": "server1:8080",
"d": 1, "d": 1,
@ -23,7 +23,7 @@ MOCK_SERVERS = {
"name": "Server2", "name": "Server2",
"country": "Country2", "country": "Country2",
"cc": "LL2", "cc": "LL2",
"sponsor": "server2", "sponsor": "Sponsor2",
"id": "2", "id": "2",
"host": "server2:8080", "host": "server2:8080",
"d": 2, "d": 2,

View File

@ -108,7 +108,7 @@ async def test_options(hass):
result = await hass.config_entries.options.async_configure( result = await hass.config_entries.options.async_configure(
result["flow_id"], result["flow_id"],
user_input={ user_input={
CONF_SERVER_NAME: "Country1 - Server1", CONF_SERVER_NAME: "Country1 - Sponsor1 - Server1",
CONF_SCAN_INTERVAL: 30, CONF_SCAN_INTERVAL: 30,
CONF_MANUAL: False, CONF_MANUAL: False,
}, },
@ -116,7 +116,7 @@ async def test_options(hass):
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["data"] == { assert result["data"] == {
CONF_SERVER_NAME: "Country1 - Server1", CONF_SERVER_NAME: "Country1 - Sponsor1 - Server1",
CONF_SERVER_ID: "1", CONF_SERVER_ID: "1",
CONF_SCAN_INTERVAL: 30, CONF_SCAN_INTERVAL: 30,
CONF_MANUAL: False, CONF_MANUAL: False,