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