Catch exception when user has no lastfm friends (#94235)
This commit is contained in:
parent
758eb5e510
commit
20449d1f01
2 changed files with 5 additions and 5 deletions
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
||||||
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from pylast import LastFMNetwork, User, WSError
|
from pylast import LastFMNetwork, PyLastError, User, WSError
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.config_entries import (
|
from homeassistant.config_entries import (
|
||||||
|
@ -135,7 +135,7 @@ class LastFmConfigFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||||
SelectOptionDict(value=friend.name, label=friend.get_name(True))
|
SelectOptionDict(value=friend.name, label=friend.get_name(True))
|
||||||
for friend in friends_response
|
for friend in friends_response
|
||||||
]
|
]
|
||||||
except WSError:
|
except PyLastError:
|
||||||
friends = []
|
friends = []
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="friends",
|
step_id="friends",
|
||||||
|
@ -207,7 +207,7 @@ class LastFmOptionsFlowHandler(OptionsFlowWithConfigEntry):
|
||||||
SelectOptionDict(value=friend.name, label=friend.get_name(True))
|
SelectOptionDict(value=friend.name, label=friend.get_name(True))
|
||||||
for friend in friends_response
|
for friend in friends_response
|
||||||
]
|
]
|
||||||
except WSError:
|
except PyLastError:
|
||||||
friends = []
|
friends = []
|
||||||
else:
|
else:
|
||||||
friends = []
|
friends = []
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
"""The tests for lastfm."""
|
"""The tests for lastfm."""
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from pylast import Track, WSError
|
from pylast import PyLastError, Track
|
||||||
|
|
||||||
from homeassistant.components.lastfm.const import CONF_MAIN_USER, CONF_USERS
|
from homeassistant.components.lastfm.const import CONF_MAIN_USER, CONF_USERS
|
||||||
from homeassistant.const import CONF_API_KEY
|
from homeassistant.const import CONF_API_KEY
|
||||||
|
@ -65,7 +65,7 @@ class MockUser:
|
||||||
def get_friends(self):
|
def get_friends(self):
|
||||||
"""Get mock friends."""
|
"""Get mock friends."""
|
||||||
if self._has_friends is False:
|
if self._has_friends is False:
|
||||||
raise WSError("network", "status", "Page not found")
|
raise PyLastError("network", "status", "Page not found")
|
||||||
return [MockUser(None, None, True, USERNAME_2)]
|
return [MockUser(None, None, True, USERNAME_2)]
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue