firstOrFail(); $this->entityUuid = $model->uuid; $state = $model->state?->state ?? []; $this->brightness = (int) ($state['brightness'] ?? 100); if (isset($state['rgb']) && is_array($state['rgb'])) { $rgb = array_pad(array_map('intval', $state['rgb']), 3, 255); $this->color = sprintf('#%02X%02X%02X', $rgb[0], $rgb[1], $rgb[2]); } } #[Computed] public function entity(): Entity { return Entity::with('device', 'state')->where('uuid', $this->entityUuid)->firstOrFail(); } public function apply(): void { $rgb = sscanf($this->color, '#%02x%02x%02x'); app(DeviceCommandService::class)->setLight($this->entity(), [ 'on' => true, 'brightness' => $this->brightness, 'rgb' => $rgb, ]); $this->closeModal(); } public function turnOff(): void { app(DeviceCommandService::class)->setOn($this->entity(), false); $this->closeModal(); } public function render() { return view('livewire.modals.light-control', [ 'presets' => ['#FFD9A0', '#FFFFFF', '#FF6B6B', '#4FC1FF', '#34D399', '#A78BFA', '#FBBF24'], ]); } }