From 8a06a1674b6dd72ff0388156938dea9020d7c23a Mon Sep 17 00:00:00 2001 From: Ari Date: Tue, 26 Apr 2022 22:11:14 -0400 Subject: [PATCH] added details route --- api/src/api/app.py | 5 +++-- api/src/api/routes/details.py | 21 +++++++++++++++++++++ api/src/hass_config/loader.py | 3 ++- 3 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 api/src/api/routes/details.py diff --git a/api/src/api/app.py b/api/src/api/app.py index 176944f..67721be 100644 --- a/api/src/api/app.py +++ b/api/src/api/app.py @@ -1,9 +1,10 @@ +from sys import prefix from fastapi import FastAPI from fastapi.staticfiles import StaticFiles from fastapi.middleware.cors import CORSMiddleware from src.automations.manager import AutomationManager from src.env import ROOT_FOLDER, ORIGIN -from .routes import ping, automations +from .routes import ping, automations, details def make_app(automation_mgr: AutomationManager) -> FastAPI: @@ -28,5 +29,5 @@ def make_app(automation_mgr: AutomationManager) -> FastAPI: ) app.include_router(ping.router, prefix="/ping") app.include_router(automations.make_automation_router(automation_mgr), prefix="/automations") - + app.include_router(details.make_details_router(automation_mgr.hass_config), prefix="/details") return app diff --git a/api/src/api/routes/details.py b/api/src/api/routes/details.py new file mode 100644 index 0000000..f7196a8 --- /dev/null +++ b/api/src/api/routes/details.py @@ -0,0 +1,21 @@ +from fastapi import APIRouter +from datetime import datetime + +from src.hass_config import HassConfig +from src.env import BUILD_VERSION + + + +def make_details_router(hass_config: HassConfig) -> APIRouter: + router = APIRouter() + + @router.get("/") + def read_ping(): + return { + "version": BUILD_VERSION, + "config": hass_config.get_configuration_path(), + "tags": hass_config.get_automation_tags_path(), + "autos": hass_config.get_automation_path(), + } + + return router \ No newline at end of file diff --git a/api/src/hass_config/loader.py b/api/src/hass_config/loader.py index 9856408..de9ce13 100644 --- a/api/src/hass_config/loader.py +++ b/api/src/hass_config/loader.py @@ -30,13 +30,14 @@ class HassConfig: def automation_tags(self) -> TagManager: tag_path = self.get_automation_tags_path() if not tag_path.exists(): + tag_path.parent.mkdir(parents=True, exist_ok=True) return TagManager() else: return TagManager.load(tag_path) def get_automation_tags_path(self) -> Path: - return self.root_path / "_shortu_automation_tags.yaml" + return self.root_path / ".shortumations" / "tags.yaml" def get_configuration_path(self) -> Path: return self.root_path / "configuration.yaml"