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