2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-28 17:12:32 +00:00

inform timer and \n for fhem commands

git-svn-id: https://svn.fhem.de/fhem/trunk@241 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2008-09-14 12:53:39 +00:00
parent a768e941f8
commit 4d3607be42

View File

@ -145,7 +145,7 @@ my $nextat; # Time when next timer will be triggered.
my $intAtCnt=0; my $intAtCnt=0;
my $reread_active = 0; my $reread_active = 0;
my $AttrList = "room comment"; my $AttrList = "room comment";
my $cvsid = '$Id: fhem.pl,v 1.54 2008-09-06 08:33:55 rudolfkoenig Exp $'; my $cvsid = '$Id: fhem.pl,v 1.55 2008-09-14 12:53:39 rudolfkoenig Exp $';
my $namedef = my $namedef =
"where <name> is either:\n" . "where <name> is either:\n" .
"- a single device name\n" . "- a single device name\n" .
@ -182,7 +182,7 @@ my %cmds = (
"include" => { Fn=>"CommandInclude", "include" => { Fn=>"CommandInclude",
Hlp=>"<filename>,read the commands from <filenname>" }, Hlp=>"<filename>,read the commands from <filenname>" },
"inform" => { Fn=>"CommandInform", "inform" => { Fn=>"CommandInform",
Hlp=>"{on|off},echo all commands and events to this client" }, Hlp=>"{on|timer|off},echo all commands and events to this client" },
"list" => { Fn=>"CommandList", "list" => { Fn=>"CommandList",
Hlp=>"[devspec],list definitions and status info" }, Hlp=>"[devspec],list definitions and status info" },
"modify" => { Fn=>"CommandModify", "modify" => { Fn=>"CommandModify",
@ -505,9 +505,10 @@ AnalyzeCommand($$)
{ {
my ($cl, $cmd) = @_; my ($cl, $cmd) = @_;
$cmd =~ s/^[ \t]*//; # Strip space $cmd =~ s/^(\\\n|[ \t])*//; # Strip space or \\n at the begginning
$cmd =~ s/[ \t]*$//; $cmd =~ s/[ \t]*$//;
Log 5, "Cmd: >$cmd<"; Log 5, "Cmd: >$cmd<";
return if(!$cmd); return if(!$cmd);
@ -1589,9 +1590,15 @@ CommandInform($$)
return; return;
} }
return "Usage: inform {on|off}" if($param !~ m/^(on|off)$/i); $param = lc($param);
$client{$cl}{inform} = ($param =~ m/on/i);
Log 4, "Setting inform to " . ($client{$cl}{inform} ? "on" : "off"); return "Usage: inform {on|off}" if($param !~ m/^(on|off|timer)$/);
if($param =~ m/off/) {
delete($client{$cl}{inform});
} else {
$client{$cl}{inform} = $param;
Log 4, "Setting inform to $param";
}
return undef; return undef;
} }
@ -1829,10 +1836,13 @@ DoTrigger($$)
# Inform # Inform
foreach my $c (keys %client) { # Do client loop first, is cheaper foreach my $c (keys %client) { # Do client loop first, is cheaper
next if(!$client{$c}{inform}); next if(!$client{$c}{inform});
my $tn = TimeNow();
for(my $i = 0; $i < $max; $i++) { for(my $i = 0; $i < $max; $i++) {
my $state = $defs{$dev}{CHANGED}[$i]; my $state = $defs{$dev}{CHANGED}[$i];
my $fe = "$dev:$state"; my $fe = "$dev:$state";
syswrite($client{$c}{fd}, "$defs{$dev}{TYPE} $dev $state\n"); syswrite($client{$c}{fd},
($client{$c}{inform} eq "timer" ? "$tn " : "") .
"$defs{$dev}{TYPE} $dev $state\n");
} }
} }