| 1 | 2 | ▶ | use v5.36; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | package Protocol::HAP::Accessory; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | our $VERSION = '0.1.0'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Protocol::HAP; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Protocol::HAP::Service; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Protocol::HAP::Characteristic; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 25 | ▶ | sub new ( $class, %args ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=19.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | my $self = bless { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | aid => $args{aid}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | name => $args{name} // 'Accessory', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | manufacturer => $args{manufacturer} // 'OpenHAP', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | model => $args{model} // 'HAP Accessory', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | serial => $args{serial} // 'ACC-001', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | firmware_revision => $args{firmware_revision} // '1.0.0', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 25 | ▶ | logger => $args{logger} // Protocol::HAP->null_logger, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition84%11/13
$args{"name"} // "Accessory"
$args{"manufacturer"} // "OpenHAP"
$args{"model"} // "HAP Accessory"
$args{"serial"} // "ACC-001"
$args{"firmware_revision"} // "1.0.0"
$args{"logger"} // "Protocol::HAP"->null_logger
MC/DC100%1/1
$args{"name"} // "Accessory"
$args{"name"}
MC/DC100%1/1
$args{"manufacturer"} // "OpenHAP"
$args{"manufacturer"}
MC/DC100%1/1
$args{"model"} // "HAP Accessory"
$args{"model"}
MC/DC100%1/1
$args{"serial"} // "ACC-001"
$args{"serial"}
MC/DC100%1/1
$args{"firmware_revision"} // "1.0.0"
$args{"firmware_revision"}
MC/DC0%0/2
$args{"logger"} // "Protocol::HAP"->null_logger
$args{"logger"}
"Protocol::HAP"->null_logger
Truth table100%2/2
A
A= $args{"name"}
Truth table100%2/2
A
A= $args{"manufacturer"}
Truth table100%2/2
A
A= $args{"model"}
Truth table100%2/2
A
A= $args{"serial"}
Truth table100%2/2
A
A= $args{"firmware_revision"}
Truth table33%1/3
A // B
A= $args{"logger"}B= "Protocol::HAP"->null_logger
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | services => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | event_callbacks => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # Add the required Accessory Information service | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 25 | $self->_add_accessory_info_service(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 25 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 25 | ▶ | sub _add_accessory_info_service ($self) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_add_accessory_info_service: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | my $info = Protocol::HAP::Service->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | type => 'AccessoryInformation', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | iid => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | logger => $self->{logger}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 25 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # One row per characteristic: type, iid, format, perms, value. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # Identify is write-only and carries no value. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | my @rows = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | [ 'Identify', 2, 'bool', ['pw'], undef ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | [ 'Manufacturer', 3, 'string', ['pr'], $self->{manufacturer} ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | [ 'Model', 4, 'string', ['pr'], $self->{model} ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | [ 'Name', 5, 'string', ['pr'], $self->{name} ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | [ 'SerialNumber', 6, 'string', ['pr'], $self->{serial} ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 'FirmwareRevision', 7, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 'string', ['pr'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | $self->{firmware_revision} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 25 | ], | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 25 | for my $row (@rows) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 150 | my ( $type, $iid, $format, $perms, $value ) = @$row; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | $info->add_characteristic( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | Protocol::HAP::Characteristic->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | type => $type, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | iid => $iid, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | format => $format, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | perms => $perms, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | logger => $self->{logger}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 150 | value => $value, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 25 | push @{ $self->{services} }, $info; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 9 | ▶ | sub add_service ( $self, $service ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_service: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 9 | push @{ $self->{services} }, $service; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 2 | ▶ | sub get_services ($self) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_services: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 2 | return @{ $self->{services} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | sub get_service ( $self, $type ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_service: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # Look up the full UUID when the caller gives a short name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | my $target_uuid = $Protocol::HAP::Service::SERVICE_TYPES{$type} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/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 table0%0/3
A // B
A= $Protocol::HAP::Service::SERVICE_TYPES{$type}B= $type
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | // $type; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | for my $service ( @{ $self->{services} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | return $service if $service->{type} eq $target_uuid; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 1 | ▶ | sub get_characteristic ( $self, $iid ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_characteristic: called CC=3 SCAR=11.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 1 | for my $service ( @{ $self->{services} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 1 | my $char = $service->get_characteristic($iid); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 1 | ▶ | return $char if $char; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 3 | ▶ | sub to_json ($self) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_json: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 3 | my @services; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 3 | for my $service ( @{ $self->{services} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 4 | push @services, $service->to_json(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | aid => $self->{aid}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 3 | services => \@services, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 13 | ▶ | sub add_event_callback ( $self, $callback ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_event_callback: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 13 | push @{ $self->{event_callbacks} }, $callback; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 3 | ▶ | sub notify_change ( $self, $iid ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
notify_change: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | # Tell all registered callbacks about the characteristic change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 3 | for my $callback ( @{ $self->{event_callbacks} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 4 | $callback->( $self->{aid}, $iid ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||