mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-03 23:06:37 +00:00
39_alexa.pm: some preparations for automatic interaction model upload
git-svn-id: https://svn.fhem.de/fhem/trunk@15030 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
09e76a4dfe
commit
a288ac736c
@ -34,6 +34,7 @@ alexa_Initialize($)
|
|||||||
"articles prepositions ".
|
"articles prepositions ".
|
||||||
"echoRooms:textField-long ".
|
"echoRooms:textField-long ".
|
||||||
"alexaConfirmationLevel:2,1,0 alexaStatusLevel:2,1 ".
|
"alexaConfirmationLevel:2,1,0 alexaStatusLevel:2,1 ".
|
||||||
|
"skillId:textField ".
|
||||||
$readingFnAttributes;
|
$readingFnAttributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,7 +139,7 @@ alexa_Set($$@)
|
|||||||
{
|
{
|
||||||
my ($hash, $name, $cmd, @args) = @_;
|
my ($hash, $name, $cmd, @args) = @_;
|
||||||
|
|
||||||
my $list = "reload:noArg";
|
my $list = "reload:noArg skillId";
|
||||||
|
|
||||||
if( $cmd eq 'reload' ) {
|
if( $cmd eq 'reload' ) {
|
||||||
$hash->{".triggerUsed"} = 1;
|
$hash->{".triggerUsed"} = 1;
|
||||||
@ -180,17 +181,22 @@ alexa_Set($$@)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
|
} elsif( $cmd eq 'skillId' ) {
|
||||||
|
|
||||||
|
return CommandAttr(undef,"$name skillId $args[0]" );
|
||||||
}
|
}
|
||||||
|
|
||||||
return "Unknown argument $cmd, choose one of $list";
|
return "Unknown argument $cmd, choose one of $list";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
sub
|
sub
|
||||||
alexa_Get($$@)
|
alexa_Get($$@)
|
||||||
{
|
{
|
||||||
my ($hash, $name, $cmd) = @_;
|
my ($hash, $name, $cmd) = @_;
|
||||||
|
|
||||||
my $list = "customSlotTypes:noArg interactionModel:noArg";
|
my $list = "customSlotTypes:noArg interactionModel:noArg skillId:noArg";
|
||||||
|
|
||||||
if( lc($cmd) eq 'customslottypes' ) {
|
if( lc($cmd) eq 'customslottypes' ) {
|
||||||
if( $hash->{CL} ) {
|
if( $hash->{CL} ) {
|
||||||
@ -363,6 +369,7 @@ Log 1, Dumper $characteristicsOfIntent;
|
|||||||
$intents->{$intent} = 1;
|
$intents->{$intent} = 1;
|
||||||
|
|
||||||
my $slots = [];
|
my $slots = [];
|
||||||
|
my $samples2 = [];
|
||||||
push @{$slots}, { name => 'article', type => 'FHEM_article' };
|
push @{$slots}, { name => 'article', type => 'FHEM_article' };
|
||||||
push @{$slots}, { name => 'Device', type => 'FHEM_Device' } if( !$mapping->{device} );
|
push @{$slots}, { name => 'Device', type => 'FHEM_Device' } if( !$mapping->{device} );
|
||||||
push @{$slots}, { name => 'preposition', type => 'FHEM_preposition' };
|
push @{$slots}, { name => 'preposition', type => 'FHEM_preposition' };
|
||||||
@ -422,12 +429,15 @@ Log 1, Dumper $characteristicsOfIntent;
|
|||||||
$line .= " $mapping->{valueSuffix}" if( $mapping->{valueSuffix} );
|
$line .= " $mapping->{valueSuffix}" if( $mapping->{valueSuffix} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
push @{$samples2}, $line;
|
||||||
|
|
||||||
$samples .= "\n" if( $samples );
|
$samples .= "\n" if( $samples );
|
||||||
$samples .= $line;
|
$samples .= $line;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
push @{$schema->{intents}}, {intent => $intent, slots => $slots};
|
push @{$schema->{intents}}, {intent => $intent, slots => $slots};
|
||||||
|
#push @{$schema->{intents}}, {intent => $intent, slots => $slots, samples => $samples2};
|
||||||
}
|
}
|
||||||
|
|
||||||
++$i;
|
++$i;
|
||||||
@ -568,6 +578,14 @@ Log 1, Dumper $characteristicsOfIntent;
|
|||||||
"get alexa interactionmodel\n";
|
"get alexa interactionmodel\n";
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
|
} elsif( $cmd eq 'skillId' ) {
|
||||||
|
my $skillId = AttrVal($name, 'skillId', undef);
|
||||||
|
|
||||||
|
return 'no skillId set' if( !$skillId );
|
||||||
|
|
||||||
|
$skillId = plex_decrypt( $skillId );
|
||||||
|
|
||||||
|
return "skillId: $skillId";
|
||||||
}
|
}
|
||||||
|
|
||||||
return "Unknown argument $cmd, choose one of $list";
|
return "Unknown argument $cmd, choose one of $list";
|
||||||
@ -598,6 +616,41 @@ Log 1, "!!!!!!!!!!";
|
|||||||
alexa_Parse($hash, $buf, $hash->{CD}->peerhost);
|
alexa_Parse($hash, $buf, $hash->{CD}->peerhost);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub
|
||||||
|
alexa_encrypt($)
|
||||||
|
{
|
||||||
|
my ($decoded) = @_;
|
||||||
|
my $key = getUniqueId();
|
||||||
|
my $encoded;
|
||||||
|
|
||||||
|
return $decoded if( $decoded =~ /^crypt:(.*)/ );
|
||||||
|
|
||||||
|
for my $char (split //, $decoded) {
|
||||||
|
my $encode = chop($key);
|
||||||
|
$encoded .= sprintf("%.2x",ord($char)^ord($encode));
|
||||||
|
$key = $encode.$key;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'crypt:'. $encoded;
|
||||||
|
}
|
||||||
|
sub
|
||||||
|
alexa_decrypt($)
|
||||||
|
{
|
||||||
|
my ($encoded) = @_;
|
||||||
|
my $key = getUniqueId();
|
||||||
|
my $decoded;
|
||||||
|
|
||||||
|
$encoded = $1 if( $encoded =~ /^crypt:(.*)/ );
|
||||||
|
|
||||||
|
for my $char (map { pack('C', hex($_)) } ($encoded =~ /(..)/g)) {
|
||||||
|
my $decode = chop($key);
|
||||||
|
$decoded .= chr(ord($char)^ord($decode));
|
||||||
|
$key = $decode.$key;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $decoded;
|
||||||
|
}
|
||||||
|
|
||||||
sub
|
sub
|
||||||
alexa_Attr($$$)
|
alexa_Attr($$$)
|
||||||
{
|
{
|
||||||
@ -607,15 +660,33 @@ alexa_Attr($$$)
|
|||||||
|
|
||||||
my $hash = $defs{$name};
|
my $hash = $defs{$name};
|
||||||
if( $attrName eq "disable" ) {
|
if( $attrName eq "disable" ) {
|
||||||
|
} elsif( $attrName eq 'skillId' ) {
|
||||||
|
if( $cmd eq "set" && $attrVal ) {
|
||||||
|
|
||||||
|
if( $attrVal =~ /^crypt:/ ) {
|
||||||
|
return;
|
||||||
|
|
||||||
|
} elsif( $attrVal !~ /(^amzn1\.ask\.skill\.[0-9a-f\-]+)|(^amzn1\.echo-sdk-ams\.app\.[0-9a-f\-]+)/ ) {
|
||||||
|
return "$attrVal is not a valid skill id";
|
||||||
|
}
|
||||||
|
|
||||||
|
$attrVal = plex_encrypt($attrVal);
|
||||||
|
|
||||||
|
if( $orig ne $attrVal ) {
|
||||||
|
$attr{$name}{$attrName} = $attrVal;
|
||||||
|
return "stored obfuscated skillId";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if( $cmd eq 'set' ) {
|
if( $cmd eq 'set' ) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
delete $attr{$name}{$attrName};
|
delete $attr{$name}{$attrName};
|
||||||
|
|
||||||
RemoveInternalTimer($hash);
|
RemoveInternalTimer($hash);
|
||||||
InternalTimer(gettimeofday(), "alexa_AttrDefaults", $hash, 0);
|
InternalTimer(gettimeofday(), "alexa_AttrDefaults", $hash, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -656,6 +727,8 @@ alexa_Attr($$$)
|
|||||||
<li>interactionModel<br>
|
<li>interactionModel<br>
|
||||||
Get Intent Schema, non device specific Custom Slot Types and Sample Utterances for the Interaction Model
|
Get Intent Schema, non device specific Custom Slot Types and Sample Utterances for the Interaction Model
|
||||||
configuration.</li>
|
configuration.</li>
|
||||||
|
<li>skillId<br>
|
||||||
|
shows the configured skillId.</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<a name="alexa_Attr"></a>
|
<a name="alexa_Attr"></a>
|
||||||
@ -681,6 +754,9 @@ alexa_Attr($$$)
|
|||||||
</li>
|
</li>
|
||||||
<li>alexaStatusLevel<br>
|
<li>alexaStatusLevel<br>
|
||||||
</li>
|
</li>
|
||||||
|
<li>skillId<br>
|
||||||
|
skillId to use for automatic interaction model upload (not yet finished !!!)
|
||||||
|
</li>
|
||||||
Note: changes to attributes of the alexa device will automatically trigger a reconfiguration of
|
Note: changes to attributes of the alexa device will automatically trigger a reconfiguration of
|
||||||
alxea-fhem and there is no need to restart the service.
|
alxea-fhem and there is no need to restart the service.
|
||||||
</ul>
|
</ul>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user