Skip to content

Commit

Permalink
Merge pull request #699 from imnotjames/chore/fix-style-issues
Browse files Browse the repository at this point in the history
chore: fix style issues in MainSail and MailCatcher apps
  • Loading branch information
mvdkleijn authored Feb 28, 2024
2 parents f912eac + 94eda79 commit 8b5192a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 55 deletions.
8 changes: 5 additions & 3 deletions MailCatcher/MailCatcher.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php namespace App\SupportedApps\MailCatcher;
<?php

class MailCatcher extends \App\SupportedApps {
namespace App\SupportedApps\MailCatcher;

}
class MailCatcher extends \App\SupportedApps
{
}
101 changes: 49 additions & 52 deletions Mainsail/Mainsail.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,61 +6,58 @@

class Mainsail extends \App\SupportedApps implements \App\EnhancedApps
{
public $config;
public $config;

function __construct()
{
}
public function __construct()
{
}

public function test()
{
//https://moonraker.readthedocs.io/en/latest/web_api/#query-server-info
$test = parent::appTest($this->url("/server/info"));
echo $test->status;
}
public function test()
{
//https://moonraker.readthedocs.io/en/latest/web_api/#query-server-info
$test = parent::appTest($this->url("/server/info"));
echo $test->status;
}

public function livestats()
{
$status = "standby";
//https://moonraker.readthedocs.io/en/latest/web_api/#query-printer-object-status
$res = parent::execute($this->url('/printer/objects/query?display_status&toolhead&print_stats'));
if (!$res) {
return parent::getLiveStats($status, ["error" => "Connection"]);
}
$details = json_decode($res->getBody());
$data = [];

$status = $details->result->status->print_stats->state;

if ($status == 'printing'){
$data["completed_pct"] = round($details->result->status->display_status->progress) . '%';

$total_seconds = $details->result->status->toolhead->estimated_print_time;
$completed_seconds = $details->result->status->print_stats->print_duration;

if ($completed_seconds === null) {
$data["estimated"] = "N/A";
} elseif ($completed_seconds > $total_seconds) {
$data["estimated"] = "Soon!";
} elseif ($completed_seconds > 0) {
$remaining_seconds = $total_seconds - $completed_seconds;
$data["estimated"] = Carbon::now()
->addSeconds($remaining_seconds)
->diffForHumans();
} else {
$data["estimated"] = "N/A";
}

}
else {
$data["state"] = ucwords($status);
}
return parent::getLiveStats($status, $data);
}
public function url($endpoint)
{
$api_url = parent::normaliseurl($this->config->url, false) . ':' . $this->config->moonraker_port . $endpoint;
return $api_url;
public function livestats()
{
$status = "standby";
//https://moonraker.readthedocs.io/en/latest/web_api/#query-printer-object-status
$res = parent::execute($this->url('/printer/objects/query?display_status&toolhead&print_stats'));
if (!$res) {
return parent::getLiveStats($status, ["error" => "Connection"]);
}
$details = json_decode($res->getBody());
$data = [];

$status = $details->result->status->print_stats->state;

if ($status == 'printing') {
$data["completed_pct"] = round($details->result->status->display_status->progress) . '%';

$total_seconds = $details->result->status->toolhead->estimated_print_time;
$completed_seconds = $details->result->status->print_stats->print_duration;

if ($completed_seconds === null) {
$data["estimated"] = "N/A";
} elseif ($completed_seconds > $total_seconds) {
$data["estimated"] = "Soon!";
} elseif ($completed_seconds > 0) {
$remaining_seconds = $total_seconds - $completed_seconds;
$data["estimated"] = Carbon::now()
->addSeconds($remaining_seconds)
->diffForHumans();
} else {
$data["estimated"] = "N/A";
}
} else {
$data["state"] = ucwords($status);
}
return parent::getLiveStats($status, $data);
}
public function url($endpoint)
{
$api_url = parent::normaliseurl($this->config->url, false) . ':' . $this->config->moonraker_port . $endpoint;
return $api_url;
}
}

0 comments on commit 8b5192a

Please sign in to comment.