Skip to content

Commit

Permalink
fix for HA 2024.1.6 and aiohttp
Browse files Browse the repository at this point in the history
  • Loading branch information
chises committed Jan 31, 2024
1 parent 455894d commit 9e0645c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
15 changes: 10 additions & 5 deletions custom_components/oilfox/OilFox.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,18 @@ async def update_stats(self):

if not_error:
headers = {"Authorization": "Bearer " + self.access_token}
async with aiohttp.ClientSession(timeout=self.TIMEOUT) as session:
async with aiohttp.ClientSession(
timeout=aiohttp.ClientTimeout(self.TIMEOUT)
) as session:
try:
async with session.get(
self.device_url + self.hwid,
headers=headers,
timeout=self.TIMEOUT,
timeout=aiohttp.ClientTimeout(self.TIMEOUT),
) as response:
if response.status == 200:
self.state = await response.json()
except asyncio.TimeoutError as err:
except asyncio.TimeoutError:
raise ConfigEntryNotReady( # noqa: TRY200
f"Update values failed because of http timeout (waited for {self.TIMEOUT} s)!"
)
Expand All @@ -101,7 +103,10 @@ async def get_tokens(self):
}

async with aiohttp.ClientSession() as session, session.post(
self.login_url, headers=headers, json=json_data, timeout=self.TIMEOUT
self.login_url,
headers=headers,
json=json_data,
timeout=aiohttp.ClientTimeout(self.TIMEOUT),
) as response:
if response.status == 200:
json_response = await response.json()
Expand All @@ -121,7 +126,7 @@ async def get_access_token(self):
"refresh_token": self.refresh_token,
}
async with aiohttp.ClientSession() as session, session.post(
self.token_url, data=data, timeout=self.TIMEOUT
self.token_url, data=data, timeout=aiohttp.ClientTimeout(self.TIMEOUT)
) as response:
_LOGGER.debug("Get Access Token:%s", response.status)
if response.status == 200:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/oilfox/UpdateCoordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(
hass,
_LOGGER,
name=DOMAIN,
update_interval=timedelta(minutes=1),
update_interval=timedelta(minutes=15),
)

async def _async_update_data(self) -> None:
Expand Down
4 changes: 2 additions & 2 deletions custom_components/oilfox/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/chises/ha-oilfox/issues",
"loggers": ["oilfox_component"],
"requirements": ["aiohttp==3.9.1"],
"version": "1.0.0-alpha"
"requirements": ["aiohttp"],
"version": "1.0.1-alpha"
}

0 comments on commit 9e0645c

Please sign in to comment.