2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-10 09:16:53 +00:00

39_alexa.pm: preparations for local execution of fhemIntents

git-svn-id: https://svn.fhem.de/fhem/trunk@13562 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
justme-1968 2017-03-01 11:50:58 +00:00
parent ba2fd16071
commit c9ac23c1ae

View File

@ -135,6 +135,37 @@ alexa_Set($$@)
FW_directNotify($name, 'reload');
}
return undef;
} elsif( $cmd eq 'execute' ) {
my ($intent,$applicationId) = split(':', shift @args, 2 );
return 'usage $cmd execute <intent> [json]' if( !$intent );
my $json = join(' ',@args);
my $decoded = eval { decode_json($json) };
if( $@ ) {
my $msg = "json error: $@ in $json";
Log3 $name, 2, "$name: $msg";
return $msg;
}
Log3 $name, 5, "$name: \"$json\" -> ". Dumper $decoded;
my $cmd = '{Log 1, "test"; return "result";}';
Log3 $name, 5, "$name: cmd: $cmd";
if( ref($decoded->{slots}) eq 'HASH' ) {
$hash->{active} = 1;
my $intent = $intent;
$intent = "$intent:$applicationId" if( $applicationId );
readingsSingleUpdate($hash, 'fhemIntent', $intent, 1 );
my $exec = EvalSpecials($cmd, %{$decoded->{slots}});
Log3 $name, 5, "$name: exec: $exec";
my $ret = AnalyzeCommandChain($hash, $exec);
Log3 $name, 5, "$name: ret ". ($ret?$ret:"undefined");
$hash->{active} = 0;
return $ret;
}
return undef;
}