Skip to content

fix: async timeout does not support context manager error #164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}