diff --git a/PrusaLink/PrusaLink.php b/PrusaLink/PrusaLink.php new file mode 100644 index 0000000000..cc58543eea --- /dev/null +++ b/PrusaLink/PrusaLink.php @@ -0,0 +1,84 @@ +jar = new \GuzzleHttp\Cookie\CookieJar; // Uncomment if cookies need to be set + } + + public function test() + { + $test = parent::appTest($this->url('api/v1/status'), $this->getAttrs()); + echo $test->status; + } + + public function livestats() + { + $status = 'inactive'; + $res = parent::execute($this->url('api/v1/status'), $this->getAttrs()); + $details = json_decode($res->getBody()); + + // Check if time_remaining exists and convert it + if (isset($details->job->time_remaining)) { + $short_time_remaining = $this->secondsToShortTime($details->job->time_remaining); + } else { + $short_time_remaining = "N/A"; + } + + if (isset($details->printer->temp_bed)) { + $temp_bed = $details->printer->temp_bed . " °C"; // Append "°C" + } else { + $temp_bed = "N/A"; // Default value + } + + if (isset($details->printer->temp_nozzle)) { + $temp_nozzle = $details->printer->temp_nozzle . " °C"; // Append "°C" + } else { + $temp_nozzle = "N/A"; // Default value + } + + $data = [ + "state" => $details->printer->state ?? "OFFLINE", // Default state as "OFFLINE" + "short_time_remaining" => $short_time_remaining, + "temp_nozzle" => $temp_nozzle, + "temp_bed" => $temp_bed + ]; + + return parent::getLiveStats($status, $data); + } + + private function secondsToShortTime($seconds) { + return CarbonInterval::seconds($seconds) + ->cascade() + ->forHumans([ + 'short' => true, + 'join' => ' ', // Use a space instead of "and" or "," + 'maximumUnit' => 2 + ]); + } + + public function url($endpoint) + { + $api_url = parent::normaliseurl($this->config->url) . $endpoint; + return $api_url; + } + + private function getAttrs() + { + return [ + "headers" => [ + "X-Api-Key" => $this->config->apikey + ], + ]; + } +} diff --git a/PrusaLink/app.json b/PrusaLink/app.json new file mode 100644 index 0000000000..727a7cbf7b --- /dev/null +++ b/PrusaLink/app.json @@ -0,0 +1,10 @@ +{ + "appid": "e5f6e96e960a08fa8f1fe702b45690cbc789ebc9", + "name": "PrusaLink", + "website": "https://github.com/prusa3d/Prusa-Link-Web/tree/master", + "license": "CNRI Python Open Source GPL Compatible License Agreement", + "description": "Website for Prusa Printers to Control and get the current Status of the printer\r\nhttps://github.com/prusa3d/Prusa-Link-Web/blob/master/spec/openapi.yaml", + "enhanced": true, + "tile_background": "dark", + "icon": "prusalink.svg" +} \ No newline at end of file diff --git a/PrusaLink/config.blade.php b/PrusaLink/config.blade.php new file mode 100644 index 0000000000..5dc2116903 --- /dev/null +++ b/PrusaLink/config.blade.php @@ -0,0 +1,15 @@ +

{{ __('app.apps.config') }} ({{ __('app.optional') }}) @include('items.enable')

+
+
+ + {!! Form::text('config[override_url]', isset($item) ? $item->getconfig()->override_url : null, ['placeholder' => __('app.apps.override'), 'id' => 'override_url', 'class' => 'form-control']) !!} +
+
+ + {!! Form::input('password', 'config[apikey]', isset($item) ? $item->getconfig()->apikey : null, ['placeholder' => __('app.apps.apikey'), 'data-config' => 'apikey', 'class' => 'form-control config-item']) !!} +
+
+ +
+
+ \ No newline at end of file diff --git a/PrusaLink/livestats.blade.php b/PrusaLink/livestats.blade.php new file mode 100644 index 0000000000..2fbf84ce82 --- /dev/null +++ b/PrusaLink/livestats.blade.php @@ -0,0 +1,23 @@ + + \ No newline at end of file diff --git a/PrusaLink/prusalink.svg b/PrusaLink/prusalink.svg new file mode 100644 index 0000000000..e43021555b --- /dev/null +++ b/PrusaLink/prusalink.svg @@ -0,0 +1 @@ + \ No newline at end of file