Files
labFusion/services/service-adapters/main.py
GSRN 7eaea39928
Some checks failed
Integration Tests / integration-tests (push) Failing after 20s
Integration Tests / performance-tests (push) Has been skipped
Service Adapters (Python FastAPI) / test (3.11) (push) Failing after 24s
Service Adapters (Python FastAPI) / test (3.12) (push) Failing after 25s
Service Adapters (Python FastAPI) / test (3.13) (push) Failing after 25s
Service Adapters (Python FastAPI) / build (push) Has been skipped
fix: Clean up whitespace and improve code formatting across service adapters
### Summary of Changes
- Removed unnecessary whitespace and standardized formatting in multiple files, including `main.py`, `logging_middleware.py`, `general.py`, and various health checker implementations.
- Enhanced readability and maintainability of the codebase by ensuring consistent formatting practices.

### Expected Results
- Improved code clarity, making it easier for developers to read and understand the service adapters' code.
- Streamlined the codebase, facilitating future updates and maintenance.
2025-09-18 13:02:46 +02:00

71 lines
2.1 KiB
Python

from contextlib import asynccontextmanager
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
# Import route modules
from middleware import LoggingMiddleware
from routes import events, frigate, general, home_assistant, immich
from services.logging_config import get_application_logger, setup_logging
from services.status_checker import status_checker
# Set up unified logging for both application and request logs
setup_logging(level="INFO", enable_request_logging=True)
@asynccontextmanager
async def lifespan(app: FastAPI):
"""Manage application lifespan events."""
# Startup
logger = get_application_logger()
logger.info("LabFusion Service Adapters starting up")
yield
# Shutdown
logger.info("LabFusion Service Adapters shutting down")
await status_checker.close()
# Create FastAPI app
app = FastAPI(
title="LabFusion Service Adapters",
description="Service integration adapters for Home Assistant, Frigate, Immich, and other homelab services",
version="1.0.0",
license_info={"name": "MIT License", "url": "https://opensource.org/licenses/MIT"},
servers=[
{"url": "http://localhost:8001", "description": "Development Server"},
{"url": "https://adapters.labfusion.dev", "description": "Production Server"},
],
lifespan=lifespan,
)
# Add custom logging middleware first (runs last in the chain)
app.add_middleware(LoggingMiddleware)
# CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Include routers
app.include_router(general.router)
app.include_router(home_assistant.router)
app.include_router(frigate.router)
app.include_router(immich.router)
app.include_router(events.router)
if __name__ == "__main__":
import uvicorn
# Configure uvicorn to use our unified logging
uvicorn.run(
app,
host="127.0.0.1",
port=8001,
log_config=None, # Disable uvicorn's default logging config
access_log=True, # Enable access logging
)