79 lines
1.9 KiB
PHP
79 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Devices;
|
|
|
|
use App\Models\Device;
|
|
use App\Models\Room;
|
|
use Livewire\Attributes\Layout;
|
|
use Livewire\Attributes\On;
|
|
use Livewire\Attributes\Validate;
|
|
use Livewire\Component;
|
|
|
|
#[Layout('layouts.app')]
|
|
class Show extends Component
|
|
{
|
|
public Device $device;
|
|
|
|
#[Validate('required|string|max:100')]
|
|
public string $name = '';
|
|
|
|
public ?int $roomId = null;
|
|
|
|
public ?string $flash = null;
|
|
|
|
public function mount(Device $device): void
|
|
{
|
|
$this->device = $device;
|
|
$this->name = $device->name;
|
|
$this->roomId = $device->room_id;
|
|
}
|
|
|
|
public function saveName(): void
|
|
{
|
|
$this->validate();
|
|
$this->device->update(['name' => $this->name]);
|
|
$this->flashMessage(__('devices.saved'));
|
|
}
|
|
|
|
public function saveRoom(): void
|
|
{
|
|
$this->validate(['roomId' => ['nullable', 'integer', 'exists:rooms,id']]);
|
|
$this->device->update(['room_id' => $this->roomId ?: null]);
|
|
$this->flashMessage(__('devices.saved'));
|
|
}
|
|
|
|
public function toggleStatus(): void
|
|
{
|
|
$this->device->update([
|
|
'status' => $this->device->status === 'active' ? 'ignored' : 'active',
|
|
]);
|
|
$this->flashMessage(__('devices.saved'));
|
|
}
|
|
|
|
// Mock command paths — Phase 3 routes these through DeviceCommandService → driver (H1).
|
|
#[On('restartDevice')]
|
|
public function restart(): void
|
|
{
|
|
$this->flashMessage(__('devices.command_sent_demo'));
|
|
}
|
|
|
|
public function checkUpdate(): void
|
|
{
|
|
$this->flashMessage(__('devices.no_update_demo'));
|
|
}
|
|
|
|
protected function flashMessage(string $message): void
|
|
{
|
|
$this->flash = $message;
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
$this->device->load(['entities.state', 'room']);
|
|
|
|
return view('livewire.devices.show', [
|
|
'rooms' => Room::orderBy('sort')->orderBy('name')->get(),
|
|
]);
|
|
}
|
|
}
|