Don't fail on successful relogin in pyLoad integration (#138936)
* Don't fail on successful relogin * loggingpull/139008/head
parent
d522571308
commit
8068f82888
|
@ -59,14 +59,11 @@ class PyLoadCoordinator(DataUpdateCoordinator[PyLoadData]):
|
|||
async def _async_update_data(self) -> PyLoadData:
|
||||
"""Fetch data from API endpoint."""
|
||||
try:
|
||||
if not self.version:
|
||||
self.version = await self.pyload.version()
|
||||
return PyLoadData(
|
||||
**await self.pyload.get_status(),
|
||||
free_space=await self.pyload.free_space(),
|
||||
)
|
||||
|
||||
except InvalidAuth as e:
|
||||
except InvalidAuth:
|
||||
try:
|
||||
await self.pyload.login()
|
||||
except InvalidAuth as exc:
|
||||
|
@ -75,10 +72,10 @@ class PyLoadCoordinator(DataUpdateCoordinator[PyLoadData]):
|
|||
translation_key="setup_authentication_exception",
|
||||
translation_placeholders={CONF_USERNAME: self.pyload.username},
|
||||
) from exc
|
||||
|
||||
raise UpdateFailed(
|
||||
"Unable to retrieve data due to cookie expiration"
|
||||
) from e
|
||||
_LOGGER.debug(
|
||||
"Unable to retrieve data due to cookie expiration, retrying after 20 seconds"
|
||||
)
|
||||
return self.data
|
||||
except CannotConnect as e:
|
||||
raise UpdateFailed(
|
||||
"Unable to connect and retrieve data from pyLoad API"
|
||||
|
@ -91,6 +88,7 @@ class PyLoadCoordinator(DataUpdateCoordinator[PyLoadData]):
|
|||
|
||||
try:
|
||||
await self.pyload.login()
|
||||
self.version = await self.pyload.version()
|
||||
except CannotConnect as e:
|
||||
raise ConfigEntryNotReady(
|
||||
translation_domain=DOMAIN,
|
||||
|
|
|
@ -310,7 +310,7 @@
|
|||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'unavailable',
|
||||
'state': '1',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensor_update_exceptions[InvalidAuth][sensor.pyload_downloads_in_queue-entry]
|
||||
|
@ -361,7 +361,7 @@
|
|||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'unavailable',
|
||||
'state': '6',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensor_update_exceptions[InvalidAuth][sensor.pyload_free_space-entry]
|
||||
|
@ -416,7 +416,7 @@
|
|||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'unavailable',
|
||||
'state': '93.1322574606165',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensor_update_exceptions[InvalidAuth][sensor.pyload_speed-entry]
|
||||
|
@ -471,7 +471,7 @@
|
|||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'unavailable',
|
||||
'state': '43.247704',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensor_update_exceptions[InvalidAuth][sensor.pyload_total_downloads-entry]
|
||||
|
@ -522,7 +522,7 @@
|
|||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'unavailable',
|
||||
'state': '37',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensor_update_exceptions[ParserError][sensor.pyload_active_downloads-entry]
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
"""Test pyLoad init."""
|
||||
|
||||
from datetime import timedelta
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from freezegun.api import FrozenDateTimeFactory
|
||||
from pyloadapi.exceptions import CannotConnect, InvalidAuth, ParserError
|
||||
import pytest
|
||||
|
||||
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.common import MockConfigEntry, async_fire_time_changed
|
||||
|
||||
|
||||
async def test_entry_setup_unload(
|
||||
|
@ -63,3 +65,26 @@ async def test_config_entry_setup_invalid_auth(
|
|||
assert config_entry.state is ConfigEntryState.SETUP_ERROR
|
||||
|
||||
assert any(config_entry.async_get_active_flows(hass, {SOURCE_REAUTH}))
|
||||
|
||||
|
||||
async def test_coordinator_update_invalid_auth(
|
||||
hass: HomeAssistant,
|
||||
config_entry: MockConfigEntry,
|
||||
mock_pyloadapi: MagicMock,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
) -> None:
|
||||
"""Test coordinator authentication."""
|
||||
config_entry.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
mock_pyloadapi.login.side_effect = InvalidAuth
|
||||
mock_pyloadapi.get_status.side_effect = InvalidAuth
|
||||
|
||||
freezer.tick(timedelta(seconds=20))
|
||||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert any(config_entry.async_get_active_flows(hass, {SOURCE_REAUTH}))
|
||||
|
|
Loading…
Reference in New Issue