forked from NativePHP/laravel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPowerMonitor.php
38 lines (29 loc) · 1.09 KB
/
PowerMonitor.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
namespace Native\Laravel;
use Native\Laravel\Client\Client;
use Native\Laravel\Enums\SystemIdleStatesEnum;
use Native\Laravel\Enums\ThermalStatesEnum;
class PowerMonitor
{
public function __construct(protected Client $client) {}
public function getSystemIdleState(int $threshold): SystemIdleStatesEnum
{
$result = $this->client->get('power-monitor/get-system-idle-state', [
'threshold' => $threshold,
])->json('result');
return SystemIdleStatesEnum::tryFrom($result) ?? SystemIdleStatesEnum::UNKNOWN;
}
public function getSystemIdleTime(): int
{
return $this->client->get('power-monitor/get-system-idle-time')->json('result');
}
public function getCurrentThermalState(): ThermalStatesEnum
{
$result = $this->client->get('power-monitor/get-current-thermal-state')->json('result');
return ThermalStatesEnum::tryFrom($result) ?? ThermalStatesEnum::UNKNOWN;
}
public function isOnBatteryPower(): bool
{
return $this->client->get('power-monitor/is-on-battery-power')->json('result');
}
}