Add location recorder
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import ast
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
@@ -7,6 +5,7 @@ import httpx
|
||||
from pydantic import BaseModel
|
||||
|
||||
from src.config import Config
|
||||
from src.util.location_recorder import LocationData, LocationRecorder
|
||||
from src.util.ticktick import TickTick
|
||||
|
||||
|
||||
@@ -16,13 +15,15 @@ class HomeAssistant:
|
||||
action: str
|
||||
content: str
|
||||
|
||||
def __init__(self, ticktick: TickTick) -> None:
|
||||
def __init__(self, ticktick: TickTick, location_recorder: LocationRecorder) -> None:
|
||||
self._ticktick = ticktick
|
||||
self._location_recorder = location_recorder
|
||||
|
||||
async def process_message(self, message: Message) -> dict[str, str]:
|
||||
if message.target == "ticktick":
|
||||
return await self._process_ticktick_message(message=message)
|
||||
|
||||
if message.target == "location_recorder":
|
||||
return await self._process_location(message=message)
|
||||
return {"Status": "Unknown target"}
|
||||
|
||||
async def trigger_webhook(self, payload: dict[str, str], webhook_id: str) -> None:
|
||||
@@ -39,6 +40,20 @@ class HomeAssistant:
|
||||
|
||||
return {"Status": "Unknown action"}
|
||||
|
||||
async def _process_location(self, message: Message) -> dict[str, str]:
|
||||
if message.action == "record":
|
||||
location: dict[str, str] = ast.literal_eval(message.content)
|
||||
await self._location_recorder.insert_location_now(
|
||||
people=location["person"],
|
||||
location=LocationData(
|
||||
latitude=float(location["latitude"]),
|
||||
longitude=float(location["longitude"]),
|
||||
altitude=float(location["altitude"]),
|
||||
),
|
||||
)
|
||||
return {"Status": "Location recorded"}
|
||||
return {"Status": "Unknown action"}
|
||||
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user