Setting system timezone using Controller.
Some checks are pending
CodeQL / Analyze (push) Waiting to run
Controller Tests / controller-tests (push) Waiting to run
Jest Tests / jest-tests (push) Waiting to run

This commit is contained in:
Roland 2026-03-13 15:56:21 -06:00
parent b1db71f04a
commit ccc6cf78d3
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
8 changed files with 390 additions and 2 deletions

View file

@ -12,6 +12,9 @@ from controller.api.schemas import (
SystemActionResponse,
ThrottleActionResponse,
ThrottleStatusResponse,
TimezoneSetRequest,
TimezoneSetResponse,
TimezoneStatusResponse,
)
from controller.lib.admin import (
disable_hotspot,
@ -20,8 +23,10 @@ from controller.lib.admin import (
enable_throttle,
get_hotspot_status_dict,
get_throttle_status_dict,
get_timezone_status_dict,
reboot_system,
restart_all_services,
set_timezone,
shutdown_system,
)
from controller.lib.config import is_docker_mode
@ -81,6 +86,23 @@ async def throttle_disable() -> ThrottleActionResponse:
return ThrottleActionResponse(**result)
# --- Timezone ---
@router.get("/api/timezone/status", response_model=TimezoneStatusResponse)
async def timezone_status() -> TimezoneStatusResponse:
"""Get current system timezone."""
return TimezoneStatusResponse(**get_timezone_status_dict())
@router.post("/api/timezone/set", response_model=TimezoneSetResponse)
async def timezone_set(request: TimezoneSetRequest) -> TimezoneSetResponse:
"""Set the system timezone."""
result = set_timezone(request.timezone)
if not result.get("success"):
raise HTTPException(status_code=500, detail=result.get("error", "Failed"))
return TimezoneSetResponse(**result)
# --- System Control ---
@router.post("/api/shutdown", response_model=SystemActionResponse)

View file

@ -216,6 +216,32 @@ class RestartServicesResponse(BaseModel):
error: Optional[str] = Field(default=None, description="Error message if failed")
# ============================================================================
# Admin - Timezone
# ============================================================================
class TimezoneStatusResponse(BaseModel):
"""Response model for /api/timezone/status endpoint."""
available: bool = Field(description="Whether system timezone control is available")
timezone: Optional[str] = Field(default=None, description="Current system timezone (IANA)")
reason: Optional[str] = Field(default=None, description="Reason if unavailable")
class TimezoneSetRequest(BaseModel):
"""Request model for setting the system timezone."""
timezone: str = Field(description="IANA timezone string (e.g. America/Denver)")
class TimezoneSetResponse(BaseModel):
"""Response model for setting the system timezone."""
success: bool = Field(description="Whether the timezone was set")
timezone: Optional[str] = Field(default=None, description="New timezone if successful")
error: Optional[str] = Field(default=None, description="Error message if failed")
# ============================================================================
# Services - Status
# ============================================================================