room = $room; } #[On('echo-private:home,.DeviceStateChanged')] public function onDeviceStateChanged(): void {} public function toggleEntity(int $entityId): void { $entity = Entity::query() ->whereHas('device', fn ($q) => $q->where('room_id', $this->room->id)) ->with('device', 'state') ->find($entityId); if ($entity === null || ! in_array($entity->type, ['switch', 'light'], true)) { return; } app(DeviceCommandService::class)->toggle($entity); } public function render() { $this->room->load(['devices' => fn ($q) => $q->orderBy('name'), 'devices.entities.state']); return view('livewire.rooms.show'); } }