homeos/app/Jobs/PollShellyDevice.php

26 lines
626 B
PHP

<?php
namespace App\Jobs;
use App\Models\Device;
use App\Services\ShellyPoller;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
/** Polls one local (HTTP) Shelly off the queue — after a command, or from the scheduled sweep. */
class PollShellyDevice implements ShouldQueue
{
use Queueable;
public function __construct(public int $deviceId) {}
public function handle(ShellyPoller $poller): void
{
$device = Device::find($this->deviceId);
if ($device !== null && $device->protocol === 'http') {
$poller->poll($device);
}
}
}