From 1f6cdcae01e15182396022fcccbf511f509f01bc Mon Sep 17 00:00:00 2001 From: host Date: Wed, 29 Jul 2026 19:02:03 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B0=20=5Fcall=5Fservice?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- home_assistant_tools.py | 37 ++++++++++++------------------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/home_assistant_tools.py b/home_assistant_tools.py index 6c7e4aa..0f48ada 100644 --- a/home_assistant_tools.py +++ b/home_assistant_tools.py @@ -1,25 +1,12 @@ -def _request(self, method: str, path: str, **kwargs) -> requests.Response: - """HTTP-запрос с ретраями и логированием.""" - url = self.valves.ha_url + path - last_exc: Optional[Exception] = None - # Прокидываем verify_ssl если не передан явно - kwargs.setdefault("verify", self.valves.verify_ssl) - for attempt in range(1, self.valves.max_retries + 2): - try: - resp = requests.request( - method, url, - headers=self._headers(), - timeout=self.valves.request_timeout, - **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)) \ No newline at end of file +def _call_service(self, domain: str, service: str, data: Dict[str, Any]) -> bool: + """Вызов сервиса HA. Возвращает True если выполнено, False если dry-run.""" + logger.info( + "%s -> %s.%s %s", + "[DRY] " if self.valves.dry_run else "", + domain, service, data, + ) + if self.valves.dry_run: + return False + # verify_ssl уже передаётся в _request через kwargs + self._request("POST", "/api/services/" + domain + "/" + service, json=data) + return True \ No newline at end of file