mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-10-18 21:47:39 +02:00
Fix unused globals and redundant JS conditions (CodeQL)
Remove vestigial _debug_logging_enabled and _debug_logging_enabled_at globals from support.py (written but never read; DB is queried directly). Simplify hue classification in PrintersPage.tsx and colors.ts by removing always-true h < 345 checks and dead 'Unknown' fallbacks. Narrow getWifiStrength param type to remove always-false null guard.
This commit is contained in:
@@ -30,10 +30,6 @@ from backend.app.models.user import User
|
||||
router = APIRouter(prefix="/support", tags=["support"])
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# In-memory state for debug logging (persisted to settings DB)
|
||||
_debug_logging_enabled = False
|
||||
_debug_logging_enabled_at: datetime | None = None
|
||||
|
||||
|
||||
class DebugLoggingState(BaseModel):
|
||||
enabled: bool
|
||||
@@ -114,12 +110,8 @@ async def get_debug_logging_state(
|
||||
_: User | None = RequirePermissionIfAuthEnabled(Permission.SETTINGS_READ),
|
||||
):
|
||||
"""Get current debug logging state."""
|
||||
global _debug_logging_enabled, _debug_logging_enabled_at
|
||||
|
||||
async with async_session() as db:
|
||||
enabled, enabled_at = await _get_debug_setting(db)
|
||||
_debug_logging_enabled = enabled
|
||||
_debug_logging_enabled_at = enabled_at
|
||||
|
||||
duration = None
|
||||
if enabled and enabled_at:
|
||||
@@ -138,12 +130,8 @@ async def toggle_debug_logging(
|
||||
_: User | None = RequirePermissionIfAuthEnabled(Permission.SETTINGS_UPDATE),
|
||||
):
|
||||
"""Enable or disable debug logging."""
|
||||
global _debug_logging_enabled, _debug_logging_enabled_at
|
||||
|
||||
async with async_session() as db:
|
||||
enabled_at = await _set_debug_setting(db, toggle.enabled)
|
||||
_debug_logging_enabled = toggle.enabled
|
||||
_debug_logging_enabled_at = enabled_at
|
||||
|
||||
_apply_log_level(toggle.enabled)
|
||||
|
||||
@@ -458,13 +446,9 @@ async def generate_support_bundle(
|
||||
_: User | None = RequirePermissionIfAuthEnabled(Permission.SETTINGS_READ),
|
||||
):
|
||||
"""Generate a support bundle ZIP file for issue reporting."""
|
||||
global _debug_logging_enabled, _debug_logging_enabled_at
|
||||
|
||||
# Check if debug logging is enabled
|
||||
async with async_session() as db:
|
||||
enabled, enabled_at = await _get_debug_setting(db)
|
||||
_debug_logging_enabled = enabled
|
||||
_debug_logging_enabled_at = enabled_at
|
||||
enabled, _enabled_at = await _get_debug_setting(db)
|
||||
|
||||
if not enabled:
|
||||
raise HTTPException(
|
||||
@@ -500,13 +484,9 @@ async def generate_support_bundle(
|
||||
|
||||
async def init_debug_logging():
|
||||
"""Initialize debug logging state from database on startup."""
|
||||
global _debug_logging_enabled, _debug_logging_enabled_at
|
||||
|
||||
try:
|
||||
async with async_session() as db:
|
||||
enabled, enabled_at = await _get_debug_setting(db)
|
||||
_debug_logging_enabled = enabled
|
||||
_debug_logging_enabled_at = enabled_at
|
||||
enabled, _ = await _get_debug_setting(db)
|
||||
|
||||
if enabled:
|
||||
_apply_log_level(True)
|
||||
|
||||
@@ -398,9 +398,7 @@ function hexToBasicColorName(hex: string | null | undefined): string {
|
||||
if (h < 200) return 'Cyan';
|
||||
if (h < 260) return 'Blue';
|
||||
if (h < 290) return 'Purple';
|
||||
if (h < 345) return 'Pink';
|
||||
|
||||
return 'Unknown';
|
||||
return 'Pink';
|
||||
}
|
||||
|
||||
// Format K value with 3 decimal places, default to 0.020 if null
|
||||
@@ -707,8 +705,7 @@ function getPrinterImage(model: string | null | undefined): string {
|
||||
return '/img/printers/default.png';
|
||||
}
|
||||
|
||||
function getWifiStrength(rssi: number | null | undefined): { labelKey: string; color: string; bars: number } {
|
||||
if (rssi == null) return { labelKey: '', color: 'text-bambu-gray', bars: 0 };
|
||||
function getWifiStrength(rssi: number): { labelKey: string; color: string; bars: number } {
|
||||
if (rssi >= -50) return { labelKey: 'printers.wifiSignal.excellent', color: 'text-bambu-green', bars: 4 };
|
||||
if (rssi >= -60) return { labelKey: 'printers.wifiSignal.good', color: 'text-bambu-green', bars: 3 };
|
||||
if (rssi >= -70) return { labelKey: 'printers.wifiSignal.fair', color: 'text-yellow-400', bars: 2 };
|
||||
|
||||
@@ -90,8 +90,7 @@ export function hexToColorName(hex: string | null | undefined): string {
|
||||
if (h < 200) return 'Cyan';
|
||||
if (h < 260) return 'Blue';
|
||||
if (h < 290) return 'Purple';
|
||||
if (h < 345) return 'Pink';
|
||||
return 'Unknown';
|
||||
return 'Pink';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user