mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 06:39:11 +00:00
01_FHEMWEB.js: add "Raw definition" in the device overview.
git-svn-id: https://svn.fhem.de/fhem/trunk@12416 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
ec5aa1b9b7
commit
8cf86fa79b
@ -1278,6 +1278,7 @@ FW_doDetail($)
|
||||
|
||||
FW_pH "cmd=style iconFor $d", "Select icon", undef, "detLink iconFor";
|
||||
FW_pH "cmd=style showDSI $d", "Extend devStateIcon", undef, "detLink showDSI";
|
||||
FW_pH "cmd=rawDef $d", "Raw defintion", undef, "detLink rawDef";
|
||||
FW_pH "cmd=delete $d", "Delete this device ($d)", undef, "detLink delDev"
|
||||
if($d ne "global");
|
||||
my $sfx = AttrVal("global", "language", "EN");
|
||||
|
@ -886,7 +886,9 @@ The following local attributes are used by a wider range of devices:
|
||||
<a name="list"></a>
|
||||
<h3>list</h3>
|
||||
<ul>
|
||||
<code>list [devspec] [value]</code>
|
||||
<code>list [devspec] [value]</code><br>
|
||||
or<br>
|
||||
<code>list -r devspec</code><br>
|
||||
<br><br>
|
||||
Output a list of all definitions, all notify settings and all at
|
||||
entries. This is one of the few commands which return a string in a
|
||||
@ -947,6 +949,8 @@ The following local attributes are used by a wider range of devices:
|
||||
2006-11-02 09:45:56 actuator 19%
|
||||
[...]
|
||||
</code></pre>
|
||||
With the -r (raw) option output the device definition in a format suitable
|
||||
for inclusion in fhem.cfg and fhem.state.
|
||||
</ul>
|
||||
|
||||
<a name="modify"></a>
|
||||
|
@ -935,7 +935,9 @@ Die folgenden lokalen Attribute werden von mehreren Geräten verwendet:
|
||||
<a name="list"></a>
|
||||
<h3>list</h3>
|
||||
<ul>
|
||||
<code>list [devspec] [value]</code>
|
||||
<code>list [devspec] [value]</code><br>
|
||||
oder<br>
|
||||
<code>list -r devspec</code><br>
|
||||
<br><br>
|
||||
Auflistung aller "definitions", "notify" und
|
||||
"at"-Definitionen. Dies ist eines der wenigen Befehle, die im
|
||||
@ -996,6 +998,8 @@ Die folgenden lokalen Attribute werden von mehreren Geräten verwendet:
|
||||
2006-11-02 09:45:56 actuator 19%
|
||||
[...]
|
||||
</code></pre>
|
||||
Mit der -r (raw) Option werden die Daten in einem für fhem.cfg bzw.
|
||||
fhem.state passenden format generiert.
|
||||
</ul>
|
||||
|
||||
|
||||
|
148
fhem/fhem.pl
148
fhem/fhem.pl
@ -348,7 +348,7 @@ $readingFnAttributes = "event-on-change-reading event-on-update-reading ".
|
||||
"iowrite" => { Fn=>"CommandIOWrite",
|
||||
Hlp=>"<iodev> <data>,write raw data with iodev" },
|
||||
"list" => { Fn=>"CommandList",
|
||||
Hlp=>"[devspec],list definitions and status info" },
|
||||
Hlp=>"[-r] [devspec],list definitions and status info" },
|
||||
"modify" => { Fn=>"CommandModify",
|
||||
Hlp=>"device <options>,modify the definition (e.g. at, notify)" },
|
||||
"quit" => { Fn=>"CommandQuit",
|
||||
@ -1349,6 +1349,46 @@ CommandQuit($$)
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub
|
||||
GetAllReadings($)
|
||||
{
|
||||
my ($d) = @_;
|
||||
my @ret;
|
||||
my $val = $defs{$d}{STATE};
|
||||
if(defined($val) &&
|
||||
$val ne "unknown" &&
|
||||
$val ne "Initialized" &&
|
||||
$val ne "???") {
|
||||
$val =~ s/;/;;/g;
|
||||
$val =~ s/\n/\\\n/g;
|
||||
push @ret, "setstate $d $val";
|
||||
}
|
||||
|
||||
#############
|
||||
# Now the detailed list
|
||||
my $r = $defs{$d}{READINGS};
|
||||
if($r) {
|
||||
foreach my $c (sort keys %{$r}) {
|
||||
|
||||
my $rd = $r->{$c};
|
||||
if(!defined($rd->{TIME})) {
|
||||
Log 4, "WriteStatefile $d $c: Missing TIME, using current time";
|
||||
$rd->{TIME} = TimeNow();
|
||||
}
|
||||
|
||||
if(!defined($rd->{VAL})) {
|
||||
Log 4, "WriteStatefile $d $c: Missing VAL, setting it to 0";
|
||||
$rd->{VAL} = 0;
|
||||
}
|
||||
my $val = $rd->{VAL};
|
||||
$val =~ s/;/;;/g;
|
||||
$val =~ s/\n/\\\n/g;
|
||||
push @ret,"setstate $d $rd->{TIME} $c $val";
|
||||
}
|
||||
}
|
||||
return @ret;
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
WriteStatefile()
|
||||
@ -1380,44 +1420,46 @@ WriteStatefile()
|
||||
print SFH "define $d $defs{$d}{TYPE} $def\n";
|
||||
}
|
||||
|
||||
my $val = $defs{$d}{STATE};
|
||||
if(defined($val) &&
|
||||
$val ne "unknown" &&
|
||||
$val ne "Initialized" &&
|
||||
$val ne "???") {
|
||||
$val =~ s/;/;;/g;
|
||||
$val =~ s/\n/\\\n/g;
|
||||
print SFH "setstate $d $val\n"
|
||||
}
|
||||
|
||||
#############
|
||||
# Now the detailed list
|
||||
my $r = $defs{$d}{READINGS};
|
||||
if($r) {
|
||||
foreach my $c (sort keys %{$r}) {
|
||||
|
||||
my $rd = $r->{$c};
|
||||
if(!defined($rd->{TIME})) {
|
||||
Log 4, "WriteStatefile $d $c: Missing TIME, using current time";
|
||||
$rd->{TIME} = TimeNow();
|
||||
}
|
||||
|
||||
if(!defined($rd->{VAL})) {
|
||||
Log 4, "WriteStatefile $d $c: Missing VAL, setting it to 0";
|
||||
$rd->{VAL} = 0;
|
||||
}
|
||||
my $val = $rd->{VAL};
|
||||
$val =~ s/;/;;/g;
|
||||
$val =~ s/\n/\\\n/g;
|
||||
print SFH "setstate $d $rd->{TIME} $c $val\n";
|
||||
}
|
||||
}
|
||||
my @arr = GetAllReadings($d);
|
||||
printf SFH join(@arr, "\n") if(@arr);
|
||||
}
|
||||
|
||||
return "$attr{global}{statefile}: $!" if(!close(SFH));
|
||||
return "";
|
||||
}
|
||||
|
||||
sub
|
||||
GetDefAndAttr($)
|
||||
{
|
||||
my ($d) = @_;
|
||||
my @ret;
|
||||
|
||||
if($d ne "global") {
|
||||
my $def = $defs{$d}{DEF};
|
||||
if(defined($def)) {
|
||||
$def =~ s/;/;;/g;
|
||||
$def =~ s/\n/\\\n/g;
|
||||
push @ret,"define $d $defs{$d}{TYPE} $def";
|
||||
} else {
|
||||
push @ret,"define $d $defs{$d}{TYPE}";
|
||||
}
|
||||
}
|
||||
|
||||
foreach my $a (sort {
|
||||
return -1 if($a eq "userattr"); # userattr must be first
|
||||
return 1 if($b eq "userattr");
|
||||
return $a cmp $b;
|
||||
} keys %{$attr{$d}}) {
|
||||
next if($d eq "global" &&
|
||||
($a eq "configfile" || $a eq "version"));
|
||||
my $val = $attr{$d}{$a};
|
||||
$val =~ s/;/;;/g;
|
||||
$val =~ s/\n/\\\n/g;
|
||||
push @ret,"attr $d $a $val";
|
||||
}
|
||||
return @ret;
|
||||
}
|
||||
|
||||
#####################################
|
||||
sub
|
||||
CommandSave($$)
|
||||
@ -1484,29 +1526,9 @@ CommandSave($$)
|
||||
next;
|
||||
}
|
||||
|
||||
if($d ne "global") {
|
||||
my $def = $defs{$d}{DEF};
|
||||
if(defined($def)) {
|
||||
$def =~ s/;/;;/g;
|
||||
$def =~ s/\n/\\\n/g;
|
||||
print $fh "define $d $defs{$d}{TYPE} $def\n";
|
||||
} else {
|
||||
print $fh "define $d $defs{$d}{TYPE}\n";
|
||||
}
|
||||
}
|
||||
my @arr = GetDefAndAttr($d);
|
||||
print $fh join("\n", @arr)."\n" if(@arr);
|
||||
|
||||
foreach my $a (sort {
|
||||
return -1 if($a eq "userattr"); # userattr must be first
|
||||
return 1 if($b eq "userattr");
|
||||
return $a cmp $b;
|
||||
} keys %{$attr{$d}}) {
|
||||
next if($d eq "global" &&
|
||||
($a eq "configfile" || $a eq "version"));
|
||||
my $val = $attr{$d}{$a};
|
||||
$val =~ s/;/;;/g;
|
||||
$val =~ s/\n/\\\n/g;
|
||||
print $fh "attr $d $a $val\n";
|
||||
}
|
||||
}
|
||||
|
||||
print SFH "include $attr{global}{lastinclude}\n"
|
||||
@ -2143,6 +2165,22 @@ CommandList($$)
|
||||
my ($cl, $param) = @_;
|
||||
my $str = "";
|
||||
|
||||
if($param =~ m/^-r *(.*)$/) {
|
||||
my $arg = ($1 ? $1 : ".*");
|
||||
foreach my $d (devspec2array($arg,$cl)) {
|
||||
if(!defined($defs{$d})) {
|
||||
$str .= "No device named $d found";
|
||||
last;
|
||||
}
|
||||
$str .= "\n" if($str);
|
||||
my @a = GetDefAndAttr($d);
|
||||
$str .= join("\n", @a)."\n" if(@a);
|
||||
@a = GetAllReadings($d);
|
||||
$str .= join("\n", @a)."\n" if(@a);
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
||||
if(!$param) { # List of all devices
|
||||
|
||||
$str = "\nType list <name> for detailed info.\n";
|
||||
|
@ -212,8 +212,8 @@ FW_jqueryReadyFn()
|
||||
|
||||
|
||||
FW_smallScreenCommands();
|
||||
|
||||
FW_inlineModify();
|
||||
FW_rawDef();
|
||||
}
|
||||
|
||||
function
|
||||
@ -583,6 +583,65 @@ FW_inlineModify() // Do not generate a new HTML page upon pressing modify
|
||||
});
|
||||
}
|
||||
|
||||
function
|
||||
FW_rawDef()
|
||||
{
|
||||
$("div.rawDef a").each(function(){ // Help on detail window
|
||||
var dev = FW_getLink(this).split(" ").pop();
|
||||
$(this).unbind("click");
|
||||
$(this).attr("href", "#"); // Desktop: show underlined Text
|
||||
$(this).removeAttr("onclick");
|
||||
|
||||
$(this).click(function(evt){
|
||||
if($("#rawDef").length) {
|
||||
$("#rawDef").remove();
|
||||
return;
|
||||
}
|
||||
|
||||
$("#content").append('<div id="rawDef">'+
|
||||
'<textarea id="td_longText" rows="25" cols="60" style="width:99%"/>'+
|
||||
'<button>Apply changes</button>'+
|
||||
'</div></br>');
|
||||
FW_cmd(FW_root+"?cmd=list -r "+dev+"&XHR=1", function(data) {
|
||||
data = data.replace("define", "defmod");
|
||||
$("#rawDef textarea").val(data);
|
||||
var off = $("#rawDef").position().top-20;
|
||||
$('body, html').animate({scrollTop:off}, 500);
|
||||
});
|
||||
$("#rawDef button").click(function(){
|
||||
var data = $("#rawDef textarea").val();
|
||||
var arr = data.split("\n"), str="", i1=-1;
|
||||
function
|
||||
doNext()
|
||||
{
|
||||
if(++i1 >= arr.length)
|
||||
return;
|
||||
str += arr[i1];
|
||||
if(arr[i1].charAt(arr[i1].length-1) === "\\") {
|
||||
str += "\n";
|
||||
return doNext();
|
||||
}
|
||||
if(str != "") {
|
||||
str = str.replace(/\\\n/g, "\n")
|
||||
.replace(/;;/g, ";");
|
||||
FW_cmd(FW_root+"?cmd."+dev+"="+encodeURIComponent(str)+"&XHR=1",
|
||||
function(r){
|
||||
if(r)
|
||||
return FW_okDialog('<pre>'+r+'</pre>');
|
||||
str = "";
|
||||
doNext();
|
||||
});
|
||||
} else {
|
||||
doNext();
|
||||
}
|
||||
}
|
||||
doNext();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
/*************** LONGPOLL START **************/
|
||||
var FW_pollConn;
|
||||
var FW_longpollOffset = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user