Catch exception when user has no lastfm friends (#94235)
parent
2b1c45c28c
commit
8705a26a1a
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
|||
|
||||
from typing import Any
|
||||
|
||||
from pylast import LastFMNetwork, User, WSError
|
||||
from pylast import LastFMNetwork, PyLastError, User, WSError
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.config_entries import (
|
||||
|
@ -132,7 +132,7 @@ class LastFmConfigFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||
SelectOptionDict(value=friend.name, label=friend.get_name(True))
|
||||
for friend in main_user.get_friends()
|
||||
]
|
||||
except WSError:
|
||||
except PyLastError:
|
||||
friends = []
|
||||
return self.async_show_form(
|
||||
step_id="friends",
|
||||
|
@ -201,7 +201,7 @@ class LastFmOptionsFlowHandler(OptionsFlowWithConfigEntry):
|
|||
SelectOptionDict(value=friend.name, label=friend.get_name(True))
|
||||
for friend in main_user.get_friends()
|
||||
]
|
||||
except WSError:
|
||||
except PyLastError:
|
||||
friends = []
|
||||
else:
|
||||
friends = []
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
"""The tests for lastfm."""
|
||||
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.const import CONF_API_KEY
|
||||
|
@ -65,7 +65,7 @@ class MockUser:
|
|||
def get_friends(self):
|
||||
"""Get mock friends."""
|
||||
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)]
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue