From 90345b7a7261d77aa25ed948593e144d79d52076 Mon Sep 17 00:00:00 2001
From: rudolfkoenig <>
Date: Wed, 9 Dec 2009 13:15:16 +0000
Subject: [PATCH] DEFINED & INITIALIZED Macros
git-svn-id: https://svn.fhem.de/fhem/trunk@502 2b470e98-0d58-463d-a4d8-8e2adae1ed80
---
fhem/CHANGED | 1 +
fhem/docs/commandref.html | 23 +++++++++++++++++++++++
fhem/fhem.pl | 9 +++++++--
3 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/fhem/CHANGED b/fhem/CHANGED
index f13ed666e..e1091bcfc 100644
--- a/fhem/CHANGED
+++ b/fhem/CHANGED
@@ -552,3 +552,4 @@
- bugfix: Path in the examples fixed (got corrupted)
- bugfix: PachLog fixes from Axel
- bugfix: HOWTO/Examples revisited for correctness
+ - bugfix: DEFINED & INITIALIZED triggers.
diff --git a/fhem/docs/commandref.html b/fhem/docs/commandref.html
index 41d5d1fb5..cfc7466a5 100644
--- a/fhem/docs/commandref.html
+++ b/fhem/docs/commandref.html
@@ -3722,6 +3722,20 @@ A line ending with \ will be concatenated with the next one, so long lines
Each undefined device (FS20, HMS, FHT) will be reported with the
device name "UNDEFINED". The % parameter will contain the type (FS20,
HMS100T, etc) and device number, separated by a space.
+
+ After defining a device, the event "DEFINED" will be triggered. This
+ can be used in the fhem.cfg to set some values of the device.
+
+ After initialization finished, the event "INITIALIZED" for the device
+ "global" will be triggered.
+
+ Notify can be used to store macros for manual execution. Use the trigger command to execute the macro. E.g.
+
+ fhem> define MyMacro notify MyMacro { Log 1, "Hello"}
+ fhem> trigger MyMacro
+
+
@@ -4356,6 +4370,15 @@ isday
Perl specials
+ - To test perl oneliners, type them on the prompt by enclosing it in {}, e.g.
+
+
+
+ - To store some macros, see the Notes in the notify
+ description.
+
- To use fhem commands from the perl expression, use the function "fhem",
which takes a string argument, this string will be evaluated as a fhem
command chain.
diff --git a/fhem/fhem.pl b/fhem/fhem.pl
index 6ae41a70f..dc88f6e55 100755
--- a/fhem/fhem.pl
+++ b/fhem/fhem.pl
@@ -48,6 +48,7 @@ sub CallFn(@);
sub CommandChain($$);
sub CheckDuplicate($$);
sub DoClose($);
+sub DoTrigger($$);
sub Dispatch($$$);
sub FmtDateTime($);
sub FmtTime($);
@@ -155,7 +156,7 @@ my $nextat; # Time when next timer will be triggered.
my $intAtCnt=0;
my %duplicate; # Pool of received msg for multi-fhz/cul setups
my $duplidx=0; # helper for the above pool
-my $cvsid = '$Id: fhem.pl,v 1.89 2009-12-01 22:41:17 rudolfkoenig Exp $';
+my $cvsid = '$Id: fhem.pl,v 1.90 2009-12-09 13:15:16 rudolfkoenig Exp $';
my $namedef =
"where is either:\n" .
"- a single device name\n" .
@@ -286,6 +287,7 @@ if($pfn) {
close(PID);
}
$init_done = 1;
+DoTrigger("global", "INITIALIZED");
Log 0, "Server started (version $attr{global}{version}, pid $$)";
@@ -1041,6 +1043,7 @@ CommandDefine($$)
CommandAttr($cl, "$a[0] $da $defaultattr{$da}");
}
}
+ DoTrigger($a[0], "DEFINED");
return $ret;
}
@@ -1572,7 +1575,8 @@ CommandTrigger($$)
my ($cl, $param) = @_;
my ($dev, $state) = split(" ", $param, 2);
- return "Usage: trigger \n$namedef" if(!$state);
+ return "Usage: trigger \n$namedef" if(!$dev);
+ $state = "" if(!$state);
my @rets;
foreach my $sdev (devspec2array($dev)) {
@@ -1873,6 +1877,7 @@ DoTrigger($$)
my $ret = "";
foreach my $n (sort keys %defs) {
next if(!defined($defs{$n})); # Was deleted in a previous notify
+ next if($n eq $dev && defined($ns) && $ns eq "DEFINED");
if(defined($modules{$defs{$n}{TYPE}})) {
if($modules{$defs{$n}{TYPE}}{NotifyFn}) {
Log 5, "$dev trigger: Checking $n for notify";