Skip to content

Commit 2b295d9

Browse files
committed
Fix UpdateFailed for transient auth errors, simplify sensor class hierarchy
- api.py: raise UpdateFailed (not ConfigEntryNotReady) for transient OAuth token errors so the coordinator can handle them gracefully during periodic updates - sensor.py: remove intermediate EveOnlineSensor base class; move native_value and entity_description directly into EveOnlineCharacterSensor - conftest.py: fix Generator return type annotation to full form Generator[AsyncMock, None, None] for strict mypy compliance - test_api.py: update assertions to expect UpdateFailed instead of ConfigEntryNotReady for transient errors
1 parent a1095c6 commit 2b295d9

File tree

3 files changed

+14
-19
lines changed

3 files changed

+14
-19
lines changed

homeassistant/components/eveonline/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99

1010
from homeassistant.exceptions import (
1111
ConfigEntryAuthFailed,
12-
ConfigEntryNotReady,
1312
OAuth2TokenRequestReauthError,
1413
OAuth2TokenRequestTransientError,
1514
)
1615
from homeassistant.helpers.config_entry_oauth2_flow import OAuth2Session
16+
from homeassistant.helpers.update_coordinator import UpdateFailed
1717

1818
from .const import DOMAIN
1919

@@ -40,7 +40,7 @@ async def async_get_access_token(self) -> str:
4040
translation_key="authentication_failed",
4141
) from err
4242
except (OAuth2TokenRequestTransientError, ClientError) as err:
43-
raise ConfigEntryNotReady(
43+
raise UpdateFailed(
4444
translation_domain=DOMAIN,
4545
translation_key="token_refresh_failed",
4646
translation_placeholders={"error": str(err)},

homeassistant/components/eveonline/sensor.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -164,20 +164,10 @@ async def async_setup_entry(
164164
)
165165

166166

167-
class EveOnlineSensor(SensorEntity):
168-
"""Base class for Eve Online sensors."""
167+
class EveOnlineCharacterSensor(EveOnlineCharacterEntity, SensorEntity):
168+
"""Eve Online character sensor (per-character device)."""
169169

170170
entity_description: EveOnlineSensorDescription
171-
coordinator: EveOnlineCoordinator
172-
173-
@property
174-
def native_value(self) -> str | int | float | datetime | None:
175-
"""Return the sensor value."""
176-
return self.entity_description.value_fn(self.coordinator.data)
177-
178-
179-
class EveOnlineCharacterSensor(EveOnlineCharacterEntity, EveOnlineSensor):
180-
"""Eve Online character sensor (per-character device)."""
181171

182172
def __init__(
183173
self,
@@ -187,3 +177,8 @@ def __init__(
187177
"""Initialize the sensor."""
188178
super().__init__(coordinator, description.key)
189179
self.entity_description = description
180+
181+
@property
182+
def native_value(self) -> str | int | float | datetime | None:
183+
"""Return the sensor value."""
184+
return self.entity_description.value_fn(self.coordinator.data)

tests/components/eveonline/test_api.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
from homeassistant.components.eveonline.const import DOMAIN
1010
from homeassistant.exceptions import (
1111
ConfigEntryAuthFailed,
12-
ConfigEntryNotReady,
1312
OAuth2TokenRequestReauthError,
1413
OAuth2TokenRequestTransientError,
1514
)
15+
from homeassistant.helpers.update_coordinator import UpdateFailed
1616

1717

1818
def _make_auth(
@@ -43,16 +43,16 @@ async def test_get_access_token_reauth_error() -> None:
4343

4444

4545
async def test_get_access_token_transient_error() -> None:
46-
"""Test that OAuth2TokenRequestTransientError raises ConfigEntryNotReady."""
46+
"""Test that OAuth2TokenRequestTransientError raises UpdateFailed."""
4747
auth = _make_auth(
4848
OAuth2TokenRequestTransientError(domain=DOMAIN, request_info=Mock())
4949
)
50-
with pytest.raises(ConfigEntryNotReady):
50+
with pytest.raises(UpdateFailed):
5151
await auth.async_get_access_token()
5252

5353

5454
async def test_get_access_token_client_error() -> None:
55-
"""Test that aiohttp.ClientError raises ConfigEntryNotReady."""
55+
"""Test that aiohttp.ClientError raises UpdateFailed."""
5656
auth = _make_auth(aiohttp.ClientError("network"))
57-
with pytest.raises(ConfigEntryNotReady):
57+
with pytest.raises(UpdateFailed):
5858
await auth.async_get_access_token()

0 commit comments

Comments
 (0)