Skip to content

Commit

Permalink
Merge pull request #255 from pmatis/scene_simple
Browse files Browse the repository at this point in the history
Scene Build
  • Loading branch information
krkeegan committed Oct 8, 2013
2 parents 3148014 + 4423d34 commit 5aac865
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
4 changes: 4 additions & 0 deletions bin/mh
Original file line number Diff line number Diff line change
Expand Up @@ -4775,6 +4775,10 @@ sub read_table_files {
print "Error in &read_table_$format: $@\n" if $@;
}
}
if (defined(&{"read_table_finish_$format"})) {
print TABLE_OUT eval "&read_table_finish_$format()";
print "Error in &read_table_finish_$format: $@\n" if $@;
}
close TABLE_IN;
close TABLE_OUT;
if ($format =~/xml/) { $/="\n"; }
Expand Down
67 changes: 66 additions & 1 deletion lib/read_table_A.pl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#print_log "Using read_table_A.pl";

my (%groups, %objects, %packages, %addresses);
my (%groups, %objects, %packages, %addresses, %scene_build_controllers, %scene_build_responders);

sub read_table_init_A {
# reset known groups
Expand All @@ -23,6 +23,8 @@ sub read_table_init_A {
%objects=();
%packages=();
%addresses=();
%scene_build_controllers=();
%scene_build_responders=();
}

sub read_table_A {
Expand Down Expand Up @@ -992,6 +994,21 @@ sub read_table_A {
}
$object = '';
}
elsif($type eq "SCENE_BUILD") {
#SCENE_BUILD, scene_name, scene_member, is_controller?, is_responder?, onlevel, ramprate
my ($scene_member, $is_scene_controller, $is_scene_responder, $on_level, $ramp_rate);
($name, $scene_member, $is_scene_controller, $is_scene_responder, $on_level, $ramp_rate) = @item_info;
if( ! $packages{Scene}++ ) { # first time for this object type?
$code .= "use Scene;\n";
}
if ($is_scene_controller){
$scene_build_controllers{$name}{$scene_member} = "1";
}
if ($is_scene_responder){
$scene_build_responders{$name}{$scene_member} = "$on_level,$ramp_rate";
}
$object = '';
}
elsif ($type eq "PHILIPS_HUE"){
($address, $name, $grouplist, @other) = @item_info;
$other = join ', ', (map {"'$_'"} @other); # Quote data
Expand Down Expand Up @@ -1047,6 +1064,54 @@ sub read_table_A {
return $code;
}

sub read_table_finish_A {
my $code = '';
#a scene cannot exist without a responder, but it could lack a controller if
#scene is a PLM Scene
foreach my $scene (sort keys %scene_build_responders) {
$code .= "\n#SCENE_BUILD Definition for scene: $scene\n";

#Doesn't work because object technically doesn't exist yet. Is it even
#necessary to limit to ICONTROLLER's?
#my $object = &get_object_by_name($scene);
#if(defined($object) and $object->isa("Insteon::InterfaceController")) {

if($objects{$scene}) {
#Since an INSTEON_ICONTROLLER exists with the same name as the scene,
#make it a controller of the scene, too.
$scene_build_controllers{$scene}{$scene}="1";
}

#Loop through the controller hash
foreach my $scene_controller (keys $scene_build_controllers{$scene}) {
if ($objects{$scene_controller}) {
#Make a link to each responder in the responder hash
while (my ($scene_responder, $responder_data) = each($scene_build_responders{$scene})) {
my ($on_level, $ramp_rate) = split(',', $responder_data);

if (($objects{$scene_responder}) and ($scene_responder ne $scene_controller)) {
if ($on_level) {
if ($ramp_rate) {
$code .= sprintf "\$%-35s -> add(\$%s,'%s','%s');\n",
$scene_controller, $scene_responder, $on_level, $ramp_rate;
} else {
$code .= sprintf "\$%-35s -> add(\$%s,'%s');\n",
$scene_controller, $scene_responder, $on_level;
}
} else {
$code .= sprintf "\$%-35s -> add(\$%s);\n", $scene_controller, $scene_responder;
}
}
}

} else {
print "\nThere is no object called $scene_controller defined. Ignoring SCENE_BUILD entry.\n";
}
}
}
return $code;
}

1;

#
Expand Down

0 comments on commit 5aac865

Please sign in to comment.