mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-22 07:56:18 -05:00
Controller: move hotspot settings to controller.yaml with WiFi device dropdown.
Hotspot was reported as "not supported" on x86 machines (Ubuntu/Debian PCs) because the Controller only watched the hardcoded default wlan0 device, while predictable interface naming produces names like wlp2s0. The Settings page saved hotspot_device to wrolpi.yaml, which the Controller never read. The Controller now owns hotspot settings in controller.yaml: * New endpoints: GET/POST /api/hotspot/settings, GET /api/hotspot/devices (WiFi interfaces discovered via nmcli). * Legacy hotspot_* values in wrolpi.yaml are migrated into controller.yaml once on startup, unless controller.yaml already sets them. * The Hotspot SSID/password/device fields moved from the Settings page to the Control page next to the Hotspot toggle; the device is now a dropdown of the WiFi devices found on the machine. * The Controller fallback UI gets the same hotspot settings form for parity. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
ebbc60992c
commit
0d2c13e4e7
12 changed files with 586 additions and 89 deletions
|
|
@ -8,6 +8,9 @@ from controller.api.schemas import (
|
|||
BluetoothActionResponse,
|
||||
BluetoothStatusResponse,
|
||||
HotspotActionResponse,
|
||||
HotspotDevicesResponse,
|
||||
HotspotSettingsRequest,
|
||||
HotspotSettingsResponse,
|
||||
HotspotStatusResponse,
|
||||
RestartServicesResponse,
|
||||
SambaShareAddRequest,
|
||||
|
|
@ -30,13 +33,18 @@ from controller.lib.admin import (
|
|||
enable_hotspot,
|
||||
enable_throttle,
|
||||
get_bluetooth_status_dict,
|
||||
get_hotspot_device,
|
||||
get_hotspot_password,
|
||||
get_hotspot_ssid,
|
||||
get_hotspot_status_dict,
|
||||
get_throttle_status_dict,
|
||||
get_timezone_status_dict,
|
||||
get_wifi_devices,
|
||||
reboot_system,
|
||||
restart_all_services,
|
||||
set_timezone,
|
||||
shutdown_system,
|
||||
update_hotspot_settings,
|
||||
)
|
||||
from controller.lib.config import is_docker_mode
|
||||
from controller.lib.samba import (
|
||||
|
|
@ -56,6 +64,33 @@ async def hotspot_status() -> HotspotStatusResponse:
|
|||
return HotspotStatusResponse(**get_hotspot_status_dict())
|
||||
|
||||
|
||||
@router.get("/api/hotspot/devices", response_model=HotspotDevicesResponse)
|
||||
async def hotspot_devices() -> HotspotDevicesResponse:
|
||||
"""List WiFi devices which could host the hotspot."""
|
||||
return HotspotDevicesResponse(devices=get_wifi_devices())
|
||||
|
||||
|
||||
@router.get("/api/hotspot/settings", response_model=HotspotSettingsResponse)
|
||||
async def hotspot_settings() -> HotspotSettingsResponse:
|
||||
"""Get WiFi hotspot settings."""
|
||||
return HotspotSettingsResponse(
|
||||
device=get_hotspot_device(),
|
||||
ssid=get_hotspot_ssid(),
|
||||
password=get_hotspot_password(),
|
||||
)
|
||||
|
||||
|
||||
@router.post("/api/hotspot/settings", response_model=HotspotSettingsResponse)
|
||||
async def hotspot_settings_update(request: HotspotSettingsRequest) -> HotspotSettingsResponse:
|
||||
"""Update WiFi hotspot settings; they are saved in controller.yaml."""
|
||||
result = update_hotspot_settings(device=request.device, ssid=request.ssid, password=request.password)
|
||||
if not result.get("success"):
|
||||
error = result.get("error", "Failed")
|
||||
status_code = 500 if "Docker" in error else 400
|
||||
raise HTTPException(status_code=status_code, detail=error)
|
||||
return HotspotSettingsResponse(device=result["device"], ssid=result["ssid"], password=result["password"])
|
||||
|
||||
|
||||
@router.post("/api/hotspot/enable", response_model=HotspotActionResponse)
|
||||
async def hotspot_enable() -> HotspotActionResponse:
|
||||
"""Enable WiFi hotspot."""
|
||||
|
|
|
|||
|
|
@ -157,6 +157,28 @@ class HotspotStatusResponse(BaseModel):
|
|||
device: Optional[str] = Field(default=None, description="WiFi device name")
|
||||
|
||||
|
||||
class HotspotDevicesResponse(BaseModel):
|
||||
"""Response model for /api/hotspot/devices endpoint."""
|
||||
|
||||
devices: list[str] = Field(description="Available WiFi device names")
|
||||
|
||||
|
||||
class HotspotSettingsRequest(BaseModel):
|
||||
"""Request model for updating hotspot settings; only provided values are changed."""
|
||||
|
||||
device: Optional[str] = Field(default=None, description="WiFi device name")
|
||||
ssid: Optional[str] = Field(default=None, description="Hotspot SSID")
|
||||
password: Optional[str] = Field(default=None, description="Hotspot password (8 to 63 characters)")
|
||||
|
||||
|
||||
class HotspotSettingsResponse(BaseModel):
|
||||
"""Response model for /api/hotspot/settings endpoint."""
|
||||
|
||||
device: str = Field(description="WiFi device name")
|
||||
ssid: str = Field(description="Hotspot SSID")
|
||||
password: str = Field(description="Hotspot password")
|
||||
|
||||
|
||||
class HotspotActionResponse(BaseModel):
|
||||
"""Response model for hotspot enable/disable actions."""
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,8 @@ 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_bluetooth_status, get_hotspot_status, get_throttle_status, BluetoothStatus, HotspotStatus
|
||||
from controller.lib.admin import get_bluetooth_status, get_hotspot_ssid, 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,
|
||||
|
|
@ -36,16 +37,12 @@ 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.
|
||||
"""
|
||||
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
|
||||
config = get_config()
|
||||
hotspot_config = config.get("hotspot", {})
|
||||
hotspot_ssid = hotspot_config.get("ssid", "WROLPi") if hotspot_status == HotspotStatus.connected else None
|
||||
hotspot_ssid = get_hotspot_ssid() if hotspot_status == HotspotStatus.connected else None
|
||||
|
||||
return {
|
||||
"dockerized": is_docker_mode(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue