| 1 | |||||||||||||||||||||||||||||||||||||||||||
| 2 | # Copyright (c) 1999-2017 Rob Fugina <robf@fugina.com> | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # Distributed under the terms of the GNU Public License, Version 3.0 | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | package X10::Event; | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use vars qw(@ISA); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Storable; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | @ISA = qw(Storable); | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | sub new | ||||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | my $type = shift; | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | my $self; | |||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | if (@_ == 1) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | { | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | my ($hc, $uc, $func) = &parse_string(shift); | |||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | return undef unless ($hc && $uc && $func); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$hc and $uc and $func
$hc and $uc
MC/DC0%0/3
$hc and $uc and $func
$hc
$uc
$func
Truth table0%0/4
A and B and C
A= $hcB= $ucC= $func
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | $self = { | |||||||||||||||||||||||||||||||||||||||||
| 28 | house_code => $hc, | ||||||||||||||||||||||||||||||||||||||||||
| 29 | unit_code => $uc, | ||||||||||||||||||||||||||||||||||||||||||
| 30 | func => $func, | ||||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | bless $self, $type; | |||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | sub house_code | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
house_code: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | return $self->{house_code}; | |||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | sub unit_code | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unit_code: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | return $self->{unit_code}; | |||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | sub func | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
func: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | return $self->{func}; | |||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | sub as_string | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_string: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | if ($self->unit_code eq 'ALL' || $self->unit_code eq 'LIGHTS') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->unit_code eq "ALL" or $self->unit_code eq "LIGHTS"
MC/DC0%0/2
$self->unit_code eq "ALL" or $self->unit_code eq "LIGHTS"
$self->unit_code eq "ALL"
$self->unit_code eq "LIGHTS"
Truth table0%0/3
A or B
A= $self->unit_code eq "ALL"B= $self->unit_code eq "LIGHTS"
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | { | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | return join(' ', $self->house_code, $self->unit_code, $self->func); | |||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | else | ||||||||||||||||||||||||||||||||||||||||||
| 66 | { | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | return sprintf("%s%02s %s", $self->house_code, $self->unit_code, $self->func); | |||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | ### | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | # build a string of words that implement this event | ||||||||||||||||||||||||||||||||||||||||||
| 74 | sub compile | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile: not called CC=13 SCAR=52.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | my @words = (); | |||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | if ($self->func eq 'ON' || $self->func eq 'OFF') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$self->func eq "ON" or $self->func eq "OFF"
MC/DC0%0/2
$self->func eq "ON" or $self->func eq "OFF"
$self->func eq "ON"
$self->func eq "OFF"
Truth table0%0/3
A or B
A= $self->func eq "ON"B= $self->func eq "OFF"
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | { | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | if ($self->unit_code eq 'LIGHTS' && $self->func eq 'ON') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition0%0/3
$self->unit_code eq "LIGHTS" and $self->func eq "ON"
MC/DC0%0/2
$self->unit_code eq "LIGHTS" and $self->func eq "ON"
$self->unit_code eq "LIGHTS"
$self->func eq "ON"
Truth table0%0/3
A and B
A= $self->unit_code eq "LIGHTS"B= $self->func eq "ON"
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | { | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | push @words, sprintf("%sL1", $self->house_code); | |||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | ▶ | elsif ($self->unit_code eq 'ALL' && $self->func eq 'OFF') | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->unit_code eq "ALL" and $self->func eq "OFF"
MC/DC0%0/2
$self->unit_code eq "ALL" and $self->func eq "OFF"
$self->unit_code eq "ALL"
$self->func eq "OFF"
Truth table0%0/3
A and B
A= $self->unit_code eq "ALL"B= $self->func eq "OFF"
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | { | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | push @words, sprintf("%sA0", $self->house_code); | |||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | ▶ | elsif ($self->unit_code > 0 && $self->unit_code <= 16) | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->unit_code > 0 and $self->unit_code <= 16
MC/DC0%0/2
$self->unit_code > 0 and $self->unit_code <= 16
$self->unit_code > 0
$self->unit_code <= 16
Truth table0%0/3
A and B
A= $self->unit_code > 0B= $self->unit_code <= 16
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | { | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | push @words, | |||||||||||||||||||||||||||||||||||||||||
| 93 | sprintf("%s%02s", $self->house_code, $self->unit_code), | ||||||||||||||||||||||||||||||||||||||||||
| 94 | sprintf("%s%2s", $self->house_code, substr($self->func, 0, 2)); | ||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | else | ||||||||||||||||||||||||||||||||||||||||||
| 97 | { | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | warn sprintf "Unknown command: %s %s %s (%s)", | |||||||||||||||||||||||||||||||||||||||||
| 99 | $self->house_code, $self->unit_code, $self->func, $_; | ||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | ▶ | elsif ($self->func eq 'DIM' || $self->func eq 'BRIGHT') | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->func eq "DIM" or $self->func eq "BRIGHT"
MC/DC0%0/2
$self->func eq "DIM" or $self->func eq "BRIGHT"
$self->func eq "DIM"
$self->func eq "BRIGHT"
Truth table0%0/3
A or B
A= $self->func eq "DIM"B= $self->func eq "BRIGHT"
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | { | ||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | if ($self->unit_code > 0 && $self->unit_code <= 16) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->unit_code > 0 and $self->unit_code <= 16
MC/DC0%0/2
$self->unit_code > 0 and $self->unit_code <= 16
$self->unit_code > 0
$self->unit_code <= 16
Truth table0%0/3
A and B
A= $self->unit_code > 0B= $self->unit_code <= 16
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | { | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | push @words, | |||||||||||||||||||||||||||||||||||||||||
| 107 | sprintf("%s%02s", $self->house_code, $self->unit_code), | ||||||||||||||||||||||||||||||||||||||||||
| 108 | sprintf("%s%2s", $self->house_code, substr($self->func, 0, 2)); | ||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | else | ||||||||||||||||||||||||||||||||||||||||||
| 111 | { | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | warn sprintf "Unknown command: %s %s %s (%s)", | |||||||||||||||||||||||||||||||||||||||||
| 113 | $self->house_code, $self->unit_code, $self->func, $_; | ||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | else | ||||||||||||||||||||||||||||||||||||||||||
| 117 | { | ||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | warn sprintf "Unknown command: %s %s %s (%s)", | |||||||||||||||||||||||||||||||||||||||||
| 119 | $self->house_code, $self->unit_code, $self->func, $_; | ||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | return map {uc} @words; | |||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | ### | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | sub parse_string | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_string: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | my $string = uc(shift); | |||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | if ( $string =~ /^\s*([a-p])\s*(\d+|all|lights)\s*(on|off|dim|bright)\s*$/i ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | { | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | if ( lc($2) eq 'all' && lc($3) eq 'off' ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition0%0/3
lc $2 eq "all" and lc $3 eq "off"
MC/DC0%0/2
lc $2 eq "all" and lc $3 eq "off"
lc $2 eq "all"
lc $3 eq "off"
Truth table0%0/3
A and B
A= lc $2 eq "all"B= lc $3 eq "off"
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | { | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | return map {uc} ($1, $2, $3); | |||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||
| 138 | ▶ | elsif ( lc($2) eq 'lights' && lc($3) eq 'on' ) | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
lc $2 eq "lights" and lc $3 eq "on"
MC/DC0%0/2
lc $2 eq "lights" and lc $3 eq "on"
lc $2 eq "lights"
lc $3 eq "on"
Truth table0%0/3
A and B
A= lc $2 eq "lights"B= lc $3 eq "on"
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | { | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | return map {uc} ($1, $2, $3); | |||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | ▶ | elsif ( $2 > 0 && $2 <= 16 ) | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$2 > 0 and $2 <= 16
MC/DC0%0/2
$2 > 0 and $2 <= 16
$2 > 0
$2 <= 16
Truth table0%0/3
A and B
A= $2 > 0B= $2 <= 16
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | { | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | return (uc($1), $2 * 1, uc($3)); | |||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | else | ||||||||||||||||||||||||||||||||||||||||||
| 147 | { | ||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | return (); | |||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||
| 151 | else | ||||||||||||||||||||||||||||||||||||||||||
| 152 | { | ||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | return (); | |||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||