|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace LauLamanApps\NestApi\Http\Command; |
|
6
|
|
|
|
|
7
|
|
|
use LauLamanApps\NestApi\Client\Device\Thermostat\HvacMode; |
|
8
|
|
|
use LauLamanApps\NestApi\Client\Device\Thermostat\Temperature; |
|
9
|
|
|
use LauLamanApps\NestApi\Client\Device\Thermostat\Temperature\Scale; |
|
10
|
|
|
|
|
11
|
|
|
final class ThermostatCommand implements Command |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var array |
|
15
|
|
|
*/ |
|
16
|
|
|
private $commands; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var string |
|
20
|
|
|
*/ |
|
21
|
|
|
private $thermostatId; |
|
22
|
|
|
|
|
23
|
51 |
|
public function __construct(string $id) |
|
24
|
|
|
{ |
|
25
|
51 |
|
$this->thermostatId = $id; |
|
26
|
51 |
|
$this->commands = []; |
|
27
|
51 |
|
} |
|
28
|
|
|
|
|
29
|
4 |
|
public function setScale(Scale $scale): void |
|
30
|
|
|
{ |
|
31
|
4 |
|
$this->commands['temperature_scale'] = strtoupper($scale->getValue()); |
|
32
|
4 |
|
} |
|
33
|
|
|
|
|
34
|
7 |
|
public function setTargetTemperature(Temperature $temperature): void |
|
35
|
|
|
{ |
|
36
|
7 |
|
if ($temperature->getScale()->isCelsius()) { |
|
37
|
4 |
|
$this->commands['target_temperature_c'] = $temperature->getDegrees(); |
|
38
|
|
|
} |
|
39
|
7 |
|
if ($temperature->getScale()->isFahrenheit()) { |
|
40
|
3 |
|
$this->commands['target_temperature_f'] = $temperature->getDegrees(); |
|
41
|
|
|
} |
|
42
|
7 |
|
} |
|
43
|
|
|
|
|
44
|
6 |
|
public function setTargetTemperatureHigh(Temperature $temperature): void |
|
45
|
|
|
{ |
|
46
|
6 |
|
if ($temperature->getScale()->isCelsius()) { |
|
47
|
3 |
|
$this->commands['target_temperature_high_c'] = $temperature->getDegrees(); |
|
48
|
|
|
} |
|
49
|
6 |
|
if ($temperature->getScale()->isFahrenheit()) { |
|
50
|
3 |
|
$this->commands['target_temperature_high_f'] = $temperature->getDegrees(); |
|
51
|
|
|
} |
|
52
|
6 |
|
} |
|
53
|
|
|
|
|
54
|
6 |
|
public function setTargetTemperatureLow(Temperature $temperature): void |
|
55
|
|
|
{ |
|
56
|
6 |
|
if ($temperature->getScale()->isCelsius()) { |
|
57
|
3 |
|
$this->commands['target_temperature_low_c'] = $temperature->getDegrees(); |
|
58
|
|
|
} |
|
59
|
6 |
|
if ($temperature->getScale()->isFahrenheit()) { |
|
60
|
3 |
|
$this->commands['target_temperature_low_f'] = $temperature->getDegrees(); |
|
61
|
|
|
} |
|
62
|
6 |
|
} |
|
63
|
|
|
|
|
64
|
6 |
|
public function setEcoTemperatureHigh(Temperature $temperature): void |
|
65
|
|
|
{ |
|
66
|
6 |
|
if ($temperature->getScale()->isCelsius()) { |
|
67
|
3 |
|
$this->commands['eco_temperature_high_c'] = $temperature->getDegrees(); |
|
68
|
|
|
} |
|
69
|
6 |
|
if ($temperature->getScale()->isFahrenheit()) { |
|
70
|
3 |
|
$this->commands['eco_temperature_high_f'] = $temperature->getDegrees(); |
|
71
|
|
|
} |
|
72
|
6 |
|
} |
|
73
|
|
|
|
|
74
|
6 |
|
public function setEcoTemperatureLow(Temperature $temperature): void |
|
75
|
|
|
{ |
|
76
|
6 |
|
if ($temperature->getScale()->isCelsius()) { |
|
77
|
3 |
|
$this->commands['eco_temperature_low_c'] = $temperature->getDegrees(); |
|
78
|
|
|
} |
|
79
|
6 |
|
if ($temperature->getScale()->isFahrenheit()) { |
|
80
|
3 |
|
$this->commands['eco_temperature_low_f'] = $temperature->getDegrees(); |
|
81
|
|
|
} |
|
82
|
6 |
|
} |
|
83
|
|
|
|
|
84
|
10 |
|
public function setHvacMode(HvacMode $mode): void |
|
85
|
|
|
{ |
|
86
|
10 |
|
$this->commands['hvac_mode'] = $mode->getValue(); |
|
87
|
10 |
|
} |
|
88
|
|
|
|
|
89
|
2 |
|
public function setLabel(string $label): void |
|
90
|
|
|
{ |
|
91
|
2 |
|
$this->commands['label'] = $label; |
|
92
|
2 |
|
} |
|
93
|
|
|
|
|
94
|
2 |
|
public function setFanTimerDuration(int $duration): void |
|
95
|
|
|
{ |
|
96
|
2 |
|
$this->commands['fan_timer_duration'] = $duration; |
|
97
|
2 |
|
} |
|
98
|
|
|
|
|
99
|
50 |
|
public function getCommands(): array |
|
100
|
|
|
{ |
|
101
|
50 |
|
return $this->commands; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
31 |
|
public function getDeviceId(): string |
|
105
|
|
|
{ |
|
106
|
31 |
|
return $this->thermostatId; |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|