Skip to content

Commit

Permalink
Independent API use counter for every account take 2
Browse files Browse the repository at this point in the history
  • Loading branch information
autoSteve committed Jun 18, 2024
1 parent 9373df6 commit a3dadc7
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions custom_components/solcast_solar/solcastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ def get_energy_data(self) -> dict[str, Any]:

async def http_data(self, dopast = False):
"""Request forecast data via the Solcast API."""
if self.get_last_updated_datetime() + timedelta(minutes=15) < dt.now(timezone.utc):
if self.get_last_updated_datetime() + timedelta(minutes=15) > dt.now(timezone.utc):
_LOGGER.warning(f"SOLCAST - not requesting forecast because time is within fifteen minutes of last update ({self.get_last_updated_datetime().astimezone(self._tz)})")
return

Expand All @@ -609,7 +609,11 @@ async def http_data(self, dopast = False):
for site in self._sites:
_LOGGER.debug(f"SOLCAST - API polling for rooftop {site['resource_id']}")
#site=site['resource_id'], apikey=site['apikey'],
result = await self.http_data_call(site['resource_id'], site['apikey'], dopast)
if len(self._sites) == 1:
usageCacheFileName = "solcast-usage.json"
else:
usageCacheFileName = "solcast-usage-%s.json" % (site['apikey'],)
result = await self.http_data_call(usageCacheFileName, site['resource_id'], site['apikey'], dopast)
if not result:
failure = True

Expand All @@ -622,6 +626,7 @@ async def http_data(self, dopast = False):

await self.buildforcastdata()
await self.serialize_data()

async def http_data_call(self, usageCacheFileName, r_id = None, api = None, dopast = False):
"""Request forecast data via the Solcast API."""
lastday = dt.now(self._tz) + timedelta(days=7)
Expand Down

0 comments on commit a3dadc7

Please sign in to comment.