Skip to content

Commit

Permalink
Merge pull request #599 from hplato/ia7
Browse files Browse the repository at this point in the history
Ia7 v1.2.301
  • Loading branch information
hplato authored Jul 10, 2016
2 parents 29e0fc5 + 3900acd commit d272213
Show file tree
Hide file tree
Showing 29 changed files with 2,052 additions and 441 deletions.
51 changes: 51 additions & 0 deletions code/common/ia7_collection_upgrader.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Category = IA7

#@ IA7 v1.2 : This is a helper utility that can find and update collections.json files
#@ if any structural changes are required.
#@
#@ v1.2 - add in new login system id 700

my $ia7_coll_current_ver = 1.2;

if ($Startup) {

my @collection_files = ("$Pgm_Root/data/web/collections.json",
"$config_parms{data_dir}/web/collections.json",
"$config_parms{ia7_data_dir}/collections.json");
for my $file (@collection_files) {
if (-e $file) {
print_log "[IA7_Collection_Updater] : Checking $file to current version $ia7_coll_current_ver";
my $json_data;
my $file_data;
eval {
$file_data = file_read($file);
$json_data = decode_json($file_data); #HP, wrap this in eval to prevent MH crashes
};

if ($@) {
print_log "[IA7_Collection_Updater] : WARNING: decode_json failed for $file. Please check this file!";
} else {
my $updated = 0;

if ((! defined $json_data->{meta}->{version}) or ($json_data->{meta}->{version} < 1.2)) { #IA7 v1.2 required change
$json_data->{700}->{user} = '$Authorized' unless (defined $json_data->{700}->{user});
my $found = 0;
foreach my $i (@{$json_data->{500}->{children}}) {
$found = 1 if ($i == 700);
}
push (@{$json_data->{500}->{children}},700) unless ($found);
$json_data->{meta}->{version} = "1.2";
print_log "[IA7_Collection_Updater] : Checking $file to version $ia7_coll_current_ver";
$updated = 1;
}
if ($updated) {
my $json_newdata = to_json($json_data, {utf8 => 1, pretty => 1});
my $backup_file = $file . ".v" . $version . ".backup";
file_write($backup_file,$file_data);
print_log "[IA7_Collection_Updater] : Saved backup " . $file . ".v" . $version . ".backup";
file_write($file,$json_newdata);
}
}
}
}
}
45 changes: 45 additions & 0 deletions code/common/ia7_notifications.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Category = IA7

#@ IA7 v1.1 : Enables speech notifications to browsers.
#@ also includes some sample code of how to use other notifications

if ($Startup or $Reload) {
if (! defined $Info{IPAddress_local}) {
print_log "json_server.pl: \$Info{IPAddress_local} not defined. Json speech disabled";
} else {
print_log "IA7 Speech Notifications enabled";
&Speak_parms_add_hook(\&json_speech_enable);
}
}

$v_ia7_test_sound = new Voice_Cmd ("Test playing a sound");
$v_ia7_test_banner = new Voice_Cmd("Test [blue,green,yellow,red] Banner Notification");

if (my $said = said $v_ia7_test_banner) {
my %data;
$data{text} = "This is a test of the IA7 notification";
$data{color} = $said;
&json_notification("banner",{%data});
}

if (said $v_ia7_test_sound) {
my %data;
$data{url} = "http://" . $Info{IPAddress_local} . ":" . $config_parms{http_port} . "/misc/tellme_welcome.wav";
&json_notification("sound",{%data});
}

sub json_speech_enable {
my ($parms) = @_;
push @{$parms->{web_hook}},\&file_ready_for_ia7;
}

sub file_ready_for_ia7 {
my (%parms) = @_;
my %data;
$data{mode} = $parms{mode};
$data{url} = "http://" . $Info{IPAddress_local} . ":" . $config_parms{http_port} . "/" . $parms{web_file};
$data{text} = $parms{raw_text};
$data{client} = $parms{requestor};
&json_notification("speech",{%data});
}

13 changes: 7 additions & 6 deletions data/web/collections.json
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@
"28" : {
"link" : "/bin/set_parm_tv_provider.pl",
"name" : "Setup TV Provider",
"mode" : "advanced",
"icon" : "fa-desktop"
},
"5" : {
Expand Down Expand Up @@ -487,6 +488,7 @@
"26" : {
"link" : "/ia5/house/irman.shtml",
"name" : "Program IRMAN",
"mode" : "advanced",
"icon" : "fa-rss"
},
"57" : {
Expand Down Expand Up @@ -707,6 +709,7 @@
"27" : {
"icon" : "fa-wrench",
"name" : "Header Control",
"mode" : "advanced",
"link" : "/bin/headercontrol.pl"
},
"78" : {
Expand All @@ -717,7 +720,7 @@
"102" : {
"name" : "Picture Frame",
"icon" : "fa-desktop",
"external" : "http://home.krkeegan.com:8081/misc/photos.shtml"
"external" : "$config_parms{html_dir}/misc/photos.shtml"
},
"105" : {
"link" : "/ia5/calendar/main.shtml",
Expand Down Expand Up @@ -772,14 +775,12 @@
"icon" : "fa-home",
"name" : "Gear Settings",
"children" : [
501
700

]
},
"501" : {
"link" : "/UNSET_PASSWORD?user=admin",
"name" : "Authorize",
"icon" : "fa-lock"
"700" : {
"user" : "$Authorized"
},
"600" : {
"link" : "/ia7/#path=/objects&parents=ia7_status_items",
Expand Down
4 changes: 3 additions & 1 deletion data/web/ia7_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"fp_icon_size" : "32",
"fp_state_popovers" : "yes",
"substate_percentages" : "20",
"disable_current_state" : "yes"
"disable_current_state" : "yes",
"notifications" : "yes",
"speech_default" : "banner"
},
"objects" : {
"example_object" : {
Expand Down
5 changes: 4 additions & 1 deletion lib/ajax.pm
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ sub checkForUpdate {
&main::print_log("checkForUpdate sub ${$$self{sub}} returned $xml")
if $main::Debug{ajax};
&::print_socket_fork( ${ $$self{waitingSocket} }, $xml );
${ $$self{waitingSocket} }->close;
&main::print_log( "Closing Socket " . ${ $$self{waitingSocket} } )
if $main::Debug{ajax};
${ $$self{waitingSocket} }->shutdown(2)
; #Changed this from close() to shutdown(2). In some cases, the parent port wasn't being closed -- ie. speech events
${ $$self{changed} } = 1;
}
else {
Expand Down
Loading

0 comments on commit d272213

Please sign in to comment.