00_FBAHAHTTP.pm: support groups (Forum #53206)

git-svn-id: https://svn.fhem.de/fhem/trunk@11422 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig
2016-05-09 20:43:10 +00:00
parent 010b31d7e2
commit 3775b46f94
2 changed files with 13 additions and 14 deletions

View File

@@ -72,7 +72,8 @@ FBAHAHTTP_Poll($)
return $dr->("MISSING: set $name password") if(!$fb_pw);
my $sid = FB_doCheckPW($hash->{DEF}, $fb_user, $fb_pw);
return $dr->("ERROR: cannot get SID, check hostname/fritzbox-user/password")
return $dr->("$name error: cannot get SID, ".
"check connection/hostname/fritzbox-user/password")
if(!$sid);
$hash->{".SID"} = $sid;
$hash->{STATE} = "connected";
@@ -91,19 +92,15 @@ FBAHAHTTP_Poll($)
return;
}
Log 1, $_[2] if(AttrVal($name, "verbose", 1) > 4);
if($_[2] !~ m,^<devicelist.*</devicelist>$,s) {
Log3 $name, 3, "$name: unexpected reply from device: $_[2]";
delete $hash->{".SID"};
return;
}
$_[2] =~ s,</devicelist>,,;
my @a = split("<device ", $_[2]);
for(my $i=1; $i<int(@a); $i++) {
Dispatch($hash, "<device ".$a[$i], undef);
}
$_[2] =~ s+<(device|group) (.*?)</\g1>+
Dispatch($hash, "<$1 $2</$1>", undef)+gse; # Quick&Hack
}
});

View File

@@ -217,20 +217,21 @@ my %fbhttp_readings = (
state => '"state:".($val?"on":"off")',
tist => 'sprintf("temperature:%.1f C (measured)", $val/2)',
tsoll => 'sprintf("desired-temp:%.1f C", $val/2)',
members => '"members:$val"',
);
sub
FBDECT_ParseHttp($$)
FBDECT_ParseHttp($$$)
{
my ($iodev, $msg, $local) = @_;
my ($iodev, $msg, $type) = @_;
my $ioName = $iodev->{NAME};
my %h;
$msg =~ s,<([^/>]+?)>([^<]+?)<,$h{$1}=$2,ge; # Quick & Dirty: Tags
$msg =~ s, ([a-z]+?)="([^"]+)",$h{$1}=$2,ge; # Quick & Dirty: Attributes
$msg =~ s, ([a-z]+?)="([^"]*)",$h{$1}=$2,ge; # Quick & Dirty: Attributes
my $ain = $h{identifier};
$ain =~ s/[: ]/_/g;
$ain =~ s/[-: ]/_/g;
my %ll = (6=>"actuator", 7=>"powerMeter", 8=>"tempSensor",
9=>"switch", 10=>"repeater");
@@ -259,6 +260,7 @@ FBDECT_ParseHttp($$)
Log3 $hash, 5, " $n = $h{$n}";
next if(!$fbhttp_readings{$n});
my $val = $h{$n};
$val = $type if($n eq "productname" && $val eq "");
my ($ptyp,$pyld) = split(":", eval $fbhttp_readings{$n}, 2);
readingsBulkUpdate($hash, $ptyp, $pyld);
readingsBulkUpdate($hash, "state", "desired-temp: ".($val/2))
@@ -275,9 +277,9 @@ FBDECT_Parse($$@)
{
my ($iodev, $msg, $local) = @_;
my $mt = substr($msg, 0, 2);
return FBDECT_ParseHttp($iodev, $msg) if($mt eq "<d");
return FBDECT_ParseHttp($iodev, $msg, $1) if($msg =~ m/^<(device|group) /);
my $mt = substr($msg, 0, 2);
my $ioName = $iodev->{NAME};
if($mt ne "07" && $mt ne "04") {
Log3 $ioName, 1, "FBDECT: unknown message type $mt";