From 7a1675a55aee95987559da7162e8ea61dde4c227 Mon Sep 17 00:00:00 2001 From: Julian Pawlowski Date: Fri, 21 Nov 2025 17:29:04 +0000 Subject: [PATCH] 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. --- custom_components/tibber_prices/api/client.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/custom_components/tibber_prices/api/client.py b/custom_components/tibber_prices/api/client.py index 53c2d0e..1f66b3f 100644 --- a/custom_components/tibber_prices/api/client.py +++ b/custom_components/tibber_prices/api/client.py @@ -46,7 +46,7 @@ class TibberPricesApiClient: self._session = session self._version = version 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._min_request_interval = timedelta(seconds=1) # Min 1 second between requests self._max_retries = 5 @@ -148,6 +148,10 @@ class TibberPricesApiClient: async def _get_price_info_for_specific_homes(self, home_ids: set[str]) -> dict: """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: return {"homes": {}}