diff --git a/src/Services/WebResetter.php b/src/Services/WebResetter.php new file mode 100644 index 0000000000000000000000000000000000000000..14eb20cc2af75747dcc50565180fa831720c9aea --- /dev/null +++ b/src/Services/WebResetter.php @@ -0,0 +1,73 @@ +<?php + +namespace App\Services; + +use Symfony\Component\HttpClient\HttpClient; +use Symfony\Contracts\HttpClient\HttpClientInterface; + +class WebResetter +{ + public function __construct( + private readonly string $webResetterIp, + private readonly string $webResetterApikey, + private readonly HttpClientInterface $httpClient + ) + { + } + + public function pressPowerButton(int $deviceID, bool $shortPress = true): bool|string + { + $response = $this->httpClient->request( + 'POST', + 'http://' . $this->webResetterIp . '/button/power', + [ + 'json' => [ + 'deviceID' => $deviceID, + 'shortPress' => $shortPress, + 'apikey' => $this->webResetterApikey + ] + ] + ); + if($response->getStatusCode() != 200) { + return $response->getContent(); + } + return true; + } + public function pressResetButton(int $deviceID, bool $shortPress = true): bool|string + { + $response = $this->httpClient->request( + 'POST', + 'http://' . $this->webResetterIp . '/button/reset', + [ + 'json' => [ + 'deviceID' => $deviceID, + 'shortPress' => $shortPress, + 'apikey' => $this->webResetterApikey + ] + ] + ); + if($response->getStatusCode() != 200) { + return $response->getContent(); + } + return true; + } + public function locateLED(int $deviceID, bool $powerOn = true): bool|string + { + $response = $this->httpClient->request( + 'POST', + 'http://' . $this->webResetterIp . '/locate', + [ + 'json' => [ + 'deviceID' => $deviceID, + 'power' => $powerOn, + 'apikey' => $this->webResetterApikey + ] + ] + ); + if($response->getStatusCode() != 200) { + return $response->getContent(); + } + return true; + } + +} \ No newline at end of file