@props(['device', 'controllable' => true]) @php $entities = $device->entities; $primary = $controllable ? $entities->first(fn ($e) => in_array($e->type, ['switch', 'light'], true)) : null; $on = $primary ? (data_get($primary->state?->state, 'on') === true) : false; $secondary = $primary ? $entities->reject(fn ($e) => $e->id === $primary->id) : $entities; $online = $device->isOnline(); $icon = match (true) { $device->isCloud() => 'doorbell', $primary?->type === 'light' => 'bolt', $entities->contains(fn ($e) => $e->type === 'contact') => 'window', $entities->contains(fn ($e) => $e->type === 'motion') => 'activity', default => 'devices', }; @endphp