added details route
This commit is contained in:
1 parent
3e28974abf
commit
8a06a1674b
3 files changed
+26
-3
No files matched your search
+3
-2
@@ -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
|
||||
@@ -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
|
||||
@@ -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"
|
||||
|
||||
Reference in new issue
Block a user