| 1 | package Device::WallyHome::Sensor; | ||||||||||||
| 2 | 1 | ▶ | use Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 1 | ▶ | use MooseX::AttributeShortcuts; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 1 | ▶ | use namespace::autoclean; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | 1 | our $VERSION = '0.21.3'; | |||||||||||
| 7 | |||||||||||||
| 8 | 1 | with 'Device::WallyHome::Role::Creator'; | |||||||||||
| 9 | 1 | with 'Device::WallyHome::Role::REST'; | |||||||||||
| 10 | 1 | with 'Device::WallyHome::Role::Validator'; | |||||||||||
| 11 | |||||||||||||
| 12 | |||||||||||||
| 13 | #== ATTRIBUTES ================================================================= | ||||||||||||
| 14 | |||||||||||||
| 15 | 1 | has 'snid' => ( | |||||||||||
| 16 | is => 'ro', | ||||||||||||
| 17 | isa => 'Str', | ||||||||||||
| 18 | required => 1, | ||||||||||||
| 19 | writer => '_snid', | ||||||||||||
| 20 | ); | ||||||||||||
| 21 | |||||||||||||
| 22 | 1 | has 'offline' => ( | |||||||||||
| 23 | is => 'ro', | ||||||||||||
| 24 | isa => 'Int', | ||||||||||||
| 25 | required => 1, | ||||||||||||
| 26 | writer => '_offline', | ||||||||||||
| 27 | ); | ||||||||||||
| 28 | |||||||||||||
| 29 | 1 | has 'paired' => ( | |||||||||||
| 30 | is => 'ro', | ||||||||||||
| 31 | isa => 'Str', | ||||||||||||
| 32 | required => 1, | ||||||||||||
| 33 | writer => '_paired', | ||||||||||||
| 34 | ); | ||||||||||||
| 35 | |||||||||||||
| 36 | 1 | has 'updated' => ( | |||||||||||
| 37 | is => 'ro', | ||||||||||||
| 38 | isa => 'Str', | ||||||||||||
| 39 | required => 1, | ||||||||||||
| 40 | writer => '_updated', | ||||||||||||
| 41 | ); | ||||||||||||
| 42 | |||||||||||||
| 43 | 1 | has 'alarmed' => ( | |||||||||||
| 44 | is => 'ro', | ||||||||||||
| 45 | isa => 'Str', | ||||||||||||
| 46 | required => 1, | ||||||||||||
| 47 | writer => '_alarmed', | ||||||||||||
| 48 | ); | ||||||||||||
| 49 | |||||||||||||
| 50 | 1 | has 'signalStrength' => ( | |||||||||||
| 51 | is => 'ro', | ||||||||||||
| 52 | isa => 'Num', | ||||||||||||
| 53 | required => 1, | ||||||||||||
| 54 | writer => '_signalStrength', | ||||||||||||
| 55 | ); | ||||||||||||
| 56 | |||||||||||||
| 57 | 1 | has 'recentSignalStrength' => ( | |||||||||||
| 58 | is => 'ro', | ||||||||||||
| 59 | isa => 'Num', | ||||||||||||
| 60 | required => 1, | ||||||||||||
| 61 | writer => '_recentSignalStrength', | ||||||||||||
| 62 | ); | ||||||||||||
| 63 | |||||||||||||
| 64 | 1 | has 'hardwareType' => ( | |||||||||||
| 65 | is => 'ro', | ||||||||||||
| 66 | isa => 'Str', | ||||||||||||
| 67 | required => 1, | ||||||||||||
| 68 | writer => '_hardwareType', | ||||||||||||
| 69 | ); | ||||||||||||
| 70 | |||||||||||||
| 71 | 1 | has 'location' => ( | |||||||||||
| 72 | is => 'ro', | ||||||||||||
| 73 | isa => 'Device::WallyHome::Sensor::Location', | ||||||||||||
| 74 | required => 1, | ||||||||||||
| 75 | writer => '_location', | ||||||||||||
| 76 | ); | ||||||||||||
| 77 | |||||||||||||
| 78 | 1 | has 'thresholds' => ( | |||||||||||
| 79 | is => 'lazy', | ||||||||||||
| 80 | ); | ||||||||||||
| 81 | |||||||||||||
| 82 | 1 | has 'thresholdsByName' => ( | |||||||||||
| 83 | is => 'ro', | ||||||||||||
| 84 | isa => 'HashRef[Device::WallyHome::Sensor::Threshold]', | ||||||||||||
| 85 | required => 1, | ||||||||||||
| 86 | writer => '_thresholds', | ||||||||||||
| 87 | ); | ||||||||||||
| 88 | |||||||||||||
| 89 | 1 | has 'states' => ( | |||||||||||
| 90 | is => 'lazy', | ||||||||||||
| 91 | ); | ||||||||||||
| 92 | |||||||||||||
| 93 | 1 | has 'statesByName' => ( | |||||||||||
| 94 | is => 'ro', | ||||||||||||
| 95 | isa => 'HashRef[Device::WallyHome::Sensor::State]', | ||||||||||||
| 96 | required => 1, | ||||||||||||
| 97 | writer => '_state', | ||||||||||||
| 98 | ); | ||||||||||||
| 99 | |||||||||||||
| 100 | 1 | has 'activities' => ( | |||||||||||
| 101 | is => 'ro', | ||||||||||||
| 102 | isa => 'ArrayRef', | ||||||||||||
| 103 | required => 1, | ||||||||||||
| 104 | writer => '_activities', | ||||||||||||
| 105 | ); | ||||||||||||
| 106 | |||||||||||||
| 107 | |||||||||||||
| 108 | #== ATTRIBUTE BUILDERS ========================================================= | ||||||||||||
| 109 | |||||||||||||
| 110 | 1 | ▶ | sub _build_thresholds { | ||||||||||
|
Subroutine
_build_thresholds: called CC=1 SCAR=0.0
| |||||||||||||
| 111 | 1 | my ($self) = @_; | |||||||||||
| 112 | |||||||||||||
| 113 | 1 | return [map { $self->thresholdsByName()->{$_} } sort keys %{ $self->thresholdsByName() }]; | |||||||||||
| 114 | } | ||||||||||||
| 115 | |||||||||||||
| 116 | 1 | ▶ | sub _build_states { | ||||||||||
|
Subroutine
_build_states: called CC=1 SCAR=0.0
| |||||||||||||
| 117 | 1 | my ($self) = @_; | |||||||||||
| 118 | |||||||||||||
| 119 | 1 | return [map { $self->statesByName()->{$_} } sort keys %{ $self->statesByName() }]; | |||||||||||
| 120 | } | ||||||||||||
| 121 | |||||||||||||
| 122 | #== PUBLIC METHODS ============================================================= | ||||||||||||
| 123 | |||||||||||||
| 124 | 1 | ▶ | sub threshold { | ||||||||||
|
Subroutine
threshold: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||
| 125 | 1 | my ($self, $name) = @_; | |||||||||||
| 126 | |||||||||||||
| 127 | 1 | $self->_checkRequiredScalarParam($name, 'name'); | |||||||||||
| 128 | |||||||||||||
| 129 | 1 | ▶ | return $self->thresholdsByName->{$name} // undef; | ||||||||||
|
Condition50%1/2
$self->thresholdsByName->{$name} // undef
MC/DC0%0/1
$self->thresholdsByName->{$name} // undef
$self->thresholdsByName->{$name}
Truth table50%1/2
A
A= $self->thresholdsByName->{$name}
| |||||||||||||
| 130 | } | ||||||||||||
| 131 | |||||||||||||
| 132 | 1 | ▶ | sub state { | ||||||||||
|
Subroutine
state: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||
| 133 | 1 | my ($self, $name) = @_; | |||||||||||
| 134 | |||||||||||||
| 135 | 1 | $self->_checkRequiredScalarParam($name, 'name'); | |||||||||||
| 136 | |||||||||||||
| 137 | 1 | ▶ | return $self->statesByName->{$name} // undef; | ||||||||||
|
Condition50%1/2
$self->statesByName->{$name} // undef
MC/DC0%0/1
$self->statesByName->{$name} // undef
$self->statesByName->{$name}
Truth table50%1/2
A
A= $self->statesByName->{$name}
| |||||||||||||
| 138 | } | ||||||||||||
| 139 | |||||||||||||
| 140 | |||||||||||||
| 141 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||
| 142 | |||||||||||||
| 143 | 1 | 1; | |||||||||||
| 144 | |||||||||||||
| 145 | __END__ | ||||||||||||