Passed
Push — master ( f9c14b...c6fe8b )
by Laurens
02:03
created

ThermostatCommand   A

Complexity

Total Complexity 22

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 96
ccs 50
cts 50
cp 1
rs 10
c 0
b 0
f 0
wmc 22

12 Methods

Rating   Name   Duplication   Size   Complexity  
A setFanTimerDuration() 0 3 1
A getCommands() 0 3 1
A getId() 0 3 1
A setEcoTemperatureLow() 0 7 3
A setTargetTemperature() 0 7 3
A setHvacMode() 0 3 1
A __construct() 0 4 1
A setTargetTemperatureLow() 0 7 3
A setTargetTemperatureHigh() 0 7 3
A setEcoTemperatureHigh() 0 7 3
A setLabel() 0 3 1
A setScale() 0 3 1
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 22
    public function __construct(string $id)
24
    {
25 22
        $this->thermostatId = $id;
26 22
        $this->commands = [];
27 22
    }
28
29 2
    public function setScale(Scale $scale): void
30
    {
31 2
        $this->commands['temperature_scale'] = strtoupper($scale->getValue());
32 2
    }
33
34 3
    public function setTargetTemperature(Temperature $temperature): void
35
    {
36 3
        if ($temperature->getScale()->isCelsius()) {
37 2
            $this->commands['target_temperature_c'] = $temperature->getDegrees();
38
        }
39 3
        if ($temperature->getScale()->isFahrenheit()) {
40 1
            $this->commands['target_temperature_f'] = $temperature->getDegrees();
41
        }
42 3
    }
43
44 2
    public function setTargetTemperatureHigh(Temperature $temperature): void
45
    {
46 2
        if ($temperature->getScale()->isCelsius()) {
47 1
            $this->commands['target_temperature_high_c'] = $temperature->getDegrees();
48
        }
49 2
        if ($temperature->getScale()->isFahrenheit()) {
50 1
            $this->commands['target_temperature_high_f'] = $temperature->getDegrees();
51
        }
52 2
    }
53
54 2
    public function setTargetTemperatureLow(Temperature $temperature): void
55
    {
56 2
        if ($temperature->getScale()->isCelsius()) {
57 1
            $this->commands['target_temperature_low_c'] = $temperature->getDegrees();
58
        }
59 2
        if ($temperature->getScale()->isFahrenheit()) {
60 1
            $this->commands['target_temperature_low_f'] = $temperature->getDegrees();
61
        }
62 2
    }
63
64 2
    public function setEcoTemperatureHigh(Temperature $temperature): void
65
    {
66 2
        if ($temperature->getScale()->isCelsius()) {
67 1
            $this->commands['eco_temperature_high_c'] = $temperature->getDegrees();
68
        }
69 2
        if ($temperature->getScale()->isFahrenheit()) {
70 1
            $this->commands['eco_temperature_high_f'] = $temperature->getDegrees();
71
        }
72 2
    }
73
74 2
    public function setEcoTemperatureLow(Temperature $temperature): void
75
    {
76 2
        if ($temperature->getScale()->isCelsius()) {
77 1
            $this->commands['eco_temperature_low_c'] = $temperature->getDegrees();
78
        }
79 2
        if ($temperature->getScale()->isFahrenheit()) {
80 1
            $this->commands['eco_temperature_low_f'] = $temperature->getDegrees();
81
        }
82 2
    }
83
84 5
    public function setHvacMode(HvacMode $mode): void
85
    {
86 5
        $this->commands['hvac_mode'] = $mode->getValue();
87 5
    }
88
89 1
    public function setLabel(string $label): void
90
    {
91 1
        $this->commands['label'] = $label;
92 1
    }
93
94 1
    public function setFanTimerDuration(int $duration): void
95
    {
96 1
        $this->commands['fan_timer_duration'] = $duration;
97 1
    }
98
99 21
    public function getCommands(): array
100
    {
101 21
        return $this->commands;
102
    }
103
104 2
    public function getId(): string
105
    {
106 2
        return $this->thermostatId;
107
    }
108
}
109