functioning profiles

This commit is contained in:
ari committed 2022-08-31 15:15:30 -04:00
1 parent 8985312dd2
commit d890c1aa64
17 files changed
+136 -78

No files matched your search

+4 -6
View File
@@ -3,13 +3,13 @@ from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import RedirectResponse
from fastapi.staticfiles import StaticFiles
from src.automations.manager import AutomationManager
from src.env import API_PREFIX, ORIGIN, ROOT_FOLDER
from src.hass_config.loader import HassConfig
from .routes import automations, details, ping, socket
def make_app(automation_mgr: AutomationManager) -> FastAPI:
def make_app(hass_config: HassConfig) -> FastAPI:
app = FastAPI()
has_web_folder = (ROOT_FOLDER / "web").exists()
if has_web_folder:
@@ -33,11 +33,9 @@ def make_app(automation_mgr: AutomationManager) -> FastAPI:
)
app.include_router(ping.router, prefix="/ping")
app.include_router(
automations.make_automation_router(automation_mgr), prefix=f"{API_PREFIX}/automations"
)
app.include_router(
details.make_details_router(automation_mgr.hass_config), prefix=f"{API_PREFIX}/details"
automations.make_automation_router(hass_config), prefix=f"{API_PREFIX}/automations"
)
app.include_router(details.make_details_router(hass_config), prefix=f"{API_PREFIX}/details")
app.include_router(socket.router, prefix=f"{API_PREFIX}/socket")
@app.get("/")
+7 -1
View File
@@ -5,13 +5,15 @@ from src.automations.errors import FailedDeletion
from src.automations.manager import AutomationManager
from src.automations.types import Automation, ExtenededAutomation
from src.errors import ErrorSet
from src.hass_config.loader import HassConfig
def make_automation_router(automations: AutomationManager) -> APIRouter:
def make_automation_router(hass_config: HassConfig) -> APIRouter:
router = APIRouter()
@router.post("/list")
def list_autos(body: ListParams) -> ListData[ExtenededAutomation]:
automations = AutomationManager(hass_config)
try:
automations.reload()
return ListData(
@@ -27,18 +29,22 @@ def make_automation_router(automations: AutomationManager) -> APIRouter:
@router.post("/item")
def insert_auto(body: Automation):
automations = AutomationManager(hass_config)
automations.create(body)
@router.put("/item")
def update_auto(body: ExtenededAutomation):
automations = AutomationManager(hass_config)
automations.update(body)
@router.post("/item/tags")
def update_tags(body: UpdateTags):
automations = AutomationManager(hass_config)
automations.update_tags(body.automation_id, body.tags)
@router.delete("/item")
def delete_auto(body: ExtenededAutomation):
automations = AutomationManager(hass_config)
try:
automations.delete(body)
except FailedDeletion as err:
+1 -1
View File
@@ -3,4 +3,4 @@ from src.automations.manager import AutomationManager
from src.hass_config import find_hass_config
hass_config = find_hass_config()
app = make_app(AutomationManager(hass_config))
app = make_app(hass_config)
-1
View File
@@ -16,7 +16,6 @@ from .errors import (
from .loader import (
get_base_automation_key,
load_and_iter_automations,
load_automation_path,
)
from .tags import TagManager
from .types import Automation, ExtenededAutomation