Thermostat   A
last analyzed

Complexity

Total Complexity 37

Size/Duplication

Total Lines 408
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 111
dl 0
loc 408
ccs 128
cts 128
cp 1
rs 9.44
c 0
b 0
f 0
wmc 37

37 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
A getHvacState() 0 3 1
A setTargetTemperature() 0 6 1
A setLabel() 0 6 1
A getSoftwareVersion() 0 3 1
A __construct() 0 58 1
A getHvacMode() 0 3 1
A getAmbientTemperature() 0 3 1
A canCool() 0 3 1
A getNameLong() 0 3 1
A hasFan() 0 3 1
A getTargetTemperature() 0 3 1
A hasLeaf() 0 3 1
A isOnline() 0 3 1
A isUsingEmergencyHeat() 0 3 1
A getScale() 0 3 1
A setHvacMode() 0 6 1
A canHeat() 0 3 1
A getHumidity() 0 3 1
A getTargetTemperatureLow() 0 3 1
A getStructureId() 0 3 1
A setScale() 0 6 1
A setEcoTemperatureHigh() 0 6 1
A getLastConnection() 0 3 1
A getLocale() 0 3 1
A setEcoTemperatureLow() 0 6 1
A isFanTimerActive() 0 3 1
A setTargetTemperatureHigh() 0 6 1
A getWhereId() 0 3 1
A getDeviceId() 0 3 1
A setTargetTemperatureLow() 0 6 1
A getLockedTempMax() 0 3 1
A getLockedTempMin() 0 3 1
A setFanTimerDuration() 0 6 1
A isLocked() 0 3 1
A getFanTimerTimeout() 0 3 1
A getTargetTemperatureHigh() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LauLamanApps\NestApi\Client\Device;
6
7
use DateTimeImmutable;
8
use LauLamanApps\NestApi\Client\Device\Thermostat\HvacMode;
9
use LauLamanApps\NestApi\Client\Device\Thermostat\HvacState;
10
use LauLamanApps\NestApi\Client\Device\Thermostat\Temperature;
11
use LauLamanApps\NestApi\Client\Device\Thermostat\Temperature\Scale;
12
use LauLamanApps\NestApi\Http\Command\ThermostatCommand;
13
use LauLamanApps\NestApi\NestClientInterface;
14
15
final class Thermostat
16
{
17
    /**
18
     * @var NestClientInterface
19
     */
20
    private $client;
21
22
    /**
23
     * @var string
24
     */
25
    private $deviceId;
26
27
    /**
28
     * @var string
29
     */
30
    private $whereId;
31
32
    /**
33
     * @var string
34
     */
35
    private $structureId;
36
37
    /**
38
     * @var string
39
     */
40
    private $name;
41
42
    /**
43
     * @var string
44
     */
45
    private $nameLong;
46
47
    /**
48
     * @var Scale
49
     */
50
    private $scale;
51
52
    /**
53
     * @var string
54
     */
55
    private $locale;
56
57
    /**
58
     * @var string
59
     */
60
    private $softwareVersion;
61
62
    /**
63
     * @var bool
64
     */
65
    private $canHeat;
66
67
    /**
68
     * @var bool
69
     */
70
    private $canCool;
71
72
    /**
73
     * @var bool
74
     */
75
    private $hasFan;
76
77
    /**
78
     * @var Temperature
79
     */
80
    private $ambientTemperature;
81
82
    /**
83
     * @var Temperature
84
     */
85
    private $targetTemperature;
86
87
    /**
88
     * @var Temperature
89
     */
90
    private $targetTemperatureHigh;
91
92
    /**
93
     * @var Temperature
94
     */
95
    private $targetTemperatureLow;
96
97
    /**
98
     * @var Temperature
99
     */
100
    private $lockedTempMin;
101
102
    /**
103
     * @var Temperature
104
     */
105
    private $lockedTempMax;
106
107
    /**
108
     * @var bool
109
     */
110
    private $has_leaf;
111
112
    /**
113
     * @var int
114
     */
115
    private $humidity;
116
117
    /**
118
     * @var HvacMode
119
     */
120
    private $hvacMode;
121
122
    /**
123
     * @var HvacState
124
     */
125
    private $hvacState;
126
127
    /**
128
     * @var bool
129
     */
130
    private $isUsingEmergencyHeat;
131
132
    /**
133
     * @var bool
134
     */
135
    private $locked;
136
137
    /**
138
     * @var bool
139
     */
140
    private $online;
141
142
    /**
143
     * @var null|DateTimeImmutable
144
     */
145
    private $lastConnection;
146
147
    /**
148
     * @var bool
149
     */
150
    private $fanTimerActive;
151
152
    /**
153
     * @var DateTimeImmutable
154
     */
155
    private $fanTimerTimeout;
156
157
158 35
    public function __construct(
159
        NestClientInterface $nestClient,
160
        string $deviceId,
161
        string $whereId,
162
        string $structureId,
163
        string $name,
164
        string $nameLong,
165
        Scale $scale,
166
        string $locale,
167
        string $softwareVersion,
168
        bool $canHeat,
169
        bool $canCool,
170
        bool $hasFan,
171
        Temperature $ambientTemperature,
172
        Temperature $targetTemperature,
173
        Temperature $targetTemperatureHigh,
174
        Temperature $targetTemperatureLow,
175
        Temperature $lockedTempMin,
176
        Temperature $lockedTempMax,
177
        bool $has_leaf,
178
        int $humidity,
179
        HvacMode $hvacMode,
180
        HvacState $hvacState,
181
        bool $isUsingEmergencyHeat,
182
        bool $locked,
183
        bool $online,
184
        ?DateTimeImmutable $lastConnection = null,
185
        bool $fanTimerActive,
186
        DateTimeImmutable $fanTimerTimeout
187
    ) {
188 35
        $this->deviceId = $deviceId;
189 35
        $this->whereId = $whereId;
190 35
        $this->structureId = $structureId;
191 35
        $this->name = $name;
192 35
        $this->nameLong = $nameLong;
193 35
        $this->scale = $scale;
194 35
        $this->locale = $locale;
195 35
        $this->softwareVersion = $softwareVersion;
196 35
        $this->canHeat = $canHeat;
197 35
        $this->canCool = $canCool;
198 35
        $this->hasFan = $hasFan;
199 35
        $this->ambientTemperature = $ambientTemperature;
200 35
        $this->targetTemperature = $targetTemperature;
201 35
        $this->targetTemperatureHigh = $targetTemperatureHigh;
202 35
        $this->targetTemperatureLow = $targetTemperatureLow;
203 35
        $this->lockedTempMin = $lockedTempMin;
204 35
        $this->lockedTempMax = $lockedTempMax;
205 35
        $this->has_leaf = $has_leaf;
206 35
        $this->humidity = $humidity;
207 35
        $this->hvacMode = $hvacMode;
208 35
        $this->hvacState = $hvacState;
209 35
        $this->isUsingEmergencyHeat = $isUsingEmergencyHeat;
210 35
        $this->locked = $locked;
211 35
        $this->online = $online;
212 35
        $this->lastConnection = $lastConnection;
213 35
        $this->fanTimerActive = $fanTimerActive;
214 35
        $this->fanTimerTimeout = $fanTimerTimeout;
215 35
        $this->client = $nestClient;
216 35
    }
217
218 33
    public function getDeviceId(): string
219
    {
220 33
        return $this->deviceId;
221
    }
222
223 2
    public function getWhereId(): string
224
    {
225 2
        return $this->whereId;
226
    }
227
228 2
    public function getStructureId(): string
229
    {
230 2
        return $this->structureId;
231
    }
232
233 4
    public function getName(): string
234
    {
235 4
        return $this->name;
236
    }
237
238 2
    public function getNameLong(): string
239
    {
240 2
        return $this->nameLong;
241
    }
242
243 2
    public function getScale(): Scale
244
    {
245 2
        return $this->scale;
246
    }
247
248 2
    public function getLocale(): string
249
    {
250 2
        return $this->locale;
251
    }
252
253 2
    public function getSoftwareVersion(): string
254
    {
255 2
        return $this->softwareVersion;
256
    }
257
258 2
    public function canHeat(): bool
259
    {
260 2
        return $this->canHeat;
261
    }
262
263 2
    public function canCool(): bool
264
    {
265 2
        return $this->canCool;
266
    }
267
268 2
    public function hasFan(): bool
269
    {
270 2
        return $this->hasFan;
271
    }
272
273 2
    public function getAmbientTemperature(): Temperature
274
    {
275 2
        return $this->ambientTemperature;
276
    }
277
278 2
    public function getTargetTemperature(): Temperature
279
    {
280 2
        return $this->targetTemperature;
281
    }
282
283 2
    public function getTargetTemperatureHigh(): Temperature
284
    {
285 2
        return $this->targetTemperatureHigh;
286
    }
287
288 2
    public function getTargetTemperatureLow(): Temperature
289
    {
290 2
        return $this->targetTemperatureLow;
291
    }
292
293 2
    public function getLockedTempMin(): Temperature
294
    {
295 2
        return $this->lockedTempMin;
296
    }
297
298 2
    public function getLockedTempMax(): Temperature
299
    {
300 2
        return $this->lockedTempMax;
301
    }
302
303 2
    public function hasLeaf(): bool
304
    {
305 2
        return $this->has_leaf;
306
    }
307
308 2
    public function getHumidity(): int
309
    {
310 2
        return $this->humidity;
311
    }
312
313 2
    public function getHvacMode(): HvacMode
314
    {
315 2
        return $this->hvacMode;
316
    }
317
318 2
    public function getHvacState(): HvacState
319
    {
320 2
        return $this->hvacState;
321
    }
322
323 2
    public function isUsingEmergencyHeat(): bool
324
    {
325 2
        return $this->isUsingEmergencyHeat;
326
    }
327
328 2
    public function isLocked(): bool
329
    {
330 2
        return $this->locked;
331
    }
332
333 2
    public function isOnline(): bool
334
    {
335 2
        return $this->online;
336
    }
337
338 2
    public function getLastConnection(): ?DateTimeImmutable
339
    {
340 2
        return $this->lastConnection;
341
    }
342
343 2
    public function isFanTimerActive(): bool
344
    {
345 2
        return $this->fanTimerActive;
346
    }
347
348 2
    public function getFanTimerTimeout(): DateTimeImmutable
349
    {
350 2
        return $this->fanTimerTimeout;
351
    }
352
353 2
    public function setScale(Scale $scale): void
354
    {
355 2
        $command = new ThermostatCommand($this->getDeviceId());
356 2
        $command->setScale($scale);
357
358 2
        $this->client->sendCommand($command);
359 2
    }
360
361 4
    public function setTargetTemperature(Temperature $temperature): void
362
    {
363 4
        $command = new ThermostatCommand($this->getDeviceId());
364 4
        $command->setTargetTemperature($temperature);
365
366 4
        $this->client->sendCommand($command);
367 4
    }
368
369 4
    public function setTargetTemperatureHigh(Temperature $temperature): void
370
    {
371 4
        $command = new ThermostatCommand($this->getDeviceId());
372 4
        $command->setTargetTemperatureHigh($temperature);
373
374 4
        $this->client->sendCommand($command);
375 4
    }
376
377 4
    public function setTargetTemperatureLow(Temperature $temperature): void
378
    {
379 4
        $command = new ThermostatCommand($this->getDeviceId());
380 4
        $command->setTargetTemperatureLow($temperature);
381
382 4
        $this->client->sendCommand($command);
383 4
    }
384
385 4
    public function setEcoTemperatureHigh(Temperature $temperature): void
386
    {
387 4
        $command = new ThermostatCommand($this->getDeviceId());
388 4
        $command->setEcoTemperatureHigh($temperature);
389
390 4
        $this->client->sendCommand($command);
391 4
    }
392
393 4
    public function setEcoTemperatureLow(Temperature $temperature): void
394
    {
395 4
        $command = new ThermostatCommand($this->getDeviceId());
396 4
        $command->setEcoTemperatureLow($temperature);
397
398 4
        $this->client->sendCommand($command);
399 4
    }
400
401 5
    public function setHvacMode(HvacMode $mode): void
402
    {
403 5
        $command = new ThermostatCommand($this->getDeviceId());
404 5
        $command->setHvacMode($mode);
405
406 5
        $this->client->sendCommand($command);
407 5
    }
408
409 1
    public function setLabel(string $label): void
410
    {
411 1
        $command = new ThermostatCommand($this->getDeviceId());
412 1
        $command->setLabel($label);
413
414 1
        $this->client->sendCommand($command);
415 1
    }
416
417 1
    public function setFanTimerDuration(int $duration): void
418
    {
419 1
        $command = new ThermostatCommand($this->getDeviceId());
420 1
        $command->setFanTimerDuration($duration);
421
422 1
        $this->client->sendCommand($command);
423 1
    }
424
}
425