getAccessPoints(); } catch (\Throwable $e) { $this->error('Failed to fetch APs: ' . $e->getMessage()); return self::FAILURE; } if (empty($aps)) { $this->warn('No access points found.'); return self::SUCCESS; } $delay = max(0, (int) $this->option('delay')); // Pre-mark all APs as planned reboots before sending any commands foreach ($aps as $ap) { $mac = strtolower($ap['mac']); Cache::put("unifi:planned_reboot:{$mac}", true, now()->addMinutes(20)); $this->line("Marked planned reboot: {$ap['name']} ({$mac})"); } $this->newLine(); $ok = 0; $fail = 0; foreach ($aps as $ap) { $mac = strtolower($ap['mac']); $name = $ap['name'] ?? $mac; try { $unifi->rebootDevice($mac); $this->info("Rebooted: {$name} ({$mac})"); $ok++; } catch (\Throwable $e) { $this->error("Failed to reboot {$name}: {$e->getMessage()}"); $fail++; } if ($delay > 0 && $ok + $fail < count($aps)) { sleep($delay); } } $this->newLine(); $this->info("Done. {$ok} rebooted, {$fail} failed."); return $fail > 0 ? self::FAILURE : self::SUCCESS; } }