Skip to content
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
3 changes: 2 additions & 1 deletion aioshelly/block_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from .coap import COAP, CoapMessage
from .common import ConnectionOptions, IpOrOptionsType, get_info, process_ip_or_options
from .const import BLOCK_DEVICE_INIT_TIMEOUT
from .const import BLOCK_DEVICE_INIT_TIMEOUT, HTTP_CALL_TIMEOUT
from .exceptions import AuthRequired, NotInitialized, WrongShellyGen

BLOCK_VALUE_UNIT = "U"
Expand Down Expand Up @@ -224,6 +224,7 @@ async def http_request(
params=params,
auth=self.options.auth,
raise_for_status=True,
timeout=HTTP_CALL_TIMEOUT,
)
return cast(dict, await resp.json())

Expand Down
12 changes: 7 additions & 5 deletions aioshelly/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
from typing import Any, Union

import aiohttp
import async_timeout

from .const import GEN1_MIN_FIRMWARE_DATE, GEN2_MIN_FIRMWARE_DATE
from .const import GEN1_MIN_FIRMWARE_DATE, GEN2_MIN_FIRMWARE_DATE, HTTP_CALL_TIMEOUT
from .exceptions import FirmwareUnsupported

FIRMWARE_PATTERN = re.compile(r"^(\d{8})")
Expand Down Expand Up @@ -62,10 +63,11 @@ async def get_info(
aiohttp_session: aiohttp.ClientSession, ip_address: str
) -> dict[str, Any]:
"""Get info from device through REST call."""
async with aiohttp_session.get(
f"http://{ip_address}/shelly", raise_for_status=True
) as resp:
result: dict[str, Any] = await resp.json()
async with async_timeout.timeout(HTTP_CALL_TIMEOUT):
async with aiohttp_session.get(
f"http://{ip_address}/shelly", raise_for_status=True
) as resp:
result: dict[str, Any] = await resp.json()

if not shelly_supported_firmware(result):
raise FirmwareUnsupported
Expand Down
3 changes: 3 additions & 0 deletions aioshelly/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
# Timeout used for Block Device init
BLOCK_DEVICE_INIT_TIMEOUT = 10

# Timeout used for HTTP calls
HTTP_CALL_TIMEOUT = 10

# Firmware 1.8.0 release date (CoAP v2)
GEN1_MIN_FIRMWARE_DATE = 20200812

Expand Down