Use webhook to publish automation trigger
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user