Lines
100.00%
9 / 9
Methods
100.00%
1 / 1
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| assessSnapshot | 100.00% | 9 / 9 | 100.00% | 1 / 1 | 7 | ||
| 12 | final readonly class ReadinessCheck | |
| 13 | { | |
| 14 | public function assessSnapshot(RuntimeSnapshot $snapshot): ReadinessVerdict | |
| 15 | { | |
| 16 | $unreadyReasons = []; | |
| 17 | ||
| 18 | if ($snapshot->connection->phase !== ConnectionPhase::Connected) { | |
| 19 | $unreadyReasons[] = 'Home Assistant is ' . $snapshot->connection->phase->value; | |
| 20 | } | |
| 21 | ||
| 22 | if ($snapshot->workers !== [] && !array_any($snapshot->workers, static fn(WorkerStatus $worker): bool => $worker->phase === WorkerPhase::Live && $worker->ready)) { | |
| 23 | $unreadyReasons[] = 'no worker is running'; | |
| 24 | } | |
| 25 | ||
| 26 | foreach ($snapshot->workers as $worker) { | |
| 27 | if ($worker->phase === WorkerPhase::Quarantined) { | |
| 28 | $unreadyReasons[] = \sprintf('worker %d is quarantined', $worker->workerId); | |
| 29 | } | |
| 30 | } | |
| 31 | ||
| 32 | return new ReadinessVerdict($unreadyReasons); | |
| 33 | } | |
| 34 | } |