diff --git a/fhem/CHANGED b/fhem/CHANGED index 92809857b..b40fa09aa 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -58,6 +58,9 @@ - feature: a lot of new features and known 1-wire slaves to OWServer / OWDevice added (M. Fischer) - feature: set-extensions (additional set commands) for FS20, EnOcean, ZWave + - feature: added new command 'notice'. (M. Fischer) + - change: update supports the display and confirmation of system messages + via the new notice command (M. Fischer) - 2012-10-28 (5.3) - feature: added functions trim, ltrim, rtrim, UntoggleDirect, diff --git a/fhem/FHEM/98_update.pm b/fhem/FHEM/98_update.pm index 0bcc97d00..5c4035196 100644 --- a/fhem/FHEM/98_update.pm +++ b/fhem/FHEM/98_update.pm @@ -83,26 +83,6 @@ CommandUpdate($$) $branch = "SVN" if ($BRANCH eq "DEVELOPMENT"); $srcdir = $UPDATE{path}."/".lc($branch); - # check arguments for fheminfo advice - if (defined($args[1]) && uc($args[1]) eq "VIEWADVICE") { - $ret = optInFhemInfo(); - Log 1,"update Action required: please run 'update viewAdvice'"; - return $ret; - } - - # check for fheminfo settings - my $sendStatistics = AttrVal("global","sendStatistics",undef); - if(!defined($sendStatistics) || - ( defined($sendStatistics) && - lc($sendStatistics) ne "onupdate" && - lc($sendStatistics) ne "manually" && - lc($sendStatistics) ne "never" ) - ) { - $ret = optInFhemInfo(); - Log 1,"update Action required: please run 'update viewAdvice'"; - return $ret; - } - # check arguments if (defined($args[1]) && $args[1] eq "?" || (int(@args) > 3 && uc($args[1]) eq "HOUSEKEEPING") || @@ -143,7 +123,15 @@ CommandUpdate($$) $ret = update_DoHousekeeping($update); $ret = "nothing to do..." if (!$ret); } else { - $ret = update_DoUpdate($srcdir,$BRANCH,$update,$force,$cl); + my $unconfirmed; + my $notice; + ($notice,$unconfirmed) = update_CheckNotice("before"); + $ret .= $notice if(defined($notice)); + return $ret if($unconfirmed); + $ret .= update_DoUpdate($srcdir,$BRANCH,$update,$force,$cl); + ($notice,$unconfirmed) = update_CheckNotice("after"); + $ret .= $notice if(defined($notice)); + my $sendStatistics = AttrVal("global","sendStatistics",undef); if(lc($sendStatistics) eq "onupdate") { $ret .= "\n\n"; $ret .= AnalyzeCommandChain(undef, "fheminfo send"); @@ -153,6 +141,100 @@ CommandUpdate($$) return $ret; } +######################################## +sub +update_CheckNotice($) +{ + my ($position) = shift; + my $modpath = (-d "updatefhem.dir" ? "updatefhem.dir":$attr{global}{modpath}); + my $moddir = "$modpath/FHEM"; + my $noticeDir = "$moddir/FhemUtils"; + my $ret; + + my @published = split(",",AnalyzeCommandChain(undef, "notice get update 6")); + my @unconfirmed = split(",",AnalyzeCommandChain(undef, "notice get update 7")); + my @confirmed = split(",",AnalyzeCommandChain(undef, "notice get update 8")); + + # remove confirmed from published + my %c; + @c{@confirmed} = undef; + @published = grep {not exists $c{$_}} @published; + + my @merged = (@published,@unconfirmed); + my %unique = (); + foreach my $notice (@merged) { + $unique{$notice} ++; + } + my @noticeList = keys %unique; + + if(@noticeList) { + foreach my $notice (sort @noticeList) { + my $sendStatistics; + my $condition = AnalyzeCommandChain(undef, "notice condition $notice"); + if($condition) { + my @conditions = split(/\|/,$condition); + foreach my $pair (@conditions) { + my ($key,$val,$con) = split(":",$pair); + if(lc($key) eq "sendstatistics") { + # skip this message if attrib sendStatistics is already defined + $sendStatistics = AttrVal("global","sendStatistics",undef); + } + } + } + next if(defined($sendStatistics) && $sendStatistics ne ""); + my $cmdret = AnalyzeCommandChain(undef, "notice position $notice"); + if( defined($cmdret) && lc($cmdret) eq lc($position) || + ( defined($cmdret) && grep (m/^$notice$/,@unconfirmed) && lc($cmdret) eq "after") || + (!defined($cmdret) && grep (m/^$notice$/,@unconfirmed) && $position eq "before") || + (!defined($cmdret) && !grep (m/^$notice$/,@unconfirmed) && $position eq "after") ) { + $ret .= "==> Message-ID: $notice\n"; + my $noticeDE = AnalyzeCommandChain(undef, "notice view $notice noheader de"); + my $noticeEN = AnalyzeCommandChain(undef, "notice view $notice noheader en"); + if($noticeDE && $noticeEN) { + $ret .= "(English Translation: Please see below.)\n\n"; + $ret .= $noticeDE; + $ret .= "~~~~~~~~~~\n"; + $ret .= $noticeEN; + } elsif($noticeDE) { + $ret .= $noticeDE; + } elsif($noticeEN) { + $ret .= $noticeEN; + } else { + $ret .= "==> Message file is corrupt. Please report this!\n" + } + } + } + if(@unconfirmed) { + $ret .= "==> Action required:\n\n"; + if($position eq "before") { + $ret .= " There is at least one unconfirmed message. Before updating FHEM\n"; + $ret .= " these messages have to be confirmed first:\n"; + } else { + $ret .= " There is at least one unconfirmed message. You have to confirm\n"; + $ret .= " these messages before you can update FHEM again.\n"; + } + foreach my $notice (@unconfirmed) { + $ret .= " ID: $notice\n"; + Log 1,"update Action required: please run 'notice view $notice'"; + } + $ret .= "\n"; + $ret .= " To view a message (again), please enter 'notice view '.\n"; + $ret .= " To confirm a message, please enter 'notice confirm [value]'.\n"; + $ret .= " '[value]' is an optional argument. Please refer to the message,\n"; + $ret .= " whether the disclosure of '[value]' is necessary.\n\n"; + $ret .= " For further information please consult the manual for the command\n"; + $ret .= " 'notice' in the documentation of FHEM (commandref.html)."; + if($position eq "before") { + $ret .= "\n\n"; + $ret .= " The update is canceled for now."; + } + } + } else { + $ret = undef; + } + return ($ret,(@unconfirmed) ? 1 : 0); +} + ######################################## sub update_DoUpdate(@) @@ -905,153 +987,6 @@ update_MakeDirectory($) return $ret; } -######################################## -sub -optInFhemInfo() -{ - my $str; - - my $str_DE=<JsonList   list   modify   + notice   quit   reload   rename   diff --git a/fhem/docs/commandref_frame_DE.html b/fhem/docs/commandref_frame_DE.html index b5fc4d5ad..2b955fc9d 100644 --- a/fhem/docs/commandref_frame_DE.html +++ b/fhem/docs/commandref_frame_DE.html @@ -44,6 +44,7 @@ JsonList   list   modify   + notice   quit   reload   rename