option('triggered-by') ?: 'schedule', null, function () use ($unifi) { $aps = $unifi->getAccessPoints(); if (empty($aps)) { $this->warn('No access points found.'); return ['status' => 'skipped', 'reason' => 'no APs found']; } $delay = max(0, (int) $this->option('delay')); $rebooted = []; $failed = []; 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(); foreach ($aps as $ap) { $mac = strtolower($ap['mac']); $name = $ap['name'] ?? $mac; try { $unifi->rebootDevice($mac); $this->info("Rebooted: {$name} ({$mac})"); $rebooted[] = $name; } catch (\Throwable $e) { $this->error("Failed to reboot {$name}: {$e->getMessage()}"); $failed[] = ['name' => $name, 'error' => $e->getMessage()]; } if ($delay > 0 && count($rebooted) + count($failed) < count($aps)) { sleep($delay); } } return [ 'status' => count($failed) === 0 ? 'succeeded' : (count($rebooted) > 0 ? 'partial' : 'failed'), 'rebooted' => $rebooted, 'failed' => $failed, 'total' => count($aps), ]; } ); $this->info("Done. Status: {$run->status}."); return $run->status === 'failed' ? self::FAILURE : self::SUCCESS; } }