Umstellung auf NonblockingGet in allen Routinen, Code wurde aufgeräumt
This commit is contained in:
parent
d317b6e33a
commit
b834a03229
58
98_AMAD.pm
58
98_AMAD.pm
@ -57,6 +57,7 @@ sub AMAD_Define($$) {
|
||||
InternalTimer(gettimeofday()+$hash->{INTERVAL}, "AMAD_GetUpdateTimer", $hash, 0);
|
||||
|
||||
$hash->{STATE} = "active";
|
||||
readingsSingleUpdate ($hash,"deviceState","online",0);
|
||||
|
||||
return undef;
|
||||
}
|
||||
@ -70,10 +71,8 @@ sub AMAD_Undef($$) {
|
||||
}
|
||||
|
||||
sub AMAD_Attr(@) {
|
||||
# my ( $cmd, $name, $attrName, $attrVal) = @_; # alt
|
||||
my ( $cmd, $hash, $attrName, $attrVal) = @_;
|
||||
# my $hash = $defs{$name}; # alt
|
||||
my $name = $hash->{NAME};
|
||||
my ( $cmd, $name, $attrName, $attrVal) = @_;
|
||||
my $hash = $defs{$name};
|
||||
|
||||
if ($attrName eq "disable") {
|
||||
if($cmd eq "set") {
|
||||
@ -109,7 +108,8 @@ sub AMAD_GetUpdateLocal($)
|
||||
my ($hash) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
AMAD_RetrieveAutomagicInfo($name, 1);
|
||||
|
||||
AMAD_RetrieveAutomagicInfo($hash);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -119,7 +119,7 @@ sub AMAD_GetUpdateTimer($)
|
||||
my ($hash) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
AMAD_RetrieveAutomagicInfo($hash, 0) if ($hash->{STATE} eq "online" || $hash->{STATE} eq "active");
|
||||
AMAD_RetrieveAutomagicInfo($hash) if (ReadingsVal($name,"deviceState","online") eq "online" && $hash->{STATE} eq "active");
|
||||
|
||||
InternalTimer(gettimeofday()+$hash->{INTERVAL}, "AMAD_GetUpdateTimer", $hash, 1);
|
||||
Log3 $name, 3, "AMAD ($name) - Call AMAD_GetUpdateTimer";
|
||||
@ -134,6 +134,7 @@ sub AMAD_Set($$@)
|
||||
my $list = "screenMsg"
|
||||
. " ttsMsg"
|
||||
. " setVolume"
|
||||
. " deviceState:online,offline"
|
||||
. " mediaPlayer:play,stop,next,back";
|
||||
|
||||
|
||||
@ -144,47 +145,40 @@ sub AMAD_Set($$@)
|
||||
Log3 $name, 3, "AMAD ($name) - set $name $cmd ".join(" ", @val);
|
||||
return AMAD_SetScreenMsg ($hash, @val);
|
||||
}
|
||||
elsif ( lc $cmd eq 'devicestate') {
|
||||
Log3 $name, 3, "AMAD ($name) - set $name $cmd ".join(" ", @val);
|
||||
my $v = join(" ", @val);
|
||||
|
||||
readingsSingleUpdate ($hash,$cmd,$v,1);
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
return "Unknown argument $cmd or wrong parameter(s), choose one of $list";
|
||||
}
|
||||
|
||||
sub AMAD_RetrieveAutomagicInfo
|
||||
sub AMAD_RetrieveAutomagicInfo($)
|
||||
{
|
||||
# my ($name, $blocking) = @_;
|
||||
my ($hash, $blocking) = @_;
|
||||
# my $hash = $defs{$name};
|
||||
my ($hash) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
my $host = $hash->{HOST};
|
||||
my $port = $hash->{PORT};
|
||||
|
||||
my $url = "http://" . $host . ":" . $port . "/automagic/deviceInfo";
|
||||
|
||||
if ($blocking) {
|
||||
my $response = HttpUtils_BlockingGet(
|
||||
{
|
||||
url => $url,
|
||||
timeout => 5,
|
||||
#noshutdown => 0,
|
||||
}
|
||||
);
|
||||
my %param = (hash => $hash, doTrigger => 0);
|
||||
AMAD_RetrieveAutomagicInfoFinished(\%param, undef, $response);
|
||||
Log3 $name, 3, "AMAD ($name) - BlockingGet get URL ";
|
||||
}
|
||||
else {
|
||||
HttpUtils_NonblockingGet(
|
||||
{
|
||||
url => $url,
|
||||
timeout => 5,
|
||||
#noshutdown => 0,
|
||||
hash => $hash,
|
||||
method => "GET",
|
||||
doTrigger => 1,
|
||||
callback => \&AMAD_RetrieveAutomagicInfoFinished,
|
||||
}
|
||||
);
|
||||
Log3 $name, 3, "AMAD ($name) - NonblockingGet get URL";
|
||||
}
|
||||
}
|
||||
|
||||
sub AMAD_RetrieveAutomagicInfoFinished($$$)
|
||||
{
|
||||
@ -230,21 +224,25 @@ sub AMAD_RetrieveAutomagicInfoFinished($$$)
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub AMAD_HTTP_Request {
|
||||
sub AMAD_HTTP_POST($$)
|
||||
{
|
||||
my ($hash, $url) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
my $state = $hash->{STATE};
|
||||
|
||||
$hash->{STATE} = "Send http Request";
|
||||
HttpUtils_BlockingGet(
|
||||
$hash->{STATE} = "Send HTTP POST";
|
||||
|
||||
HttpUtils_NonblockingGet(
|
||||
{
|
||||
url => $url,
|
||||
timeout => 5,
|
||||
#noshutdown => 0,
|
||||
method => "POST",
|
||||
doTrigger => 1,
|
||||
}
|
||||
);
|
||||
Log3 $name, 3, "AMAD ($name) - Send http Request with URL $url";
|
||||
Log3 $name, 3, "AMAD ($name) - Send HTTP POST with URL $url";
|
||||
|
||||
$hash->{STATE} = $state;
|
||||
|
||||
@ -263,7 +261,7 @@ sub AMAD_SetScreenMsg($@)
|
||||
|
||||
my $url = "http://" . $host . ":" . $port . "/automagic/screenMsg?message=$msg";
|
||||
|
||||
return AMAD_HTTP_Request ($hash,$url);
|
||||
return AMAD_HTTP_POST ($hash,$url);
|
||||
}
|
||||
|
||||
sub AMAD_SetTtsMsg($@) {
|
||||
@ -277,7 +275,7 @@ sub AMAD_SetTtsMsg($@) {
|
||||
|
||||
my $url = "http://" . $host . ":" . $port . "/automagic/ttsMsg?message=$msg";
|
||||
|
||||
return AMAD_HTTP_Request ($hash,$url);
|
||||
return AMAD_HTTP_POST ($hash,$url);
|
||||
}
|
||||
|
||||
sub AMAD_SetVolume($@) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user