mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-10 09:16:53 +00:00
00_FBAHAHTTP.pm: fix "set template" (Forum #98913)
git-svn-id: https://svn.fhem.de/fhem/trunk@19019 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
1af3883ad0
commit
e29526ba90
@ -216,20 +216,59 @@ FBAHAHTTP_Set($@)
|
|||||||
setKeyValue("FBAHAHTTP_PASSWORD_$name", $a[0]);
|
setKeyValue("FBAHAHTTP_PASSWORD_$name", $a[0]);
|
||||||
delete($hash->{".SID"});
|
delete($hash->{".SID"});
|
||||||
FBAHAHTTP_Poll($hash);
|
FBAHAHTTP_Poll($hash);
|
||||||
return;
|
|
||||||
}
|
} elsif($type eq "refreshstate") {
|
||||||
if($type eq "refreshstate") {
|
|
||||||
FBAHAHTTP_Poll($hash);
|
FBAHAHTTP_Poll($hash);
|
||||||
return;
|
|
||||||
}
|
} elsif($type eq "template") {
|
||||||
if($type eq "template") {
|
my $cl = $hash->{CL};
|
||||||
FBAHAHTTP_Write($hash, $a[0], "applytemplate");
|
my $doRet = sub($)
|
||||||
return;
|
{
|
||||||
|
if($cl) {
|
||||||
|
asyncOutput($cl, $_[0]);
|
||||||
|
} else {
|
||||||
|
Log3 $hash, 4, "$_";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
FBAHAHTTP_GetTemplateList($hash, sub($$){
|
||||||
|
my ($err, $r) = @_;
|
||||||
|
return $doRet->($err) if($err);
|
||||||
|
return $doRet->("Unknown template $a[0]") if(!defined($r->{$a[0]}));
|
||||||
|
FBAHAHTTP_Write($hash, $r->{$a[0]}, "applytemplate");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub
|
||||||
|
FBAHAHTTP_GetTemplateList($$)
|
||||||
|
{
|
||||||
|
my ($hash, $callbackFn) = @_;
|
||||||
|
|
||||||
|
my $host = ($hash->{DEF} =~ m/^http/i ? $hash->{DEF}:"http://$hash->{DEF}");
|
||||||
|
my $sid = $hash->{".SID"};
|
||||||
|
my $name = $hash->{NAME};
|
||||||
|
return "No SID found" if(!$sid);
|
||||||
|
HttpUtils_NonblockingGet({
|
||||||
|
url=>"$host/webservices/homeautoswitch.lua?".
|
||||||
|
"sid=$sid&switchcmd=gettemplatelistinfos",
|
||||||
|
loglevel => AttrVal($name, "verbose", 4),
|
||||||
|
timeout => AttrVal($name, "fbTimeout", 4),
|
||||||
|
callback => sub {
|
||||||
|
if($_[1]) {
|
||||||
|
delete $hash->{".SID"};
|
||||||
|
return $callbackFn->("$name: $_[1]");
|
||||||
|
}
|
||||||
|
my $ret = (defined($_[2]) ? $_[2] : "") ;
|
||||||
|
my %r;
|
||||||
|
$ret =~ s:<template identifier="([^"]*)".*?<name>([^<]+)</name>:
|
||||||
|
$r{$2}=$1:ge;
|
||||||
|
$callbackFn->(undef, \%r);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
#####################################
|
#####################################
|
||||||
sub
|
sub
|
||||||
FBAHAHTTP_Get($@)
|
FBAHAHTTP_Get($@)
|
||||||
@ -241,39 +280,25 @@ FBAHAHTTP_Get($@)
|
|||||||
my $type = shift @a;
|
my $type = shift @a;
|
||||||
my $cl = $hash->{CL};
|
my $cl = $hash->{CL};
|
||||||
|
|
||||||
my $doRet = sub($)
|
|
||||||
{
|
|
||||||
if($cl) {
|
|
||||||
asyncOutput($cl, $_[0]);
|
|
||||||
} else {
|
|
||||||
Log3 $hash, 4, "$_";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return "Unknown argument $type, choose one of templatelist:noArg"
|
return "Unknown argument $type, choose one of templatelist:noArg"
|
||||||
if(!defined($gets{$type}));
|
if(!defined($gets{$type}));
|
||||||
return "Missing argument for $type" if(int(@a) < $gets{$type}-1);
|
return "Missing argument for $type" if(int(@a) < $gets{$type}-1);
|
||||||
|
|
||||||
if($type eq "templatelist") {
|
if($type eq "templatelist") {
|
||||||
my $host = ($hash->{DEF} =~ m/^http/i ? $hash->{DEF}:"http://$hash->{DEF}");
|
my $doRet = sub($)
|
||||||
my $sid = $hash->{".SID"};
|
{
|
||||||
return "No SID found" if(!$sid);
|
if($cl) {
|
||||||
HttpUtils_NonblockingGet({
|
asyncOutput($cl, $_[0]);
|
||||||
url=>"$host/webservices/homeautoswitch.lua?".
|
} else {
|
||||||
"sid=$sid&switchcmd=gettemplatelistinfos",
|
Log3 $hash, 4, "$_";
|
||||||
loglevel => AttrVal($name, "verbose", 4),
|
|
||||||
timeout => AttrVal($name, "fbTimeout", 4),
|
|
||||||
callback => sub {
|
|
||||||
if($_[1]) {
|
|
||||||
delete $hash->{".SID"};
|
|
||||||
return $doRet->("$name: $_[1]");
|
|
||||||
}
|
|
||||||
my $ret = (defined($_[2]) ? $_[2] : "") ;
|
|
||||||
my @r;
|
|
||||||
$ret =~ s:<name>([^<]+)</name>:push(@r,$1):ge;
|
|
||||||
readingsSingleUpdate($hash, "templateList", join(",",@r), $1);
|
|
||||||
$doRet->(join(",",@r));
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
FBAHAHTTP_GetTemplateList($hash, sub($$){
|
||||||
|
my ($err, $r) = @_;
|
||||||
|
return $doRet->($err) if($err);
|
||||||
|
my $str = join(",",sort keys %{$r});
|
||||||
|
readingsSingleUpdate($hash, "templateList", $str, 1);
|
||||||
|
$doRet->($str);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return undef;
|
return undef;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user