blib/lib/Protocol/HAP/Service.pm

filter: Statementstmt 100% 36 / 36 Branchbran 87.5% 7 / 8 Conditioncond 66.6% 10 / 15 MC/DCmcdc 22.2% 2 / 9 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 6 totaltotal 77.1% 64 / 83 CC 14 SCAR 13.4
CC
14
Cov
90%
new
6.2
get_characteristic_by_type
4.1
to_json
4.0
CRAP 3.8
« blib/lib/Protocol/HAP/SRP.pm ↑ Summary blib/lib/Protocol/HAP/Bridge.pm »
1 3 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package Protocol::HAP::Service;
4 3 our $VERSION = '0.1.0';
5  
6 3 ▶use Protocol::HAP;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Protocol::HAP::Characteristic;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 # HAP Service Type UUIDs
10 3 our %SERVICE_TYPES = (
11 'AccessoryInformation' => '0000003E-0000-1000-8000-0026BB765291',
12 'ProtocolInformation' => '000000A2-0000-1000-8000-0026BB765291',
13 'Thermostat' => '0000004A-0000-1000-8000-0026BB765291',
14 'Switch' => '00000049-0000-1000-8000-0026BB765291',
15 'TemperatureSensor' => '0000008A-0000-1000-8000-0026BB765291',
16 'HumiditySensor' => '00000082-0000-1000-8000-0026BB765291',
17 'Outlet' => '00000047-0000-1000-8000-0026BB765291',
18 'Lightbulb' => '00000043-0000-1000-8000-0026BB765291',
19 );
20  
21 49 ▶sub new ( $class, %args )
Subroutine new: called CC=6 SCAR=18.3
Pod undocumented
22 {
23  
24 49 ▶ my $type = $args{type} // die "Service type required";
Condition50%1/2
$args{"type"} // die("Service type required")
l!l
490
MC/DC0%0/1
$args{"type"} // die("Service type required")
$args{"type"}
Truth table50%1/2
A
A= $args{"type"}
Aresult
11
00
25 49 ▶ my $uuid = $SERVICE_TYPES{$type} // $type;
Condition66%2/3
$Protocol::HAP::Service::SERVICE_TYPES{$type} // $type
l!l&&r!l&&!r
4720
MC/DC0%0/2
$Protocol::HAP::Service::SERVICE_TYPES{$type} // $type
$Protocol::HAP::Service::SERVICE_TYPES{$type} $type
Truth table66%2/3
A // B
A= $Protocol::HAP::Service::SERVICE_TYPES{$type}B= $type
ABresult
1X1
011
000
26  
27 my $self = bless {
28 type => $uuid,
29 iid => $args{iid},
30 logger => $args{logger} // Protocol::HAP->null_logger,
31 characteristics => [],
32 hidden => $args{hidden} // 0,
33 49 ▶ primary => $args{primary} // 0,
Condition85%6/7
$args{"logger"} // "Protocol::HAP"->null_logger
l!l&&r!l&&!r
33160
$args{"hidden"} // 0
l!l
148
$args{"primary"} // 0
l!l
148
MC/DC0%0/2
$args{"logger"} // "Protocol::HAP"->null_logger
$args{"logger"} "Protocol::HAP"->null_logger
MC/DC100%1/1
$args{"hidden"} // 0
$args{"hidden"}
MC/DC100%1/1
$args{"primary"} // 0
$args{"primary"}
Truth table66%2/3
A // B
A= $args{"logger"}B= "Protocol::HAP"->null_logger
ABresult
1X1
011
000
Truth table100%2/2
A
A= $args{"hidden"}
Aresult
11
00
Truth table100%2/2
A
A= $args{"primary"}
Aresult
11
00
34 }, $class;
35  
36 49 return $self;
37 }
38  
39 164 ▶sub add_characteristic ( $self, $characteristic )
Subroutine add_characteristic: called CC=1 SCAR=0.0
Pod undocumented
40 {
41 164 push @{ $self->{characteristics} }, $characteristic;
42 }
43  
44 3 ▶sub get_characteristic ( $self, $iid )
Subroutine get_characteristic: called CC=3 SCAR=11.0
Pod undocumented
45 {
46  
47 3 for my $char ( @{ $self->{characteristics} } ) {
48 4 ▶ return $char if $char->{iid} == $iid;
Branch: 1 branch
BranchTrueFalseTotal
if $char->{"iid"} == $iid 2 2 4
49 }
50  
51 1 return;
52 }
53  
54 3 ▶sub get_characteristic_by_type ( $self, $type )
Subroutine get_characteristic_by_type: called CC=4 SCAR=14.2
Pod undocumented
55 {
56 3 ▶ my $target_uuid = $Protocol::HAP::Characteristic::CHAR_TYPES{$type}
Condition33%1/3
$Protocol::HAP::Characteristic::CHAR_TYPES{$type} // $type
l!l&&r!l&&!r
300
MC/DC0%0/2
$Protocol::HAP::Characteristic::CHAR_TYPES{$type} // $type
$Protocol::HAP::Characteristic::CHAR_TYPES{$type} $type
Truth table33%1/3
A // B
A= $Protocol::HAP::Characteristic::CHAR_TYPES{$type}B= $type
ABresult
1X1
011
000
57 // $type;
58  
59 3 for my $char ( @{ $self->{characteristics} } ) {
60 5 ▶ return $char if $char->{type} eq $target_uuid;
Branch: 1 branch
BranchTrueFalseTotal
if $char->{"type"} eq $target_uuid 2 3 5
61 }
62  
63 1 return;
64 }
65  
66 1 ▶sub get_characteristics ($self)
Subroutine get_characteristics: called CC=1 SCAR=0.0
Pod undocumented
67 {
68 1 return @{ $self->{characteristics} };
69 }
70  
71 9 ▶sub to_json ($self)
Subroutine to_json: called CC=4 SCAR=13.9
Pod undocumented
72 {
73  
74 9 my @chars;
75 9 for my $char ( @{ $self->{characteristics} } ) {
76 20 push @chars, $char->to_json();
77 }
78  
79 my $json = {
80 type => Protocol::HAP::uuid_to_short( $self->{type} ),
81 iid => $self->{iid},
82 9 characteristics => \@chars,
83 };
84  
85 9 ▶ $json->{hidden} = \1 if $self->{hidden};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"hidden"} 0 9 9
86 9 ▶ $json->{primary} = \1 if $self->{primary};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"primary"} 1 8 9
87  
88 9 return $json;
89 }
90  
91 3 1;
« blib/lib/Protocol/HAP/SRP.pm ↑ Summary blib/lib/Protocol/HAP/Bridge.pm »