mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-13 15:07:49 +00:00
feat(#17): add commands and jobs to poll, download and update firmware
feat(#17): add commands and jobs to poll, download and update firmware feat(#17): update firmware modal feat(#17): add tests
This commit is contained in:
parent
93aac51182
commit
87b9b57c3d
13 changed files with 567 additions and 3 deletions
75
app/Console/Commands/FirmwareUpdateCommand.php
Normal file
75
app/Console/Commands/FirmwareUpdateCommand.php
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Device;
|
||||
use App\Models\Firmware;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
use function Laravel\Prompts\multiselect;
|
||||
use function Laravel\Prompts\select;
|
||||
|
||||
class FirmwareUpdateCommand extends Command
|
||||
{
|
||||
protected $signature = 'trmnl:firmware:update';
|
||||
|
||||
protected $description = 'Command description';
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
|
||||
$checkFirmware = select(
|
||||
label: 'Check for new firmware?',
|
||||
options: [
|
||||
'check' => 'Check. Devices will download binary from the original source.',
|
||||
'download' => 'Check & Download. Devices will download binary from BYOS.',
|
||||
'no' => 'Do not check.',
|
||||
],
|
||||
);
|
||||
|
||||
if ($checkFirmware !== 'no') {
|
||||
$this->call('trmnl:firmware:check', [
|
||||
'--download' => $checkFirmware === 'download',
|
||||
]);
|
||||
}
|
||||
|
||||
$firmwareVersion = select(
|
||||
label: 'Update to which version?',
|
||||
options: Firmware::pluck('version_tag', 'id')
|
||||
);
|
||||
|
||||
$devices = multiselect(
|
||||
label: 'Which devices should be updated?',
|
||||
options: [
|
||||
'all' => 'ALL Devices',
|
||||
...Device::all()->mapWithKeys(function ($device) {
|
||||
// without _ returns index
|
||||
return ["_$device->id" => "$device->name (Current version: $device->last_firmware_version)"];
|
||||
})->toArray()
|
||||
],
|
||||
scroll: 10
|
||||
);
|
||||
|
||||
|
||||
|
||||
if (empty($devices)) {
|
||||
$this->error('No devices selected. Aborting.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (in_array('all', $devices)) {
|
||||
$devices = Device::pluck('id')->toArray();
|
||||
} else {
|
||||
$devices = array_map(function($selected) {
|
||||
return (int) str_replace('_', '', $selected);
|
||||
}, $devices);
|
||||
}
|
||||
|
||||
|
||||
foreach ($devices as $deviceId) {
|
||||
Device::find($deviceId)->update(['update_firmware_id' => $firmwareVersion]);
|
||||
|
||||
$this->info("Device with id [$deviceId] will update firmware on next request.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue