瀏覽代碼

Add connection timeout to API requests (#238)

Damian Sypniewski 9 月之前
父節點
當前提交
612d0ed5dc
共有 1 個文件被更改,包括 6 次插入1 次删除
  1. 6 1
      switchbot/devices/lock.py

+ 6 - 1
switchbot/devices/lock.py

@@ -92,7 +92,12 @@ class SwitchbotLock(SwitchbotDevice):
         headers: dict = None,
     ) -> dict:
         url = f"https://{subdomain}.{SWITCHBOT_APP_API_BASE_URL}/{path}"
-        async with session.post(url, json=data, headers=headers) as result:
+        async with session.post(
+            url,
+            json=data,
+            headers=headers,
+            timeout=aiohttp.ClientTimeout(total=10),
+        ) as result:
             if result.status > 299:
                 raise SwitchbotApiError(
                     f"Unexpected status code returned by SwitchBot API: {result.status}"