Adding bluetooth radio toggle to Controller. Writing controller.yaml to media drive on startup, if it doesn't exist.

This commit is contained in:
Roland 2026-03-28 10:09:58 -06:00
parent 9e80683b9a
commit 1c55745884
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
13 changed files with 624 additions and 7 deletions

View file

@ -5,6 +5,8 @@ Admin API endpoints for WROLPi Controller.
from fastapi import APIRouter, HTTPException
from controller.api.schemas import (
BluetoothActionResponse,
BluetoothStatusResponse,
HotspotActionResponse,
HotspotStatusResponse,
RestartServicesResponse,
@ -17,10 +19,13 @@ from controller.api.schemas import (
TimezoneStatusResponse,
)
from controller.lib.admin import (
disable_bluetooth,
disable_hotspot,
disable_throttle,
enable_bluetooth,
enable_hotspot,
enable_throttle,
get_bluetooth_status_dict,
get_hotspot_status_dict,
get_throttle_status_dict,
get_timezone_status_dict,
@ -60,6 +65,32 @@ async def hotspot_disable() -> HotspotActionResponse:
return HotspotActionResponse(**result)
# --- Bluetooth ---
@router.get("/api/bluetooth/status", response_model=BluetoothStatusResponse)
async def bluetooth_status() -> BluetoothStatusResponse:
"""Get Bluetooth radio status."""
return BluetoothStatusResponse(**await get_bluetooth_status_dict())
@router.post("/api/bluetooth/enable", response_model=BluetoothActionResponse)
async def bluetooth_enable() -> BluetoothActionResponse:
"""Enable Bluetooth radio."""
result = await enable_bluetooth()
if not result.get("success"):
raise HTTPException(status_code=500, detail=result.get("error", "Failed"))
return BluetoothActionResponse(**result)
@router.post("/api/bluetooth/disable", response_model=BluetoothActionResponse)
async def bluetooth_disable() -> BluetoothActionResponse:
"""Disable Bluetooth radio."""
result = await disable_bluetooth()
if not result.get("success"):
raise HTTPException(status_code=500, detail=result.get("error", "Failed"))
return BluetoothActionResponse(**result)
# --- Throttle ---
@router.get("/api/throttle/status", response_model=ThrottleStatusResponse)

View file

@ -166,6 +166,25 @@ class HotspotActionResponse(BaseModel):
error: Optional[str] = Field(default=None, description="Error message if failed")
# ============================================================================
# Admin - Bluetooth
# ============================================================================
class BluetoothStatusResponse(BaseModel):
"""Response model for /api/bluetooth/status endpoint."""
enabled: bool = Field(description="Whether Bluetooth radio is currently on")
available: bool = Field(description="Whether Bluetooth functionality is available")
reason: Optional[str] = Field(default=None, description="Reason if unavailable")
class BluetoothActionResponse(BaseModel):
"""Response model for Bluetooth enable/disable actions."""
success: bool = Field(description="Whether the action succeeded")
error: Optional[str] = Field(default=None, description="Error message if failed")
# ============================================================================
# Admin - Throttle
# ============================================================================

View file

@ -12,7 +12,7 @@ wrol_mode) remain in the main WROLPi API at /api/status.
from fastapi import APIRouter, Request
from fastapi.responses import JSONResponse
from controller.lib.admin import get_hotspot_status, get_throttle_status, HotspotStatus
from controller.lib.admin import get_bluetooth_status, get_hotspot_status, get_throttle_status, BluetoothStatus, HotspotStatus
from controller.lib.config import is_docker_mode, is_rpi, is_rpi4, is_rpi5
from controller.lib.status import (
get_cpu_status,
@ -31,7 +31,7 @@ def get_cached_status(request: Request) -> dict:
return getattr(request.app.state, "cached_status", {})
def get_system_info() -> dict:
async def get_system_info() -> dict:
"""
Get static system info that doesn't need frequent updates.
These are collected on each request as they rarely change.
@ -39,6 +39,7 @@ def get_system_info() -> dict:
from controller.lib.config import get_config
hotspot_status = get_hotspot_status()
bluetooth_status = await get_bluetooth_status()
throttle_status = get_throttle_status()
# Get hotspot SSID from config if hotspot is connected
@ -51,6 +52,7 @@ def get_system_info() -> dict:
"is_rpi": is_rpi(),
"is_rpi4": is_rpi4(),
"is_rpi5": is_rpi5(),
"bluetooth_status": bluetooth_status.name,
"hotspot_status": hotspot_status.name,
"hotspot_ssid": hotspot_ssid,
"throttle_status": throttle_status.name,
@ -78,7 +80,7 @@ async def get_all_stats(request: Request):
cached = await collect_all_status()
# Add system info to response
response = {**cached, **get_system_info()}
response = {**cached, **await get_system_info()}
return JSONResponse(content=response)