|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace LauLamanApps\NestApi\Client\Factory; |
|
6
|
|
|
|
|
7
|
|
|
use DateTimeZone; |
|
8
|
|
|
use LauLamanApps\NestApi\Client\__shared\AbstractFactory; |
|
9
|
|
|
use LauLamanApps\NestApi\Client\Structure; |
|
10
|
|
|
use LauLamanApps\NestApi\Client\Structure\Away; |
|
11
|
|
|
use LauLamanApps\NestApi\NestClientInterface; |
|
12
|
|
|
|
|
13
|
|
|
final class StructureFactory extends AbstractFactory implements StructureFactoryInterface |
|
14
|
|
|
{ |
|
15
|
4 |
|
public function fromData(array $data, NestClientInterface $client): Structure |
|
16
|
|
|
{ |
|
17
|
4 |
|
return new Structure( |
|
18
|
4 |
|
$this->extractString('structure_id', $data), |
|
19
|
4 |
|
$this->extractString('name', $data), |
|
20
|
4 |
|
$this->extractThermostats($client, $this->extractArrayOrNull('thermostats', $data)), |
|
21
|
4 |
|
$this->extractSmokeCoAlarms($client, $this->extractArrayOrNull('smoke_co_alarms', $data)), |
|
22
|
4 |
|
$this->extractCameras($client, $this->extractArrayOrNull('cameras', $data)), |
|
23
|
4 |
|
$this->extractString('country_code', $data), |
|
24
|
4 |
|
new DateTimeZone($this->extractString('time_zone', $data)), |
|
25
|
4 |
|
Away::get($this->extractString('away', $data)), |
|
26
|
4 |
|
$this->extractBoolean('rhr_enrollment', $data) |
|
27
|
|
|
); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
4 |
|
private function extractThermostats(NestClientInterface $client, ?array $thermostatsData): array |
|
31
|
|
|
{ |
|
32
|
4 |
|
$thermostatsData = $thermostatsData ?? []; |
|
33
|
4 |
|
$thermostats = []; |
|
34
|
4 |
|
foreach ($thermostatsData as $thermostat) { |
|
35
|
2 |
|
$thermostats[$thermostat] = new Structure\ThermostatProxy($client, $thermostat); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
4 |
|
return $thermostats; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
4 |
|
private function extractSmokeCoAlarms(NestClientInterface $client, ?array $SmokeCoAlarmsData): array |
|
42
|
|
|
{ |
|
43
|
4 |
|
$SmokeCoAlarmsData = $SmokeCoAlarmsData ?? []; |
|
44
|
4 |
|
$SmokeCoAlarms = []; |
|
45
|
4 |
|
foreach ($SmokeCoAlarmsData as $SmokeCoAlarm) { |
|
46
|
2 |
|
$SmokeCoAlarms[$SmokeCoAlarm] = new Structure\SmokeCoAlarmProxy($client, $SmokeCoAlarm); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
4 |
|
return $SmokeCoAlarms; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
4 |
|
private function extractCameras(NestClientInterface $client, ?array $camerasData): array |
|
53
|
|
|
{ |
|
54
|
4 |
|
$camerasData = $camerasData ?? []; |
|
55
|
4 |
|
$cameras = []; |
|
56
|
4 |
|
foreach ($camerasData as $camera) { |
|
57
|
2 |
|
$cameras[$camera] = new Structure\CameraProxy($client, $camera); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
4 |
|
return $cameras; |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|