mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 06:39:11 +00:00
fhem.pl: add -silent option th define/modify/defmod (Forum #57691)
git-svn-id: https://svn.fhem.de/fhem/trunk@24260 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
483cb1ed0e
commit
123f68c620
@ -794,6 +794,9 @@ The following local attributes are used by a wider range of devices:
|
||||
be loaded. Used by fhem.cfg.demo, as using the RSS example requires the
|
||||
installation of several uncommon perl modules.
|
||||
</li><br>
|
||||
<li>-silent<br>
|
||||
Do no enter the command in the "save ?" list.
|
||||
</li><br>
|
||||
</ul>
|
||||
|
||||
</ul>
|
||||
@ -802,8 +805,8 @@ The following local attributes are used by a wider range of devices:
|
||||
<a name="defmod"></a>
|
||||
<h3>defmod</h3>
|
||||
<ul>
|
||||
<code>defmod [-temporary] <name> <type> <type-specific></code><br>
|
||||
<br>
|
||||
<code>defmod [option] <name> <type> <type-specific></code>
|
||||
<br><br>
|
||||
Define a device or modify it, if it already exists. E.g. to switch off a lamp
|
||||
10 Minutes after the last message from the motion detector, you may use
|
||||
<ul><code>
|
||||
@ -811,7 +814,8 @@ The following local attributes are used by a wider range of devices:
|
||||
</code></ul>
|
||||
Using define here for the mdOff will generate an error if the motion detector
|
||||
triggers within the 10 minutes after the first event, as the mdOff at
|
||||
definition still exists.
|
||||
definition still exists.<br>
|
||||
For the options see the define documentation.
|
||||
<br>
|
||||
</ul>
|
||||
<!-- defmod end -->
|
||||
@ -1046,7 +1050,7 @@ The following local attributes are used by a wider range of devices:
|
||||
<a name="modify"></a>
|
||||
<h3>modify</h3>
|
||||
<ul>
|
||||
<code>modify <name> <type-dependent-options></code>
|
||||
<code>modify [-silent] <name> <type-dependent-options></code>
|
||||
<br><br>
|
||||
|
||||
Used to modify some definitions. Useful for changing some <a
|
||||
@ -1054,7 +1058,8 @@ The following local attributes are used by a wider range of devices:
|
||||
one argument to an at type definition, only the time part will be changed. In
|
||||
case of a notify type definition, only the regex part will be changed. All
|
||||
other values (state, attributes, etc) will remain intact.
|
||||
After modify, the global event "MODIFIED" will be generated.
|
||||
After modify, the global event "MODIFIED" will be generated.<br>
|
||||
With the -silent option the command is not recorded in the "save -?" list.
|
||||
<br><br>
|
||||
Example:
|
||||
<ul>
|
||||
|
@ -813,6 +813,9 @@ Die folgenden lokalen Attribute werden von mehreren Geräten verwendet:
|
||||
geladen werden kann. Wird in fhem.cfg.demo verwendet, da das RSS Beispiel
|
||||
etliche, normalerweise nicht installierte perl-Module benötigt.
|
||||
</li><br>
|
||||
<li>-silent<br>
|
||||
Der Befehl wird nicht in die "save -?" Liste eingetragen.
|
||||
</li><br>
|
||||
</ul>
|
||||
</ul>
|
||||
<!-- define end -->
|
||||
@ -820,8 +823,8 @@ Die folgenden lokalen Attribute werden von mehreren Geräten verwendet:
|
||||
<a name="defmod"></a>
|
||||
<h3>defmod</h3>
|
||||
<ul>
|
||||
<code>defmod [-temporary] <name> <type> <type-specific></code><br>
|
||||
<br>
|
||||
<code>defmod [option] <name> <type> <type-specific></code>
|
||||
<br><br>
|
||||
Definiert ein Gerät, oder ändert es, falls es exisitiert. Um
|
||||
z.Bsp. eine Lampe 10 Minuten nach der letzten Meldung eines Bewegungsmelders
|
||||
abzuschalten, könnte man folgendes definieren:
|
||||
@ -830,7 +833,8 @@ Die folgenden lokalen Attribute werden von mehreren Geräten verwendet:
|
||||
</code></ul>
|
||||
Falls man statt defmod ein define verwenden würde, dann würde eine
|
||||
Meldung innerhalb von 10 Minuten nach der letzten Meldung zu einem Fehler
|
||||
führen, da mdOff noch existiert.
|
||||
führen, da mdOff noch existiert.<br>
|
||||
Für die Optionen siehe die define Dokumentation.
|
||||
<br>
|
||||
</ul>
|
||||
<!-- defmod end -->
|
||||
@ -1101,7 +1105,7 @@ Die folgenden lokalen Attribute werden von mehreren Geräten verwendet:
|
||||
<a name="modify"></a>
|
||||
<h3>modify</h3>
|
||||
<ul>
|
||||
<code>modify <name> <type-dependent-options></code>
|
||||
<code>modify [-silent] <name> <type-dependent-options></code>
|
||||
<br><br>
|
||||
|
||||
Dieser Befehl wird benutzt, um Definitionen zu verändern. Er ist
|
||||
@ -1110,9 +1114,11 @@ Die folgenden lokalen Attribute werden von mehreren Geräten verwendet:
|
||||
verändern, dann wird nur der für die Zeit zuständige Teil
|
||||
geändert. Im Falle der Veränderung einer Definition vom Typ
|
||||
"notify" wird nur der regex Teil geändert. Alle anderen
|
||||
Werte (Stati, Attribute, etc) bleiben erhalten.
|
||||
After modify, the global event "MODIFIED" will be generated.
|
||||
Nach der Durchführung das globale Ereignis "MODIFIED" wird generiert.
|
||||
Werte (Stati, Attribute, etc) bleiben erhalten.<br>
|
||||
Nach modify wird das global MODIFIED Event erzeugt.<br>
|
||||
Nach der Durchführung das globale Ereignis "MODIFIED" wird generiert.<br>
|
||||
Mit der silent Option wird der modify Befehl nicht in die "save -?" Liste
|
||||
eingetragen.
|
||||
<br><br>
|
||||
|
||||
Beispiel:
|
||||
|
65
fhem/fhem.pl
65
fhem/fhem.pl
@ -2054,27 +2054,35 @@ LoadModule($;$)
|
||||
|
||||
|
||||
#####################################
|
||||
sub
|
||||
cmd_parseOpts($$$)
|
||||
{
|
||||
my ($def, $optRegexp, $res) = @_;
|
||||
while($def) {
|
||||
last if($def !~ m/^\s*($optRegexp)\s+/);
|
||||
my $o = $1;
|
||||
$def =~ s/^\s*$o\s+//;
|
||||
$o =~ s/^-//;
|
||||
$res->{$o} = 1;
|
||||
}
|
||||
return $def;
|
||||
}
|
||||
|
||||
sub
|
||||
CommandDefine($$)
|
||||
{
|
||||
my ($cl, $def) = @_;
|
||||
my @a = split("[ \t]+", $def, 3);
|
||||
my ($ignoreErr, $temporary);
|
||||
|
||||
# used by RSS in fhem.cfg.demo, with no GD installed
|
||||
if($a[0] && $a[0] eq "-ignoreErr") {
|
||||
$def =~ s/\s*-ignoreErr\s*//;
|
||||
@a = split("[ \t][ \t]*", $def, 3);
|
||||
$ignoreErr = 1;
|
||||
}
|
||||
if($a[0] && $a[0] eq "-temporary") { # Forum #39610, 46640
|
||||
$def =~ s/\s*-temporary\s*//;
|
||||
@a = split("[ \t][ \t]*", $def, 3);
|
||||
$temporary = 1;
|
||||
}
|
||||
# ignoreErr ist used by RSS in fhem.cfg.demo, with no GD installed
|
||||
# temporary #39610 #46640
|
||||
# silent #57691
|
||||
my %opt;
|
||||
my $optRegexp = '-ignoreErr|-temporary|-silent';
|
||||
$def = cmd_parseOpts($def, $optRegexp, \%opt);
|
||||
my @a = split("[ \t]+", $def, 3);
|
||||
|
||||
my $name = $a[0];
|
||||
return "Usage: define <name> <type> <type dependent arguments>"
|
||||
return "Usage: define [$optRegexp] <name> <type> <type dependent arguments>"
|
||||
if(int(@a) < 2);
|
||||
return "$name already defined, delete it first" if(defined($defs{$name}));
|
||||
return "Invalid characters in name (not A-Za-z0-9._): $name"
|
||||
@ -2090,7 +2098,7 @@ CommandDefine($$)
|
||||
}
|
||||
}
|
||||
|
||||
my $newm = LoadModule($m, $ignoreErr);
|
||||
my $newm = LoadModule($m, $opt{ignoreErr});
|
||||
return "Cannot load module $m" if($newm eq "UNDEFINED");
|
||||
$m = $newm;
|
||||
|
||||
@ -2108,7 +2116,7 @@ CommandDefine($$)
|
||||
if($currcfgfile ne AttrVal("global", "configfile", "") &&
|
||||
!configDBUsed());
|
||||
$hash{CL} = $cl;
|
||||
$hash{TEMPORARY} = 1 if($temporary);
|
||||
$hash{TEMPORARY} = 1 if($opt{temporary});
|
||||
|
||||
# If the device wants to issue initialization gets/sets, then it needs to be
|
||||
# in the global hash.
|
||||
@ -2117,7 +2125,7 @@ CommandDefine($$)
|
||||
my $ret = CallFn($name, "DefFn", \%hash,
|
||||
$modules{$m}->{parseParams} ? parseParams($def) : $def);
|
||||
if($ret) {
|
||||
Log 1, "define $def: $ret" if(!$ignoreErr);
|
||||
Log 1, "define $def: $ret" if(!$opt{ignoreErr});
|
||||
delete $defs{$name}; # Veto
|
||||
delete $attr{$name};
|
||||
|
||||
@ -2131,12 +2139,12 @@ CommandDefine($$)
|
||||
$modules{$m}{NotifyOrderPrefix} : "50-") . $name;
|
||||
}
|
||||
%ntfyHash = ();
|
||||
if(!$temporary && $init_done) {
|
||||
addStructChange("define", $name, $def);
|
||||
if(!$opt{temporary} && $init_done) {
|
||||
addStructChange("define", $name, $def) if(!$opt{silent});
|
||||
DoTrigger("global", "DEFINED $name", 1);
|
||||
}
|
||||
}
|
||||
return ($ret && $ignoreErr ?
|
||||
return ($ret && $opt{ignoreErr} ?
|
||||
"Cannot define $name, remove -ignoreErr for details" : $ret);
|
||||
}
|
||||
|
||||
@ -2145,6 +2153,9 @@ sub
|
||||
CommandModify($$)
|
||||
{
|
||||
my ($cl, $def) = @_;
|
||||
|
||||
my %opt;
|
||||
$def = cmd_parseOpts($def, '-silent', \%opt);
|
||||
my @a = split("[ \t]+", $def, 2);
|
||||
|
||||
return "Usage: modify <name> <type dependent arguments>"
|
||||
@ -2166,7 +2177,7 @@ CommandModify($$)
|
||||
if($ret) {
|
||||
$hash->{DEF} = $hash->{OLDDEF};
|
||||
} else {
|
||||
addStructChange("modify", $a[0], $def);
|
||||
addStructChange("modify", $a[0], $def) if(!$opt{silent});
|
||||
DoTrigger("global", "MODIFIED $a[0]", 1) if($init_done);
|
||||
}
|
||||
|
||||
@ -2179,19 +2190,21 @@ sub
|
||||
CommandDefMod($$)
|
||||
{
|
||||
my ($cl, $def) = @_;
|
||||
my %opt;
|
||||
my $optRegexp = '-ignoreErr|-temporary|-silent';
|
||||
$def = cmd_parseOpts($def, $optRegexp, \%opt);
|
||||
my @a = split("[ \t]+", $def, 3);
|
||||
return "Usage: defmod <name> <type> <type dependent arguments>"
|
||||
|
||||
return "Usage: defmod [$optRegexp] <name> <type> <type dependent arguments>"
|
||||
if(int(@a) < 2);
|
||||
if($a[0] eq "-temporary" && $defs{$a[1]}) {
|
||||
@a = split("[ \t]+", $def, 4);
|
||||
shift @a;
|
||||
}
|
||||
if($defs{$a[0]}) {
|
||||
$def = $a[2] ? "$a[0] $a[2]" : $a[0];
|
||||
return "defmod $a[0]: Cannot change the TYPE of an existing definition"
|
||||
if($a[1] ne $defs{$a[0]}{TYPE});
|
||||
$def = "-".join(" -", keys %opt)." ".$def if(%opt);
|
||||
return CommandModify($cl, $def);
|
||||
} else {
|
||||
$def = "-".join(" -", keys %opt)." ".$def if(%opt);
|
||||
return CommandDefine($cl, $def);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user