| 1 | 1 | ▶ | use v5.36; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | package Protocol::HAP::Bridge; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | our $VERSION = '0.1.0'; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Protocol::HAP::Accessory; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Protocol::HAP::Service; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Protocol::HAP::Characteristic; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | our @ISA = qw(Protocol::HAP::Accessory); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 8 | ▶ | sub new ( $class, %args ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=19.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | my $self = $class->SUPER::new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | aid => 1, # The bridge is always accessory 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | name => $args{name} // 'OpenHAP Bridge', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | manufacturer => $args{manufacturer} // 'OpenBSD', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | model => $args{model} // 'OpenHAP', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | serial => $args{serial} // 'BRIDGE-001', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | firmware_revision => $args{firmware_revision} // '1.0.0', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | logger => $args{logger}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 8 | ▶ | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition60%6/10
$args{"name"} // "OpenHAP Bridge"
$args{"manufacturer"} // "OpenBSD"
$args{"model"} // "OpenHAP"
$args{"serial"} // "BRIDGE-001"
$args{"firmware_revision"} // "1.0.0"
MC/DC100%1/1
$args{"name"} // "OpenHAP Bridge"
$args{"name"}
MC/DC0%0/1
$args{"manufacturer"} // "OpenBSD"
$args{"manufacturer"}
MC/DC0%0/1
$args{"model"} // "OpenHAP"
$args{"model"}
MC/DC0%0/1
$args{"serial"} // "BRIDGE-001"
$args{"serial"}
MC/DC0%0/1
$args{"firmware_revision"} // "1.0.0"
$args{"firmware_revision"}
Truth table100%2/2
A
A= $args{"name"}
Truth table50%1/2
A
A= $args{"manufacturer"}
Truth table50%1/2
A
A= $args{"model"}
Truth table50%1/2
A
A= $args{"serial"}
Truth table50%1/2
A
A= $args{"firmware_revision"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 8 | $self->{bridged_accessories} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # The bridge accessory object itself must have the | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # ProtocolInformation service. Bridged accessories do not | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # carry it (HAP-Services.md ยง3). | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 8 | $self->_add_protocol_info_service; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 8 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 8 | ▶ | sub _add_protocol_info_service ($self) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_add_protocol_info_service: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | my $protocol = Protocol::HAP::Service->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | type => 'ProtocolInformation', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | iid => 8, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | logger => $self->{logger}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 8 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | $protocol->add_characteristic( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | Protocol::HAP::Characteristic->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | type => 'Version', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | iid => 9, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | format => 'string', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | perms => ['pr'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | logger => $self->{logger}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 8 | value => '1.1.0', | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 8 | $self->add_service($protocol); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 9 | ▶ | sub add_bridged_accessory ( $self, $accessory ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_bridged_accessory: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | $self->{logger}->debug( 'Adding bridged accessory: AID=%d, name=%s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 9 | $accessory->{aid}, $accessory->{name} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 9 | push @{ $self->{bridged_accessories} }, $accessory; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # Forward the event callbacks. Keep the device aid unchanged. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | $accessory->add_event_callback( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | ▶ | sub ( $aid, $iid ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | for my $callback ( @{ $self->{event_callbacks} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 1 | $callback->( $aid, $iid ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 9 | } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 2 | ▶ | sub get_bridged_accessories ($self) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_bridged_accessories: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 2 | return @{ $self->{bridged_accessories} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 1 | ▶ | sub get_all_accessories ($self) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_all_accessories: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 1 | return ( $self, @{ $self->{bridged_accessories} } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 3 | ▶ | sub get_accessory ( $self, $aid ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_accessory: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 3 | ▶ | return $self if $self->{aid} == $aid; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 2 | for my $acc ( @{ $self->{bridged_accessories} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 2 | ▶ | return $acc if $acc->{aid} == $aid; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | ▶ | sub to_json ($self) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_json: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 1 | my @accessories; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | # Add the bridge itself | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 1 | push @accessories, $self->SUPER::to_json(); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | # Add the bridged accessories | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 1 | for my $acc ( @{ $self->{bridged_accessories} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 1 | push @accessories, $acc->to_json; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 1 | return { accessories => \@accessories }; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||