mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Don't fail on successful relogin in pyLoad integration (#138936)
* Don't fail on successful relogin * logging
This commit is contained in:
parent
d522571308
commit
8068f82888
@ -59,14 +59,11 @@ class PyLoadCoordinator(DataUpdateCoordinator[PyLoadData]):
|
|||||||
async def _async_update_data(self) -> PyLoadData:
|
async def _async_update_data(self) -> PyLoadData:
|
||||||
"""Fetch data from API endpoint."""
|
"""Fetch data from API endpoint."""
|
||||||
try:
|
try:
|
||||||
if not self.version:
|
|
||||||
self.version = await self.pyload.version()
|
|
||||||
return PyLoadData(
|
return PyLoadData(
|
||||||
**await self.pyload.get_status(),
|
**await self.pyload.get_status(),
|
||||||
free_space=await self.pyload.free_space(),
|
free_space=await self.pyload.free_space(),
|
||||||
)
|
)
|
||||||
|
except InvalidAuth:
|
||||||
except InvalidAuth as e:
|
|
||||||
try:
|
try:
|
||||||
await self.pyload.login()
|
await self.pyload.login()
|
||||||
except InvalidAuth as exc:
|
except InvalidAuth as exc:
|
||||||
@ -75,10 +72,10 @@ class PyLoadCoordinator(DataUpdateCoordinator[PyLoadData]):
|
|||||||
translation_key="setup_authentication_exception",
|
translation_key="setup_authentication_exception",
|
||||||
translation_placeholders={CONF_USERNAME: self.pyload.username},
|
translation_placeholders={CONF_USERNAME: self.pyload.username},
|
||||||
) from exc
|
) from exc
|
||||||
|
_LOGGER.debug(
|
||||||
raise UpdateFailed(
|
"Unable to retrieve data due to cookie expiration, retrying after 20 seconds"
|
||||||
"Unable to retrieve data due to cookie expiration"
|
)
|
||||||
) from e
|
return self.data
|
||||||
except CannotConnect as e:
|
except CannotConnect as e:
|
||||||
raise UpdateFailed(
|
raise UpdateFailed(
|
||||||
"Unable to connect and retrieve data from pyLoad API"
|
"Unable to connect and retrieve data from pyLoad API"
|
||||||
@ -91,6 +88,7 @@ class PyLoadCoordinator(DataUpdateCoordinator[PyLoadData]):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
await self.pyload.login()
|
await self.pyload.login()
|
||||||
|
self.version = await self.pyload.version()
|
||||||
except CannotConnect as e:
|
except CannotConnect as e:
|
||||||
raise ConfigEntryNotReady(
|
raise ConfigEntryNotReady(
|
||||||
translation_domain=DOMAIN,
|
translation_domain=DOMAIN,
|
||||||
|
@ -310,7 +310,7 @@
|
|||||||
'last_changed': <ANY>,
|
'last_changed': <ANY>,
|
||||||
'last_reported': <ANY>,
|
'last_reported': <ANY>,
|
||||||
'last_updated': <ANY>,
|
'last_updated': <ANY>,
|
||||||
'state': 'unavailable',
|
'state': '1',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_sensor_update_exceptions[InvalidAuth][sensor.pyload_downloads_in_queue-entry]
|
# name: test_sensor_update_exceptions[InvalidAuth][sensor.pyload_downloads_in_queue-entry]
|
||||||
@ -361,7 +361,7 @@
|
|||||||
'last_changed': <ANY>,
|
'last_changed': <ANY>,
|
||||||
'last_reported': <ANY>,
|
'last_reported': <ANY>,
|
||||||
'last_updated': <ANY>,
|
'last_updated': <ANY>,
|
||||||
'state': 'unavailable',
|
'state': '6',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_sensor_update_exceptions[InvalidAuth][sensor.pyload_free_space-entry]
|
# name: test_sensor_update_exceptions[InvalidAuth][sensor.pyload_free_space-entry]
|
||||||
@ -416,7 +416,7 @@
|
|||||||
'last_changed': <ANY>,
|
'last_changed': <ANY>,
|
||||||
'last_reported': <ANY>,
|
'last_reported': <ANY>,
|
||||||
'last_updated': <ANY>,
|
'last_updated': <ANY>,
|
||||||
'state': 'unavailable',
|
'state': '93.1322574606165',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_sensor_update_exceptions[InvalidAuth][sensor.pyload_speed-entry]
|
# name: test_sensor_update_exceptions[InvalidAuth][sensor.pyload_speed-entry]
|
||||||
@ -471,7 +471,7 @@
|
|||||||
'last_changed': <ANY>,
|
'last_changed': <ANY>,
|
||||||
'last_reported': <ANY>,
|
'last_reported': <ANY>,
|
||||||
'last_updated': <ANY>,
|
'last_updated': <ANY>,
|
||||||
'state': 'unavailable',
|
'state': '43.247704',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_sensor_update_exceptions[InvalidAuth][sensor.pyload_total_downloads-entry]
|
# name: test_sensor_update_exceptions[InvalidAuth][sensor.pyload_total_downloads-entry]
|
||||||
@ -522,7 +522,7 @@
|
|||||||
'last_changed': <ANY>,
|
'last_changed': <ANY>,
|
||||||
'last_reported': <ANY>,
|
'last_reported': <ANY>,
|
||||||
'last_updated': <ANY>,
|
'last_updated': <ANY>,
|
||||||
'state': 'unavailable',
|
'state': '37',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_sensor_update_exceptions[ParserError][sensor.pyload_active_downloads-entry]
|
# name: test_sensor_update_exceptions[ParserError][sensor.pyload_active_downloads-entry]
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
"""Test pyLoad init."""
|
"""Test pyLoad init."""
|
||||||
|
|
||||||
|
from datetime import timedelta
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
|
from freezegun.api import FrozenDateTimeFactory
|
||||||
from pyloadapi.exceptions import CannotConnect, InvalidAuth, ParserError
|
from pyloadapi.exceptions import CannotConnect, InvalidAuth, ParserError
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
|
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
|
||||||
from homeassistant.core import HomeAssistant
|
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(
|
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 config_entry.state is ConfigEntryState.SETUP_ERROR
|
||||||
|
|
||||||
assert any(config_entry.async_get_active_flows(hass, {SOURCE_REAUTH}))
|
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…
x
Reference in New Issue
Block a user