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);
|
InternalTimer(gettimeofday()+$hash->{INTERVAL}, "AMAD_GetUpdateTimer", $hash, 0);
|
||||||
|
|
||||||
$hash->{STATE} = "active";
|
$hash->{STATE} = "active";
|
||||||
|
readingsSingleUpdate ($hash,"deviceState","online",0);
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
@ -70,10 +71,8 @@ sub AMAD_Undef($$) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub AMAD_Attr(@) {
|
sub AMAD_Attr(@) {
|
||||||
# my ( $cmd, $name, $attrName, $attrVal) = @_; # alt
|
my ( $cmd, $name, $attrName, $attrVal) = @_;
|
||||||
my ( $cmd, $hash, $attrName, $attrVal) = @_;
|
my $hash = $defs{$name};
|
||||||
# my $hash = $defs{$name}; # alt
|
|
||||||
my $name = $hash->{NAME};
|
|
||||||
|
|
||||||
if ($attrName eq "disable") {
|
if ($attrName eq "disable") {
|
||||||
if($cmd eq "set") {
|
if($cmd eq "set") {
|
||||||
@ -109,7 +108,8 @@ sub AMAD_GetUpdateLocal($)
|
|||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
AMAD_RetrieveAutomagicInfo($name, 1);
|
|
||||||
|
AMAD_RetrieveAutomagicInfo($hash);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -119,7 +119,7 @@ sub AMAD_GetUpdateTimer($)
|
|||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
my $name = $hash->{NAME};
|
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);
|
InternalTimer(gettimeofday()+$hash->{INTERVAL}, "AMAD_GetUpdateTimer", $hash, 1);
|
||||||
Log3 $name, 3, "AMAD ($name) - Call AMAD_GetUpdateTimer";
|
Log3 $name, 3, "AMAD ($name) - Call AMAD_GetUpdateTimer";
|
||||||
@ -134,6 +134,7 @@ sub AMAD_Set($$@)
|
|||||||
my $list = "screenMsg"
|
my $list = "screenMsg"
|
||||||
. " ttsMsg"
|
. " ttsMsg"
|
||||||
. " setVolume"
|
. " setVolume"
|
||||||
|
. " deviceState:online,offline"
|
||||||
. " mediaPlayer:play,stop,next,back";
|
. " mediaPlayer:play,stop,next,back";
|
||||||
|
|
||||||
|
|
||||||
@ -144,46 +145,39 @@ sub AMAD_Set($$@)
|
|||||||
Log3 $name, 3, "AMAD ($name) - set $name $cmd ".join(" ", @val);
|
Log3 $name, 3, "AMAD ($name) - set $name $cmd ".join(" ", @val);
|
||||||
return AMAD_SetScreenMsg ($hash, @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";
|
return "Unknown argument $cmd or wrong parameter(s), choose one of $list";
|
||||||
}
|
}
|
||||||
|
|
||||||
sub AMAD_RetrieveAutomagicInfo
|
sub AMAD_RetrieveAutomagicInfo($)
|
||||||
{
|
{
|
||||||
# my ($name, $blocking) = @_;
|
my ($hash) = @_;
|
||||||
my ($hash, $blocking) = @_;
|
|
||||||
# my $hash = $defs{$name};
|
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
my $host = $hash->{HOST};
|
my $host = $hash->{HOST};
|
||||||
my $port = $hash->{PORT};
|
my $port = $hash->{PORT};
|
||||||
|
|
||||||
my $url = "http://" . $host . ":" . $port . "/automagic/deviceInfo";
|
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(
|
HttpUtils_NonblockingGet(
|
||||||
{
|
{
|
||||||
url => $url,
|
url => $url,
|
||||||
timeout => 5,
|
timeout => 5,
|
||||||
#noshutdown => 0,
|
#noshutdown => 0,
|
||||||
hash => $hash,
|
hash => $hash,
|
||||||
|
method => "GET",
|
||||||
doTrigger => 1,
|
doTrigger => 1,
|
||||||
callback => \&AMAD_RetrieveAutomagicInfoFinished,
|
callback => \&AMAD_RetrieveAutomagicInfoFinished,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
Log3 $name, 3, "AMAD ($name) - NonblockingGet get URL";
|
Log3 $name, 3, "AMAD ($name) - NonblockingGet get URL";
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub AMAD_RetrieveAutomagicInfoFinished($$$)
|
sub AMAD_RetrieveAutomagicInfoFinished($$$)
|
||||||
@ -230,21 +224,25 @@ sub AMAD_RetrieveAutomagicInfoFinished($$$)
|
|||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub AMAD_HTTP_Request {
|
sub AMAD_HTTP_POST($$)
|
||||||
|
{
|
||||||
my ($hash, $url) = @_;
|
my ($hash, $url) = @_;
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
my $state = $hash->{STATE};
|
my $state = $hash->{STATE};
|
||||||
|
|
||||||
$hash->{STATE} = "Send http Request";
|
$hash->{STATE} = "Send HTTP POST";
|
||||||
HttpUtils_BlockingGet(
|
|
||||||
|
HttpUtils_NonblockingGet(
|
||||||
{
|
{
|
||||||
url => $url,
|
url => $url,
|
||||||
timeout => 5,
|
timeout => 5,
|
||||||
#noshutdown => 0,
|
#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;
|
$hash->{STATE} = $state;
|
||||||
|
|
||||||
@ -263,7 +261,7 @@ sub AMAD_SetScreenMsg($@)
|
|||||||
|
|
||||||
my $url = "http://" . $host . ":" . $port . "/automagic/screenMsg?message=$msg";
|
my $url = "http://" . $host . ":" . $port . "/automagic/screenMsg?message=$msg";
|
||||||
|
|
||||||
return AMAD_HTTP_Request ($hash,$url);
|
return AMAD_HTTP_POST ($hash,$url);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub AMAD_SetTtsMsg($@) {
|
sub AMAD_SetTtsMsg($@) {
|
||||||
@ -277,7 +275,7 @@ sub AMAD_SetTtsMsg($@) {
|
|||||||
|
|
||||||
my $url = "http://" . $host . ":" . $port . "/automagic/ttsMsg?message=$msg";
|
my $url = "http://" . $host . ":" . $port . "/automagic/ttsMsg?message=$msg";
|
||||||
|
|
||||||
return AMAD_HTTP_Request ($hash,$url);
|
return AMAD_HTTP_POST ($hash,$url);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub AMAD_SetVolume($@) {
|
sub AMAD_SetVolume($@) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user