Use webhook to publish automation trigger

This commit is contained in:
2024-08-21 17:05:12 +02:00
parent 3eaae13dc3
commit b9b8659347
3 changed files with 13 additions and 2 deletions

View File

@@ -3,6 +3,7 @@ from __future__ import annotations
import ast
from datetime import datetime, timedelta, timezone
import httpx
from pydantic import BaseModel
from src.cloud_util.ticktick import TickTick
@@ -24,6 +25,12 @@ class HomeAssistant:
return {"Status": "Unknown target"}
async def trigger_webhook(self, payload: dict[str, str], webhook_id: str) -> None:
token: str = Config.get_env("HOMEASSISTANT_TOKEN")
webhook_url: str = Config.get_env("HOMEASSISTANT_URL") + "/api/webhook/" + webhook_id
headers: dict[str, str] = {"Authorization": f"Bearer {token}"}
await httpx.AsyncClient().post(webhook_url, json=payload, headers=headers)
def _process_ticktick_message(self, message: Message) -> dict[str, str]:
if message.action == "create_shopping_list":
return self._create_shopping_list(content=message.content)