Skip to content

Commit

Permalink
fix: async timeout does not support context manager error (#164)
Browse files Browse the repository at this point in the history
Fixes: #159
  • Loading branch information
jcwillox authored Nov 19, 2024
1 parent 8130713 commit 4469e4d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
4 changes: 1 addition & 3 deletions custom_components/auto_backup/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@
EVENT_BACKUPS_PURGED,
EVENT_BACKUP_SUCCESSFUL,
EVENT_BACKUP_START,
UNSUB_LISTENER,
DATA_AUTO_BACKUP,
DEFAULT_BACKUP_TIMEOUT_SECONDS,
CONF_AUTO_PURGE,
CONF_BACKUP_TIMEOUT,
DEFAULT_BACKUP_TIMEOUT,
Expand Down Expand Up @@ -316,7 +314,7 @@ def validate_backup_config(self, config: Dict):

if ATTR_INCLUDE in config or ATTR_EXCLUDE in config:
raise HomeAssistantError(
f"Partial backups (e.g. include/exclude) are not supported on non-supervised installations."
"Partial backups (e.g. include/exclude) are not supported on non-supervised installations."
)

if config.get(ATTR_NAME):
Expand Down
9 changes: 4 additions & 5 deletions custom_components/auto_backup/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from typing import Dict, List, Optional

import aiohttp
import async_timeout
from aiohttp.hdrs import AUTHORIZATION
from homeassistant.components.backup import BackupManager
from homeassistant.const import ATTR_NAME
Expand Down Expand Up @@ -79,7 +78,7 @@ async def send_command(self, command, method="post", payload=None, timeout=10):
This method is a coroutine.
"""
try:
with async_timeout.timeout(timeout):
async with asyncio.timeout(timeout):
request = await self._session.request(
method,
f"http://{self._ip}{command}",
Expand All @@ -95,7 +94,7 @@ async def send_command(self, command, method="post", payload=None, timeout=10):
answer = await request.json()
return answer

except asyncio.TimeoutError:
except TimeoutError:
raise HassioAPIError("Timeout on %s request" % command)

except aiohttp.ClientError as err:
Expand Down Expand Up @@ -131,7 +130,7 @@ async def download_backup(
command = f"/backups/{slug}/download"

try:
with async_timeout.timeout(timeout):
async with asyncio.timeout(timeout):
request = await self._session.request(
"get",
f"http://{self._ip}{command}",
Expand All @@ -153,7 +152,7 @@ async def download_backup(
_LOGGER.info("Downloaded backup '%s' to '%s'", slug, destination)
return

except asyncio.TimeoutError:
except TimeoutError:
_LOGGER.error("Timeout on %s request", command)

except aiohttp.ClientError as err:
Expand Down
2 changes: 1 addition & 1 deletion hacs.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"zip_release": true,
"hide_default_branch": true,
"filename": "auto_backup.zip",
"homeassistant": "2022.4.0"
"homeassistant": "2023.4.0"
}

0 comments on commit 4469e4d

Please sign in to comment.