line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Device::WallyHome::Role::Creator; |
2
|
2
|
|
|
2
|
|
1168
|
use Moose::Role; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
16
|
|
3
|
2
|
|
|
2
|
|
8077
|
use MooseX::AttributeShortcuts; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
11
|
|
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
5513
|
use Data::Dumper; |
|
2
|
|
|
|
|
11951
|
|
|
2
|
|
|
|
|
132
|
|
6
|
2
|
|
|
2
|
|
980
|
use Module::Loader; |
|
2
|
|
|
|
|
23288
|
|
|
2
|
|
|
|
|
1175
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
#== ATTRIBUTES ================================================================= |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has 'callbackObject' => ( |
12
|
|
|
|
|
|
|
is => 'ro', |
13
|
|
|
|
|
|
|
weak_ref => 1, |
14
|
|
|
|
|
|
|
writer => '_callbackObject', |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
#== PUBLIC METHODS ============================================================= |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub instantiateObject { |
21
|
10
|
|
|
10
|
0
|
21
|
my ($self, $class, $params) = @_; |
22
|
|
|
|
|
|
|
|
23
|
10
|
|
50
|
|
|
35
|
$params //= {}; |
24
|
|
|
|
|
|
|
|
25
|
10
|
|
|
|
|
13
|
my $restApiRole = 'Device::WallyHome::Role::REST'; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Dynamically load class module |
28
|
|
|
|
|
|
|
eval { |
29
|
10
|
|
|
|
|
39
|
(my $file = $class) =~ s/::/\//g; |
30
|
|
|
|
|
|
|
|
31
|
10
|
|
|
|
|
3355
|
require $file . '.pm'; |
32
|
|
|
|
|
|
|
|
33
|
10
|
|
|
|
|
70
|
$class->import(); |
34
|
|
|
|
|
|
|
|
35
|
10
|
|
|
|
|
45
|
1; |
36
|
10
|
50
|
|
|
|
11
|
} or do { |
37
|
0
|
|
|
|
|
0
|
die "Failed to dynamically load class module ($class): " . $@; |
38
|
|
|
|
|
|
|
}; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# Pass along REST API information |
41
|
10
|
100
|
66
|
|
|
51
|
if ( |
42
|
|
|
|
|
|
|
$self->does($restApiRole) |
43
|
|
|
|
|
|
|
&& $class->does($restApiRole) |
44
|
|
|
|
|
|
|
) { |
45
|
2
|
|
33
|
|
|
1121
|
$params->{apiHostname} //= $self->apiHostname(); |
46
|
2
|
|
33
|
|
|
72
|
$params->{apiUseHttps} //= $self->apiUseHttps(); |
47
|
2
|
|
33
|
|
|
95
|
$params->{apiVersion} //= $self->apiVersion(); |
48
|
2
|
|
33
|
|
|
69
|
$params->{lastApiError} //= $self->lastApiError(); |
49
|
2
|
|
33
|
|
|
81
|
$params->{token} //= $self->token(); |
50
|
2
|
|
33
|
|
|
71
|
$params->{timeout} //= $self->timeout(); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
10
|
50
|
|
|
|
1484
|
if ($self->_testModeIdentifier()) { |
54
|
10
|
|
|
|
|
304
|
$params->{_testModeIdentifier} = $self->_testModeIdentifier(); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# Use ourself as the callback object |
58
|
10
|
|
|
|
|
19
|
$params->{callbackObject} = $self; |
59
|
|
|
|
|
|
|
|
60
|
10
|
|
|
|
|
79
|
Module::Loader->new()->load($class); |
61
|
|
|
|
|
|
|
|
62
|
10
|
|
|
|
|
679
|
my $obj = $class->new(%$params); |
63
|
|
|
|
|
|
|
|
64
|
10
|
50
|
|
|
|
32
|
die "Failed to instantiate object ($class): " . Dumper($params) unless defined $obj; |
65
|
|
|
|
|
|
|
|
66
|
10
|
|
|
|
|
62
|
return $obj; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub loadPlaceFromApiResponseData { |
70
|
1
|
|
|
1
|
0
|
2
|
my ($self, $placeData) = @_; |
71
|
|
|
|
|
|
|
|
72
|
1
|
|
|
|
|
2
|
my $initData = {}; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# Non-Boolean Attributes |
75
|
1
|
|
|
|
|
3
|
foreach my $attribute (qw{ |
76
|
|
|
|
|
|
|
id |
77
|
|
|
|
|
|
|
accountId |
78
|
|
|
|
|
|
|
label |
79
|
|
|
|
|
|
|
fullAddress |
80
|
|
|
|
|
|
|
address |
81
|
|
|
|
|
|
|
sensorIds |
82
|
|
|
|
|
|
|
nestAdjustments |
83
|
|
|
|
|
|
|
rapidResponseSupport |
84
|
|
|
|
|
|
|
}) { |
85
|
8
|
|
|
|
|
15
|
$initData->{$attribute} = $placeData->{$attribute}; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# Boolean Attributes |
89
|
1
|
|
|
|
|
5
|
foreach my $attribute (qw{ |
90
|
|
|
|
|
|
|
suspended |
91
|
|
|
|
|
|
|
buzzerEnabled |
92
|
|
|
|
|
|
|
nestEnabled |
93
|
|
|
|
|
|
|
}) { |
94
|
3
|
100
|
|
|
|
47
|
$initData->{$attribute} = $placeData->{$attribute} ? 1 : 0; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
1
|
|
|
|
|
9
|
return $self->instantiateObject('Device::WallyHome::Place', $initData); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub loadSensorFromApiResponseData { |
101
|
1
|
|
|
1
|
0
|
2
|
my ($self, $sensorData) = @_; |
102
|
|
|
|
|
|
|
|
103
|
1
|
|
|
|
|
1
|
my $initData = {}; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
# Non-Boolean Attributes |
106
|
1
|
|
|
|
|
3
|
foreach my $attribute (qw{ |
107
|
|
|
|
|
|
|
snid |
108
|
|
|
|
|
|
|
paired |
109
|
|
|
|
|
|
|
updated |
110
|
|
|
|
|
|
|
signalStrength |
111
|
|
|
|
|
|
|
recentSignalStrength |
112
|
|
|
|
|
|
|
hardwareType |
113
|
|
|
|
|
|
|
activities |
114
|
|
|
|
|
|
|
}) { |
115
|
7
|
|
|
|
|
12
|
$initData->{$attribute} = $sensorData->{$attribute}; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# Boolean Attributes |
119
|
1
|
|
|
|
|
3
|
foreach my $attribute (qw{ |
120
|
|
|
|
|
|
|
offline |
121
|
|
|
|
|
|
|
suspended |
122
|
|
|
|
|
|
|
alarmed |
123
|
|
|
|
|
|
|
}) { |
124
|
3
|
50
|
|
|
|
31
|
$initData->{$attribute} = $sensorData->{$attribute} ? 1 : 0; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
1
|
|
|
|
|
7
|
$initData->{location} = $self->instantiateObject('Device::WallyHome::Sensor::Location', $sensorData->{location}); |
128
|
|
|
|
|
|
|
|
129
|
1
|
|
|
|
|
4
|
$initData->{thresholdsByName} = {}; |
130
|
|
|
|
|
|
|
|
131
|
1
|
|
50
|
|
|
2
|
foreach my $thresholdDataKey (keys %{ $sensorData->{thresholds} // {} }) { |
|
1
|
|
|
|
|
7
|
|
132
|
2
|
|
|
|
|
4
|
my $thresholdHref = $sensorData->{thresholds}->{$thresholdDataKey}; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
my $thresholdData = { |
135
|
|
|
|
|
|
|
max => $thresholdHref->{max}, |
136
|
|
|
|
|
|
|
min => $thresholdHref->{min}, |
137
|
2
|
|
|
|
|
8
|
name => $thresholdDataKey, |
138
|
|
|
|
|
|
|
}; |
139
|
|
|
|
|
|
|
|
140
|
2
|
|
|
|
|
8
|
$initData->{thresholdsByName}->{$thresholdDataKey} = $self->instantiateObject('Device::WallyHome::Sensor::Threshold', $thresholdData); |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
1
|
|
|
|
|
3
|
$initData->{statesByName} = {}; |
144
|
|
|
|
|
|
|
|
145
|
1
|
|
50
|
|
|
3
|
foreach my $stateDataKey (keys %{ $sensorData->{state} // {} }) { |
|
1
|
|
|
|
|
8
|
|
146
|
5
|
|
|
|
|
10
|
my $stateHref = $sensorData->{state}->{$stateDataKey}; |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
my $stateData = { |
149
|
|
|
|
|
|
|
at => $stateHref->{at}, |
150
|
|
|
|
|
|
|
name => $stateDataKey, |
151
|
|
|
|
|
|
|
value => $stateHref->{value}, |
152
|
5
|
|
|
|
|
15
|
}; |
153
|
|
|
|
|
|
|
|
154
|
5
|
|
|
|
|
14
|
$initData->{statesByName}->{$stateDataKey} = $self->instantiateObject('Device::WallyHome::Sensor::State', $stateData); |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
1
|
|
|
|
|
16
|
my $sensor = $self->instantiateObject('Device::WallyHome::Sensor', $initData); |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
1; |