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