2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-12 16:46:35 +00:00

eventMap changes

git-svn-id: https://svn.fhem.de/fhem/trunk@965 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2011-07-30 13:22:25 +00:00
parent 014ed12e86
commit 5c226df01a
4 changed files with 53 additions and 41 deletions

View File

@ -2,6 +2,7 @@
- bugfix: applying smallscreen attributes to firefox/opera
- feature: CUL_TX added (thanks to Peterp)
- feature: TCM120 / EnOcean parser added
- feature: eventMap enhanced
- 2011-07-08 (5.1)
- feature: smallscreen optimizations for iPhone

View File

@ -2,7 +2,7 @@
fw=$1
if test ! -f ../../$fw.tar.gz; then
echo "usage: makeimage <fhem-VERSION.tar.gz>"
echo "usage: makeimage <fhem-VERSION>"
echo "../../<fhem-VERSION>.tar.gz must exist"
exit 1
fi

View File

@ -1318,14 +1318,16 @@ A line ending with \ will be concatenated with the next one, so long lines
<a name="eventMap"></a>
<li>eventMap<br>
Exchange event or command names to a device specific version. This
will also be used to exchange set arguments (if possible).
Example:<ul><code>
Replace event names and set arguments. The value of this attribute
consists of a list of space separated values, each value is a colon
separated pair. The first part specifies the "old" value, the second
the new/desired value. If the first character is slash(/) or komma(,)
then split not by space but by this character, enabling to embed spaces.
Examples:<ul><code>
attr store eventMap on:open off:closed<br>
attr store eventMap /on-for-timer 10:open/off:closed/<br>
set store open
</code></ul>
The attribute applies to all set commands, events and to the device
state, but not to the other device READINGS.
</li><br>
<li><a href="#do_not_notify">do_not_notify</a></li><br>

View File

@ -66,7 +66,7 @@ sub Log($$);
sub OpenLogfile($);
sub PrintHash($$);
sub ReadingsVal($$$);
sub ReplaceEventMap($$);
sub ReplaceEventMap($$$);
sub ResolveDateWildcards($@);
sub RemoveInternalTimer($);
sub SecondsTillTomorrow($);
@ -167,7 +167,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.148 2011-07-24 11:53:11 rudolfkoenig Exp $';
my $cvsid = '$Id: fhem.pl,v 1.149 2011-07-30 13:22:25 rudolfkoenig Exp $';
my $namedef =
"where <name> is either:\n" .
"- a single device name\n" .
@ -1043,16 +1043,8 @@ DoSet(@)
my $dev = $a[0];
return "Please define $dev first" if(!$defs{$dev});
return "No set implemented for $dev" if(!$modules{$defs{$dev}{TYPE}}{SetFn});
if($attr{$dev}{eventMap}) {
foreach my $rv (split(" ", $attr{$dev}{eventMap})) {
my ($re, $val) = split(":", $rv, 2);
if($a[1] =~ m/$val/) {
$a[1] =~ s/$val/$re/;
last;
}
}
}
@a = ReplaceEventMap($dev, \@a, 0) if($attr{$dev}{eventMap});
my $ret = CallFn($dev, "SetFn", $defs{$dev}, @a);
return $ret if($ret);
@ -1724,25 +1716,18 @@ CommandSetstate($$)
my $d = $defs{$sdev};
# Detailed state with timestamp
if($a[1] =~ m/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} /) {
my @b = split(" ", $a[1], 4);
if($defs{$sdev}{TYPE} eq "FS20" && $b[2] ne "state") { # Compatibility
$b[3] = $b[2] . ($b[3] ? " $b[3]" : "");
$b[2] = "state";
}
my $tim = "$b[0] $b[1]";
ReplaceEventMap($sdev, $b[2]);
my $ret = CallFn($sdev, "StateFn", $d, $tim, $b[2], $b[3]);
if($a[1] =~ m/^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}) +([^ ].*)$/) {
my ($tim, $nameval) = ($1, $2);
my ($sname, $sval) = split(" ", $nameval, 2);
my $ret = CallFn($sdev, "StateFn", $d, $tim, $sname, $sval);
if($ret) {
push @rets, $ret;
next;
}
if(!$d->{READINGS}{$b[2]} || $d->{READINGS}{$b[2]}{TIME} lt $tim) {
$d->{READINGS}{$b[2]}{VAL} = $b[3];
$d->{READINGS}{$b[2]}{TIME} = $tim;
if(!$d->{READINGS}{$sname} || $d->{READINGS}{$sname}{TIME} lt $tim) {
$d->{READINGS}{$sname}{VAL} = $sval;
$d->{READINGS}{$sname}{TIME} = $tim;
}
} else {
@ -2068,9 +2053,9 @@ DoTrigger($$)
if($attr{$dev}{eventMap}) {
my $c = $defs{$dev}{CHANGED};
for(my $i = 0; $i < @{$c}; $i++) {
$c->[$i] = ReplaceEventMap($dev, $c->[$i]);
$c->[$i] = ReplaceEventMap($dev, $c->[$i], 1);
}
$defs{$dev}{STATE} = ReplaceEventMap($dev, $defs{$dev}{STATE});
$defs{$dev}{STATE} = ReplaceEventMap($dev, $defs{$dev}{STATE}, 1);
}
# STATE && {READINGS}{state} should be the same
@ -2503,19 +2488,43 @@ addToAttrList($)
}
sub
ReplaceEventMap($$)
ReplaceEventMap($$$)
{
my ($dev, $str) = @_;
return $str if(!$attr{$dev}{eventMap});
my ($dev, $str, $dir) = @_;
my $em = $attr{$dev}{eventMap};
return $str if(!$em);
foreach my $rv (split(" ", $attr{$dev}{eventMap})) {
my $sc = " "; # Split character
my $fc = substr($em, 0, 1); # First character of the eventmap
if($fc eq "," || $fc eq "/") {
$sc = $fc;
$em = substr($em, 1);
}
my $nstr = join(" ", @{$str}) if(!$dir);
my $changed;
foreach my $rv (split($sc, $em)) {
my ($re, $val) = split(":", $rv, 2);
if($str =~ m/$re/) {
$str =~ s/$re/$val/;
last;
next if(!defined($val));
if($dir) { # event -> Presentation
if($str =~ m/$re/) {
$str =~ s/$re/$val/;
$changed = 1;
last;
}
} else { # Setting event
if($nstr =~ m/$val/) {
$nstr =~ s/$val/$re/;
$changed = 1;
last;
}
}
}
return $str;
return $str if($dir);
return split(" ",$nstr) if($changed);
return @{$str};
}
sub