| 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")
MC/DC0%0/1
$args{"type"} // die("Service type required")
$args{"type"}
Truth table50%1/2
A
A= $args{"type"}
| |||||||||||||||||||||||||||||||||||||||||
| 25 | 49 | ▶ | my $uuid = $SERVICE_TYPES{$type} // $type; | ||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$Protocol::HAP::Service::SERVICE_TYPES{$type} // $type
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
| |||||||||||||||||||||||||||||||||||||||||
| 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
$args{"hidden"} // 0
$args{"primary"} // 0
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
Truth table100%2/2
A
A= $args{"hidden"}
Truth table100%2/2
A
A= $args{"primary"}
| |||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||||||||||||||
| 57 | // $type; | ||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||
| 59 | 3 | for my $char ( @{ $self->{characteristics} } ) { | |||||||||||||||||||||||||||||||||||||||
| 60 | 5 | ▶ | return $char if $char->{type} eq $target_uuid; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||
| 86 | 9 | ▶ | $json->{primary} = \1 if $self->{primary}; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||
| 88 | 9 | return $json; | |||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||
| 91 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||