Skip to content

Commit

Permalink
chore: fix style issues in MainSail app
Browse files Browse the repository at this point in the history
  • Loading branch information
imnotjames committed Feb 27, 2024
1 parent c0a59a2 commit 94eda79
Showing 1 changed file with 49 additions and 52 deletions.
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 94eda79

Please sign in to comment.