| 1 | package Device::WallyHome::Place; | ||
| 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 | ▶ | use List::Util qw(first); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 1 | our $VERSION = '0.21.3'; | |
| 9 | |||
| 10 | 1 | with 'Device::WallyHome::Role::Creator'; | |
| 11 | 1 | with 'Device::WallyHome::Role::REST'; | |
| 12 | 1 | with 'Device::WallyHome::Role::Validator'; | |
| 13 | |||
| 14 | |||
| 15 | #== ATTRIBUTES ================================================================= | ||
| 16 | |||
| 17 | 1 | has 'id' => ( | |
| 18 | is => 'ro', | ||
| 19 | isa => 'Str', | ||
| 20 | required => 1, | ||
| 21 | writer => '_id', | ||
| 22 | ); | ||
| 23 | |||
| 24 | 1 | has 'accountId' => ( | |
| 25 | is => 'ro', | ||
| 26 | isa => 'Str', | ||
| 27 | required => 1, | ||
| 28 | writer => '_accountId', | ||
| 29 | ); | ||
| 30 | |||
| 31 | 1 | has 'label' => ( | |
| 32 | is => 'ro', | ||
| 33 | isa => 'Maybe[Str]', | ||
| 34 | required => 1, | ||
| 35 | writer => '_label', | ||
| 36 | ); | ||
| 37 | |||
| 38 | 1 | has 'fullAddress' => ( | |
| 39 | is => 'ro', | ||
| 40 | isa => 'Maybe[HashRef]', | ||
| 41 | required => 1, | ||
| 42 | writer => '_fullAddress', | ||
| 43 | ); | ||
| 44 | |||
| 45 | 1 | has 'address' => ( | |
| 46 | is => 'ro', | ||
| 47 | isa => 'Maybe[Str]', | ||
| 48 | required => 1, | ||
| 49 | writer => '_address', | ||
| 50 | ); | ||
| 51 | |||
| 52 | 1 | has 'suspended' => ( | |
| 53 | is => 'ro', | ||
| 54 | isa => 'Int', | ||
| 55 | required => 1, | ||
| 56 | writer => '_suspended', | ||
| 57 | ); | ||
| 58 | |||
| 59 | 1 | has 'buzzerEnabled' => ( | |
| 60 | is => 'ro', | ||
| 61 | isa => 'Int', | ||
| 62 | required => 1, | ||
| 63 | writer => '_buzzerEnabled', | ||
| 64 | ); | ||
| 65 | |||
| 66 | 1 | has 'sensorIds' => ( | |
| 67 | is => 'ro', | ||
| 68 | isa => 'ArrayRef', | ||
| 69 | required => 1, | ||
| 70 | writer => '_sensorIds', | ||
| 71 | ); | ||
| 72 | |||
| 73 | 1 | has 'nestAdjustments' => ( | |
| 74 | is => 'ro', | ||
| 75 | isa => 'HashRef', | ||
| 76 | required => 1, | ||
| 77 | writer => '_nestAdjustments', | ||
| 78 | ); | ||
| 79 | |||
| 80 | 1 | has 'nestEnabled' => ( | |
| 81 | is => 'ro', | ||
| 82 | isa => 'Int', | ||
| 83 | required => 1, | ||
| 84 | writer => '_nestEnabled', | ||
| 85 | ); | ||
| 86 | |||
| 87 | 1 | has 'rapidResponseSupport' => ( | |
| 88 | is => 'ro', | ||
| 89 | isa => 'ArrayRef', | ||
| 90 | required => 1, | ||
| 91 | writer => '_rapidResponseSupport', | ||
| 92 | ); | ||
| 93 | |||
| 94 | 1 | has 'sensors' => ( | |
| 95 | is => 'lazy', | ||
| 96 | ); | ||
| 97 | |||
| 98 | |||
| 99 | #== ATTRIBUTE BUILDERS ========================================================= | ||
| 100 | |||
| 101 | 1 | ▶ | sub _build_sensors { |
|
Subroutine
_build_sensors: called CC=2 SCAR=6.9
| |||
| 102 | 1 | my ($self) = @_; | |
| 103 | |||
| 104 | 1 | my $newSensorIds = []; | |
| 105 | 1 | my $sensorObjectList = []; | |
| 106 | |||
| 107 | 1 | my $sensorList = $self->request({ | |
| 108 | uri => 'places/' . $self->id() . '/sensors' | ||
| 109 | }); | ||
| 110 | |||
| 111 | 1 | foreach my $sensorData (@$sensorList) { | |
| 112 | 1 | my $sensor = $self->loadSensorFromApiResponseData($sensorData); | |
| 113 | |||
| 114 | 1 | push @$sensorObjectList, $sensor; | |
| 115 | |||
| 116 | 1 | push @$newSensorIds, $sensor->snid(); | |
| 117 | } | ||
| 118 | |||
| 119 | 1 | $self->_sensorIds($newSensorIds); | |
| 120 | |||
| 121 | 1 | return $sensorObjectList; | |
| 122 | } | ||
| 123 | |||
| 124 | |||
| 125 | #== PUBLIC METHODS ============================================================= | ||
| 126 | |||
| 127 | 1 | ▶ | sub getSensorBySnid { |
|
Subroutine
getSensorBySnid: called CC=1 SCAR=0.0
Pod
documented
| |||
| 128 | 1 | my ($self, $snid) = @_; | |
| 129 | |||
| 130 | 1 | $self->_checkRequiredScalarParam($snid, 'snid'); | |
| 131 | |||
| 132 | 1 | ▶ | return first { $_->snid() eq $snid } @{ $self->sensors() }; |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 133 | } | ||
| 134 | |||
| 135 | |||
| 136 | 1 | __PACKAGE__->meta->make_immutable; | |
| 137 | |||
| 138 | 1 | 1; | |
| 139 | |||
| 140 | __END__ | ||