fix(api): initialize time attribute to prevent AttributeError

Fixed uninitialized self.time attribute causing AttributeError during
config entry creation. Added explicit initialization to None with
Optional type annotation and guard in _get_price_info_for_specific_homes().

Impact: Config flow no longer crashes when creating initial config entry.
Users can complete setup without errors.
This commit is contained in:
Julian Pawlowski 2025-11-21 17:29:04 +00:00
parent ebd1b8ddbf
commit 7a1675a55a

View file

@ -46,7 +46,7 @@ class TibberPricesApiClient:
self._session = session self._session = session
self._version = version self._version = version
self._request_semaphore = asyncio.Semaphore(2) # Max 2 concurrent requests self._request_semaphore = asyncio.Semaphore(2) # Max 2 concurrent requests
self.time: TibberPricesTimeService # Set externally by coordinator (always initialized before use) self.time: TibberPricesTimeService | None = None # Set externally by coordinator (optional during config flow)
self._last_request_time = None # Set on first request self._last_request_time = None # Set on first request
self._min_request_interval = timedelta(seconds=1) # Min 1 second between requests self._min_request_interval = timedelta(seconds=1) # Min 1 second between requests
self._max_retries = 5 self._max_retries = 5
@ -148,6 +148,10 @@ class TibberPricesApiClient:
async def _get_price_info_for_specific_homes(self, home_ids: set[str]) -> dict: async def _get_price_info_for_specific_homes(self, home_ids: set[str]) -> dict:
"""Get price info for specific homes using GraphQL aliases.""" """Get price info for specific homes using GraphQL aliases."""
if not self.time:
msg = "TimeService not initialized - required for price info processing"
raise TibberPricesApiClientError(msg)
if not home_ids: if not home_ids:
return {"homes": {}} return {"homes": {}}