Прокинут verify_ssl в _request
This commit is contained in:
+25
-13
@@ -1,13 +1,25 @@
|
|||||||
ha_url: str = Field(
|
def _request(self, method: str, path: str, **kwargs) -> requests.Response:
|
||||||
default="https://ha.nasweb.ru",
|
"""HTTP-запрос с ретраями и логированием."""
|
||||||
description="URL Home Assistant (например https://ha.nasweb.ru)",
|
url = self.valves.ha_url + path
|
||||||
)
|
last_exc: Optional[Exception] = None
|
||||||
ha_token: str = Field(
|
# Прокидываем verify_ssl если не передан явно
|
||||||
default="",
|
kwargs.setdefault("verify", self.valves.verify_ssl)
|
||||||
description="Long-Lived Access Token из профиля HA",
|
for attempt in range(1, self.valves.max_retries + 2):
|
||||||
)
|
try:
|
||||||
verify_ssl: bool = Field(
|
resp = requests.request(
|
||||||
default=False,
|
method, url,
|
||||||
description="Проверять SSL-сертификат HA (false для самоподписанных, например за reverse-proxy)",
|
headers=self._headers(),
|
||||||
)
|
timeout=self.valves.request_timeout,
|
||||||
request_timeout: int = Field(default=10, description="Таймаут HTTP-запроса, сек")
|
**kwargs,
|
||||||
|
)
|
||||||
|
resp.raise_for_status()
|
||||||
|
return resp
|
||||||
|
except requests.RequestException as e:
|
||||||
|
last_exc = e
|
||||||
|
logger.warning(
|
||||||
|
"HA %s %s failed (attempt %d): %s",
|
||||||
|
method, path, attempt, e,
|
||||||
|
)
|
||||||
|
if attempt <= self.valves.max_retries:
|
||||||
|
time.sleep(0.5 * attempt)
|
||||||
|
raise RuntimeError("Home Assistant недоступен: " + str(last_exc))
|
||||||
Reference in New Issue
Block a user