Skip to content

Commit

Permalink
Add user-agent.
Browse files Browse the repository at this point in the history
  • Loading branch information
Makin-Things authored Aug 16, 2023
1 parent a04cf2c commit f89e303
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions custom_components/bureau_of_meteorology/PyBoM/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ def __init__(self, latitude, longitude):
self.geohash7 = geohash_encode(latitude, longitude)
self.geohash6 = self.geohash7[:6]

headers={"User-Agent": "MakeThisAPIOpenSource/1.0.0"}
async def get_locations_data(self):
"""Get JSON location name from BOM API endpoint."""
async with aiohttp.ClientSession() as session:
async with aiohttp.ClientSession(headers=headers) as session:
response = await session.get(URL_BASE + self.geohash7)

if response is not None and response.status == 200:
Expand Down Expand Up @@ -81,7 +82,8 @@ async def format_hourly_forecast_data(self):
@Throttle(datetime.timedelta(minutes=5))
async def async_update(self):
"""Refresh the data on the collector object."""
async with aiohttp.ClientSession() as session:
headers={"User-Agent": "MakeThisAPIOpenSource/1.0.0"}
async with aiohttp.ClientSession(headers=headers) as session:
if self.locations_data is None:
async with session.get(URL_BASE + self.geohash7) as resp:
self.locations_data = await resp.json()
Expand Down

0 comments on commit f89e303

Please sign in to comment.