Change requests to async
This commit is contained in:
@@ -19,9 +19,9 @@ class HomeAssistant:
|
||||
def __init__(self, ticktick: TickTick) -> None:
|
||||
self._ticktick = ticktick
|
||||
|
||||
def process_message(self, message: Message) -> dict[str, str]:
|
||||
async def process_message(self, message: Message) -> dict[str, str]:
|
||||
if message.target == "ticktick":
|
||||
return self._process_ticktick_message(message=message)
|
||||
return await self._process_ticktick_message(message=message)
|
||||
|
||||
return {"Status": "Unknown target"}
|
||||
|
||||
@@ -31,21 +31,21 @@ class HomeAssistant:
|
||||
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]:
|
||||
async def _process_ticktick_message(self, message: Message) -> dict[str, str]:
|
||||
if message.action == "create_shopping_list":
|
||||
return self._create_shopping_list(content=message.content)
|
||||
return await self._create_shopping_list(content=message.content)
|
||||
if message.action == "create_action_task":
|
||||
return self._create_action_task(content=message.content)
|
||||
return await self._create_action_task(content=message.content)
|
||||
|
||||
return {"Status": "Unknown action"}
|
||||
|
||||
def _create_shopping_list(self, content: str) -> dict[str, str]:
|
||||
async def _create_shopping_list(self, content: str) -> dict[str, str]:
|
||||
project_id = Config.get_env("TICKTICK_SHOPPING_LIST")
|
||||
item: dict[str, str] = ast.literal_eval(content)
|
||||
task = TickTick.Task(projectId=project_id, title=item["item"])
|
||||
return self._ticktick.create_task(task=task)
|
||||
return await self._ticktick.create_task(task=task)
|
||||
|
||||
def _create_action_task(self, content: str) -> dict[str, str]:
|
||||
async def _create_action_task(self, content: str) -> dict[str, str]:
|
||||
detail: dict[str, str] = ast.literal_eval(content)
|
||||
project_id = Config.get_env("TICKTICK_HOME_TASK_LIST")
|
||||
due_hour = detail["due_hour"]
|
||||
@@ -53,4 +53,4 @@ class HomeAssistant:
|
||||
due = (due + timedelta(days=1)).replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
due = due.astimezone(timezone.utc)
|
||||
task = TickTick.Task(projectId=project_id, title=detail["action"], dueDate=TickTick.datetime_to_ticktick_format(due))
|
||||
return self._ticktick.create_task(task=task)
|
||||
return await self._ticktick.create_task(task=task)
|
||||
|
||||
Reference in New Issue
Block a user