Add homeassistant
This commit is contained in:
31
src/cloud_util/homeassistant.py
Normal file
31
src/cloud_util/homeassistant.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from pydantic import BaseModel
|
||||
|
||||
from src.cloud_util.ticktick import TickTick
|
||||
from src.config import Config
|
||||
|
||||
|
||||
class HomeAssistant:
|
||||
class PublishMessage(BaseModel):
|
||||
target: str
|
||||
action: str
|
||||
content: str
|
||||
|
||||
def __init__(self, ticktick: TickTick) -> None:
|
||||
self._ticktick = ticktick
|
||||
|
||||
def process_publish_message(self, message: PublishMessage) -> dict[str, str]:
|
||||
if message.target == "ticktick":
|
||||
return self._process_ticktick_message(message=message)
|
||||
|
||||
return {"Status": "Unknown target"}
|
||||
|
||||
def _process_ticktick_message(self, message: PublishMessage) -> dict[str, str]:
|
||||
if message.action == "create_shopping_list":
|
||||
return self._create_shopping_list(item=message.content)
|
||||
|
||||
return {"Status": "Unknown action"}
|
||||
|
||||
def _create_shopping_list(self, item: str) -> dict[str, str]:
|
||||
project_id = Config.get_env("TICKTICK_SHOPPING_LIST")
|
||||
task = TickTick.Task(projectId=project_id, title=item)
|
||||
return self._ticktick.create_task(task=task)
|
||||
Reference in New Issue
Block a user