Umstellung auf NonblockingGet in allen Routinen, Code wurde aufgeräumt
This commit is contained in:
parent
d317b6e33a
commit
b834a03229
182
98_AMAD.pm
182
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,120 +71,113 @@ 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") {
|
||||||
if($attrVal eq "0") {
|
if($attrVal eq "0") {
|
||||||
RemoveInternalTimer($hash);
|
RemoveInternalTimer($hash);
|
||||||
InternalTimer(gettimeofday()+2, "AMAD_GetUpdateTimer", $hash, 0) if ($hash->{STATE} eq "disabled");
|
InternalTimer(gettimeofday()+2, "AMAD_GetUpdateTimer", $hash, 0) if ($hash->{STATE} eq "disabled");
|
||||||
$hash->{STATE}='active';
|
$hash->{STATE}='active';
|
||||||
Log3 $name, 4, "AMAD ($name) - enabled";
|
Log3 $name, 4, "AMAD ($name) - enabled";
|
||||||
} else {
|
|
||||||
$hash->{STATE} = 'disabled';
|
|
||||||
RemoveInternalTimer($hash);
|
|
||||||
Log3 $name, 4, "AMAD ($name) - disabled";
|
|
||||||
}
|
|
||||||
} elsif ($cmd eq "del") {
|
|
||||||
RemoveInternalTimer($hash);
|
|
||||||
InternalTimer(gettimeofday()+2, "AMAD_GetUpdateTimer", $hash, 0) if ($hash->{STATE} eq "disabled");
|
|
||||||
$hash->{STATE}='active';
|
|
||||||
Log3 $name, 4, "AMAD ($name) - enabled";
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if($cmd eq "set") {
|
$hash->{STATE} = 'disabled';
|
||||||
$attr{$name}{$attrName} = $attrVal;
|
RemoveInternalTimer($hash);
|
||||||
Log3 $name, 4, "AMAD ($name) - $attrName : $attrVal";
|
Log3 $name, 4, "AMAD ($name) - disabled";
|
||||||
} elsif ($cmd eq "del") {
|
}
|
||||||
}
|
} elsif ($cmd eq "del") {
|
||||||
}
|
RemoveInternalTimer($hash);
|
||||||
|
InternalTimer(gettimeofday()+2, "AMAD_GetUpdateTimer", $hash, 0) if ($hash->{STATE} eq "disabled");
|
||||||
|
$hash->{STATE}='active';
|
||||||
|
Log3 $name, 4, "AMAD ($name) - enabled";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if($cmd eq "set") {
|
||||||
|
$attr{$name}{$attrName} = $attrVal;
|
||||||
|
Log3 $name, 4, "AMAD ($name) - $attrName : $attrVal";
|
||||||
|
} elsif ($cmd eq "del") {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub AMAD_GetUpdateLocal($)
|
sub AMAD_GetUpdateLocal($)
|
||||||
{
|
{
|
||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
AMAD_RetrieveAutomagicInfo($name, 1);
|
|
||||||
|
|
||||||
return 1;
|
AMAD_RetrieveAutomagicInfo($hash);
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub AMAD_GetUpdateTimer($)
|
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";
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub AMAD_Set($$@)
|
sub AMAD_Set($$@)
|
||||||
{
|
{
|
||||||
my ($hash, $name, $cmd, @val) = @_;
|
my ($hash, $name, $cmd, @val) = @_;
|
||||||
|
|
||||||
my $list = "screenMsg"
|
my $list = "screenMsg"
|
||||||
. " ttsMsg"
|
. " ttsMsg"
|
||||||
. " setVolume"
|
. " setVolume"
|
||||||
. " mediaPlayer:play,stop,next,back";
|
. " deviceState:online,offline"
|
||||||
|
. " mediaPlayer:play,stop,next,back";
|
||||||
|
|
||||||
|
|
||||||
if ( lc $cmd eq 'screenmsg'
|
if ( lc $cmd eq 'screenmsg'
|
||||||
|| lc $cmd eq 'ttsmsg'
|
|| lc $cmd eq 'ttsmsg'
|
||||||
|| lc $cmd eq 'setvolume'
|
|| lc $cmd eq 'setvolume'
|
||||||
|| lc $cmd eq 'mediaplayer') {
|
|| lc $cmd eq 'mediaplayer') {
|
||||||
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);
|
||||||
|
|
||||||
return "Unknown argument $cmd or wrong parameter(s), choose one of $list";
|
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) = @_;
|
||||||
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) {
|
HttpUtils_NonblockingGet(
|
||||||
my $response = HttpUtils_BlockingGet(
|
{
|
||||||
{
|
url => $url,
|
||||||
url => $url,
|
timeout => 5,
|
||||||
timeout => 5,
|
#noshutdown => 0,
|
||||||
#noshutdown => 0,
|
hash => $hash,
|
||||||
}
|
method => "GET",
|
||||||
);
|
doTrigger => 1,
|
||||||
my %param = (hash => $hash, doTrigger => 0);
|
callback => \&AMAD_RetrieveAutomagicInfoFinished,
|
||||||
AMAD_RetrieveAutomagicInfoFinished(\%param, undef, $response);
|
}
|
||||||
Log3 $name, 3, "AMAD ($name) - BlockingGet get URL ";
|
);
|
||||||
}
|
Log3 $name, 3, "AMAD ($name) - NonblockingGet get URL";
|
||||||
else {
|
|
||||||
HttpUtils_NonblockingGet(
|
|
||||||
{
|
|
||||||
url => $url,
|
|
||||||
timeout => 5,
|
|
||||||
#noshutdown => 0,
|
|
||||||
hash => $hash,
|
|
||||||
doTrigger => 1,
|
|
||||||
callback => \&AMAD_RetrieveAutomagicInfoFinished,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
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,
|
{
|
||||||
timeout => 5,
|
url => $url,
|
||||||
#noshutdown => 0,
|
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;
|
$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