<?php
namespace SHServ\Tools\DeviceAPI;
class Hatch extends Base {
public function get_state(): String | null {
$status_response = $this -> get_status();
if($status_response["status"] != "ok") {
return null;
}
return $status_response["hatch"]["state"];
}
public function is_opened(): Bool | null {
$state = $this -> get_state();
return is_null($state)
? null
: $status_response["hatch"]["state"] == "open";
}
public function is_closed(): Bool | null {
$state = $this -> get_state();
return is_null($state)
? null
: $status_response["hatch"]["state"] == "closed";
}
public function is_opening(): Bool | null {
$state = $this -> get_state();
return is_null($state)
? null
: $status_response["hatch"]["state"] == "opening";
}
public function is_closing(): Bool {
$state = $this -> get_state();
return is_null($state)
? null
: $status_response["hatch"]["state"] == "closing";
}
public function open(int $percent = 100) {
return $this -> post_action("open", [
"percent" => max(0, $percent)
]);
}
public function close(int $percent = 100) {
return $this -> post_action("close", [
"percent" => max(0, $percent)
]);
}
}