28 lines
713 B
PHP
28 lines
713 B
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Jobs\PollShellyDevice;
|
|
use App\Models\Device;
|
|
use Illuminate\Console\Command;
|
|
|
|
/** Sweeps every active local (HTTP) Shelly and queues a status poll. Scheduled sub-minute. */
|
|
class ShellyPollCommand extends Command
|
|
{
|
|
protected $signature = 'shelly:poll';
|
|
|
|
protected $description = 'Poll local (HTTP) Shelly devices for their current status.';
|
|
|
|
public function handle(): int
|
|
{
|
|
Device::query()
|
|
->where('vendor', 'Shelly')
|
|
->where('protocol', 'http')
|
|
->where('status', 'active')
|
|
->pluck('id')
|
|
->each(fn ($id) => PollShellyDevice::dispatch($id));
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
}
|