post("/devices/{$externalId}/turn-on"); } /** @return array{success: bool, error: ?string} */ public function turnOff(string $externalId): array { return $this->post("/devices/{$externalId}/turn-off"); } /** @return array{success: bool, error: ?string} */ public function setLevel(string $externalId, float $level): array { return $this->post("/devices/{$externalId}/set-level", ['level' => $level]); } /** * @param array $body * @return array{success: bool, error: ?string} */ private function post(string $path, array $body = []): array { try { $response = Http::timeout(5)->post("{$this->baseUrl}{$path}", $body); } catch (ConnectionException $e) { Log::error('device-control-service unreachable', ['path' => $path, 'error' => $e->getMessage()]); return ['success' => false, 'error' => 'device-control-service недоступен']; } if ($response->failed()) { Log::error('device-control-service returned an error status', ['path' => $path, 'status' => $response->status()]); return ['success' => false, 'error' => 'device-control-service вернул ошибку']; } return [ 'success' => (bool) $response->json('success'), 'error' => $response->json('error'), ]; } }