mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-04 22:19:38 +00:00
webCms added, longpoll bug fixed
git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@1051 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
03edda6247
commit
8abb6640bd
@ -94,6 +94,7 @@ FHEMWEB_Initialize($)
|
|||||||
@FW_zoom = ("qday", "day","week","month","year");
|
@FW_zoom = ("qday", "day","week","month","year");
|
||||||
%FW_zoom = map { $_, $n++ } @FW_zoom;
|
%FW_zoom = map { $_, $n++ } @FW_zoom;
|
||||||
|
|
||||||
|
addToAttrList("webCmd");
|
||||||
}
|
}
|
||||||
|
|
||||||
#####################################
|
#####################################
|
||||||
@ -178,6 +179,7 @@ FW_Read($)
|
|||||||
Log(1, "Accept failed for HTTP port ($name: $!)");
|
Log(1, "Accept failed for HTTP port ($name: $!)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
$hash->{CONNECTS}++;
|
||||||
|
|
||||||
my @clientsock = $hash->{IPV6} ?
|
my @clientsock = $hash->{IPV6} ?
|
||||||
sockaddr_in6($clientinfo[1]) :
|
sockaddr_in6($clientinfo[1]) :
|
||||||
@ -839,14 +841,15 @@ FW_showRoom()
|
|||||||
|
|
||||||
$row++;
|
$row++;
|
||||||
|
|
||||||
my ($allSets, $hasOnOff, $txt) = FW_devState($d, $rf);
|
my ($allSets, $cmdlist, $txt) = FW_devState($d, $rf);
|
||||||
pO "<td id=\"$d\">$txt";
|
pO "<td id=\"$d\">$txt";
|
||||||
|
|
||||||
if(!$FW_ss) {
|
if(!$FW_ss) {
|
||||||
pO "</td>";
|
pO "</td>";
|
||||||
if($hasOnOff) {
|
if($cmdlist) {
|
||||||
pH "cmd.$d=set $d on$rf", ReplaceEventMap($d, "on", 1), 1, "col3";
|
foreach my $cmd (split(" ", $cmdlist)) {
|
||||||
pH "cmd.$d=set $d off$rf", ReplaceEventMap($d, "off", 1), 1, "col3";
|
pH "cmd.$d=set $d $cmd$rf", ReplaceEventMap($d,$cmd,1), 1, "col3";
|
||||||
|
}
|
||||||
|
|
||||||
} elsif($allSets =~ m/ desired-temp /) {
|
} elsif($allSets =~ m/ desired-temp /) {
|
||||||
$txt = ReadingsVal($d, "measured-temp", "");
|
$txt = ReadingsVal($d, "measured-temp", "");
|
||||||
@ -1733,7 +1736,7 @@ FW_Notify($$)
|
|||||||
my $ln = $ntfy->{NAME};
|
my $ln = $ntfy->{NAME};
|
||||||
|
|
||||||
my $dn = $dev->{NAME};
|
my $dn = $dev->{NAME};
|
||||||
return undef if(AttrVal($dn, "room", "") ne $filter);
|
return undef if($filter ne "all" && AttrVal($dn, "room", "") ne $filter);
|
||||||
|
|
||||||
FW_ReadIcons();
|
FW_ReadIcons();
|
||||||
|
|
||||||
@ -1743,7 +1746,7 @@ FW_Notify($$)
|
|||||||
$FW_longpoll = 1;
|
$FW_longpoll = 1;
|
||||||
$FW_ss = AttrVal($FW_wname, "smallscreen", 0);
|
$FW_ss = AttrVal($FW_wname, "smallscreen", 0);
|
||||||
$FW_tp = AttrVal($FW_wname, "touchpad", $FW_ss);
|
$FW_tp = AttrVal($FW_wname, "touchpad", $FW_ss);
|
||||||
my ($allSet, $hasOnOff, $txt) = FW_devState($dn, "");
|
my ($allSet, $cmdlist, $txt) = FW_devState($dn, "");
|
||||||
($FW_wname, $FW_ME, $FW_longpoll, $FW_ss, $FW_tp) = @old;
|
($FW_wname, $FW_ME, $FW_longpoll, $FW_ss, $FW_tp) = @old;
|
||||||
|
|
||||||
$ntfy->{INFORMBUF} = "" if(!defined($ntfy->{INFORMBUF}));
|
$ntfy->{INFORMBUF} = "" if(!defined($ntfy->{INFORMBUF}));
|
||||||
@ -1769,12 +1772,18 @@ sub
|
|||||||
FW_devState($$)
|
FW_devState($$)
|
||||||
{
|
{
|
||||||
my ($d, $rf) = @_;
|
my ($d, $rf) = @_;
|
||||||
my $allSets = " " . getAllSets($d) . " ";
|
|
||||||
my $hasOnOff = ($allSets =~ m/ on / && $allSets =~ m/ off /);
|
my ($allSets, $hasOnOff, $cmdlist, $link);
|
||||||
|
my $webCmd = AttrVal($d, "webCmd", undef);
|
||||||
|
|
||||||
|
if(!$webCmd) {
|
||||||
|
$allSets = " " . getAllSets($d) . " ";
|
||||||
|
$hasOnOff = ($allSets =~ m/ on / && $allSets =~ m/ off /);
|
||||||
if(!$hasOnOff) { # Check the eventMap
|
if(!$hasOnOff) { # Check the eventMap
|
||||||
my $em = AttrVal($d, "eventMap", "") . " ";
|
my $em = AttrVal($d, "eventMap", "") . " ";
|
||||||
$hasOnOff = ($em =~ m/:on / && $em =~ m/:off /);
|
$hasOnOff = ($em =~ m/:on / && $em =~ m/:off /);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
my $state = $defs{$d}{STATE};
|
my $state = $defs{$d}{STATE};
|
||||||
$state = "" if(!defined($state));
|
$state = "" if(!defined($state));
|
||||||
@ -1783,7 +1792,7 @@ FW_devState($$)
|
|||||||
if(defined(AttrVal($d, "showtime", undef))) {
|
if(defined(AttrVal($d, "showtime", undef))) {
|
||||||
$txt = $defs{$d}{READINGS}{state}{TIME};
|
$txt = $defs{$d}{READINGS}{state}{TIME};
|
||||||
|
|
||||||
} elsif($allSets =~ m/ desired-temp /) {
|
} elsif($allSets && $allSets =~ m/ desired-temp /) {
|
||||||
$txt = ReadingsVal($d, "measured-temp", "");
|
$txt = ReadingsVal($d, "measured-temp", "");
|
||||||
$txt =~ s/ .*//;
|
$txt =~ s/ .*//;
|
||||||
$txt .= "°"
|
$txt .= "°"
|
||||||
@ -1796,8 +1805,19 @@ FW_devState($$)
|
|||||||
}
|
}
|
||||||
|
|
||||||
$txt = "<div id=\"$d\" align=\"center\" class=\"col2\">$txt</div>";
|
$txt = "<div id=\"$d\" align=\"center\" class=\"col2\">$txt</div>";
|
||||||
if($hasOnOff) {
|
|
||||||
my $link = "cmd.$d=set $d ".($state eq "on" ? "off":"on");
|
if($webCmd) {
|
||||||
|
my @a = split(" ", $webCmd);
|
||||||
|
$link = "cmd.$d=set $d $a[0]";
|
||||||
|
$cmdlist = $webCmd;
|
||||||
|
|
||||||
|
} elsif($hasOnOff) {
|
||||||
|
$link = "cmd.$d=set $d ".($state eq "on" ? "off":"on");
|
||||||
|
$cmdlist = "on off";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if($link) {
|
||||||
if($FW_longpoll) {
|
if($FW_longpoll) {
|
||||||
$txt = "<a onClick=\"cmd('$FW_ME?XHR=1&$link')\">$txt</a>";
|
$txt = "<a onClick=\"cmd('$FW_ME?XHR=1&$link')\">$txt</a>";
|
||||||
|
|
||||||
@ -1809,7 +1829,7 @@ FW_devState($$)
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ($allSets, $hasOnOff, $txt);
|
return ($allSets, $cmdlist, $txt);
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
@ -30,8 +30,13 @@ function
|
|||||||
longpoll()
|
longpoll()
|
||||||
{
|
{
|
||||||
pollConn = new XMLHttpRequest();
|
pollConn = new XMLHttpRequest();
|
||||||
pollConn.open("GET", document.location.pathname+document.location.search+
|
var room="room=all";
|
||||||
"&XHR=1&inform=1", true);
|
var sa = document.location.search.substring(1).split("&");
|
||||||
|
for(var i = 0; i < sa.length; i++) {
|
||||||
|
if(sa[i].substring(0,5) == "room=")
|
||||||
|
room=sa[i];
|
||||||
|
}
|
||||||
|
pollConn.open("GET", document.location.pathname+room+"&XHR=1&inform=1", true);
|
||||||
pollConn.onreadystatechange = doUpdate;
|
pollConn.onreadystatechange = doUpdate;
|
||||||
pollConn.send(null);
|
pollConn.send(null);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user