Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scene Build #255

Merged
merged 5 commits into from
Oct 8, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"})) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allows for a new sub in read_table_*.pl that is called at the completion of reading the file.

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