34 lines
988 B
PHP
34 lines
988 B
PHP
<?php
|
|
|
|
namespace App\Livewire;
|
|
|
|
use App\Models\Entity;
|
|
use Livewire\Attributes\Layout;
|
|
use Livewire\Attributes\On;
|
|
use Livewire\Component;
|
|
|
|
#[Layout('layouts.app')]
|
|
class Windows extends Component
|
|
{
|
|
#[On('echo-private:home,.DeviceStateChanged')]
|
|
public function onDeviceStateChanged(): void {}
|
|
|
|
public function render()
|
|
{
|
|
$sensors = Entity::query()
|
|
->whereIn('type', ['contact', 'motion'])
|
|
->with(['device.room', 'device.entities.state', 'state'])
|
|
->get()
|
|
->sortBy(fn ($e) => ($e->device->room?->name ?? 'zzz').$e->device->name)
|
|
->values();
|
|
|
|
$open = $sensors->filter(fn ($e) => $e->type === 'contact' && data_get($e->state, 'state.open') === true)->count();
|
|
|
|
return view('livewire.windows', [
|
|
'groups' => $sensors->groupBy(fn ($e) => $e->device->room?->name ?? __('devices.no_room')),
|
|
'open' => $open,
|
|
'total' => $sensors->count(),
|
|
]);
|
|
}
|
|
}
|