diff --git a/fhem/FHEM/98_fheminfo.pm b/fhem/FHEM/98_fheminfo.pm index c53934af9..c8549f8e9 100644 --- a/fhem/FHEM/98_fheminfo.pm +++ b/fhem/FHEM/98_fheminfo.pm @@ -68,7 +68,10 @@ CommandFheminfo($$) return $err; } - return "Unknown argument $args[0], usage: fheminfo [send]" if(@args && lc($args[0]) ne "send"); + return "Unknown argument $args[0], usage: fheminfo [send]" + if(@args && lc($args[0]) ne "send"); + return "Argument 'send' is not useful, if global attribute 'sendStatistics' is set to 'never'." + if(@args && lc($args[0]) eq "send" && lc(AttrVal("global","sendStatistics",undef)) eq "never"); my $branch = $DISTRIB_BRANCH; my $release = $DISTRIB_RELEASE; @@ -76,7 +79,7 @@ CommandFheminfo($$) my $arch = $Config{"archname"}; my $perl = $^V; my $uniqueID = AttrVal("global","uniqueID",undef); - my $sendStatistics = AttrVal("global","sendStatistics",1); + my $sendStatistics = AttrVal("global","sendStatistics",undef); my $moddir = $attr{global}{modpath}."/FHEM"; my $uidFile = $moddir."/FhemUtils/uniqueID"; @@ -119,7 +122,6 @@ CommandFheminfo($$) } $attr{global}{uniqueID} = $uidFile; - $attr{global}{sendStatistics} = $sendStatistics; my $ret = checkConfigFile($uidFile); @@ -202,6 +204,11 @@ CommandFheminfo($$) $str .= $modStr; } + my $transmitData = ($attr{global}{sendStatistics}) ? $attr{global}{sendStatistics} : "not set"; + $str .= "\n"; + $str .= "Transmitting this information during an update:\n"; + $str .= " $transmitData (Note: You can change this via the global attribute sendStatistics)\n"; + $ret = $str; if(@args != 0 && $args[0] eq "send") { @@ -221,7 +228,7 @@ CommandFheminfo($$) chop($contModels); $req->content("uniqueID=$uniqueID&system=$contInfo&modules=$contModules&models=$contModels"); } - + my $ua = LWP::UserAgent->new( agent => "Fhem/$release", timeout => 60); @@ -328,7 +335,6 @@ sub checkConfigFile($) { push(@newConfig,$line); if($line =~ /modpath/ && $done == 0) { push(@newConfig,"attr global uniqueID $uidFile\n"); - push(@newConfig,"attr global sendStatistics 1\n"); $done = 1; } } @@ -343,7 +349,7 @@ sub checkConfigFile($) { print $fh $_; } close $fh; - Log 1, "$name global attributes 'uniqueID' and 'sendStatistics' added to configfile $configFile"; + Log 1, "$name global attributes 'uniqueID' added to configfile $configFile"; } } @@ -473,9 +479,11 @@ sub checkModule($) {
  • sendStatistics
    This attribute is used in conjunction with the update command.
    - 0: prevents transmission of data during an update. + onUpdate: transfer of data on every update (recommended setting).
    - 1: transfer of data on every update. This is the default. + manually: manually transfer of data via the fheminfo send command. +
    + never: prevents transmission of data at anytime.

  • @@ -591,9 +599,11 @@ sub checkModule($) {
  • sendStatistics
    Dieses Attribut wird in Verbindung mit dem update Befehl verwendet.
    - 0: verhindert die Übertragung der Daten während eines Updates. + onUpdate: Überträgt die Daten bei jedem Update (empfohlene Einstellung).
    - 1: überträgt die Daten bei jedem Update. Dies ist die Standardeinstellung. + manually: Manuelle Überträgung der Daten über fheminfo send. +
    + never: Verhindert die Überträgung der Daten.

  • diff --git a/fhem/FHEM/98_update.pm b/fhem/FHEM/98_update.pm index 6ef1edee1..167b8d4d1 100644 --- a/fhem/FHEM/98_update.pm +++ b/fhem/FHEM/98_update.pm @@ -58,6 +58,19 @@ CommandUpdate($$) my $force = 0; my $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; + } + # split arguments my @args = split(/ +/,$param); @@ -83,6 +96,13 @@ 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 arguments if (defined($args[1]) && $args[1] eq "?" || (int(@args) > 3 && uc($args[1]) eq "HOUSEKEEPING") || @@ -124,6 +144,10 @@ CommandUpdate($$) $ret = "nothing to do..." if (!$ret); } else { $ret = update_DoUpdate($srcdir,$BRANCH,$update,$force,$cl); + if(lc($sendStatistics) eq "onupdate") { + $ret .= "\n\n"; + $ret .= CommandFheminfo(undef,"send"); + } } return $ret; @@ -881,6 +905,153 @@ update_MakeDirectory($) return $ret; } +######################################## +sub +optInFhemInfo() +{ + my $str; + + my $str_DE=<prepare(q{REPLACE INTO nodes (uniqueID,release,branch,os,arch,perl,lastSeen) VALUES(?,?,?,?,?,?,CURRENT_TIMESTAMP)}); $sth->execute($uniqueID,$release,$branch,$os,$arch,$perl); - # insert or update goe location of fhem node + # insert or update geo location of fhem node #### TODO: sprachcode 84.191.75.195 my @geo = getLocation($ip); @@ -659,23 +662,15 @@ sub checkColumn($$) { my ($t,$k) = @_; # get table info - $sth = $dbh->prepare("PRAGMA table_info($t)"); - $sth->execute(); + my %column = %{ $dbh->column_info(undef, undef,$t, undef)->fetchall_hashref('COLUMN_NAME') }; # check if column exists - my @row; - my @match = (); - while (@row = $sth->fetchrow_array()) { - @match = grep { /\b$k\b/ } @row; - last if(@match != 0); - } - - # create column if not exists - if(@match == 0) { + if(!exists $column{$k}) { $sth = $dbh->prepare("ALTER TABLE $t ADD COLUMN '$k' INTEGER DEFAULT 0"); $sth->execute(); + $sth->finish; } - $sth->finish; + return; } diff --git a/fhem/docs/commandref_frame.html b/fhem/docs/commandref_frame.html index 7ffdd84dd..81bac499a 100644 --- a/fhem/docs/commandref_frame.html +++ b/fhem/docs/commandref_frame.html @@ -1036,7 +1036,7 @@ A line ending with \ will be concatenated with the next one, so long lines shutdown.
    -
  • sendStatistics +
  • sendStatistics
  • statefile
    @@ -1050,7 +1050,7 @@ A line ending with \ will be concatenated with the next one, so long lines Used by the web frontend fhemweb.pl (webpgm2) as a Page title.

  • -
  • uniqueID +
  • uniqueID
  • updatebranch
    diff --git a/fhem/docs/commandref_frame_DE.html b/fhem/docs/commandref_frame_DE.html index c6d81bbf1..3031e4f62 100644 --- a/fhem/docs/commandref_frame_DE.html +++ b/fhem/docs/commandref_frame_DE.html @@ -1079,7 +1079,7 @@ Zeilen erstreckende Befehle, indem man keine \ am Zeilenende eingeben muss.

    gelöscht.

  • -
  • sendStatistics +
  • sendStatistics
  • statefile
    @@ -1095,7 +1095,7 @@ Zeilen erstreckende Befehle, indem man keine \ am Zeilenende eingeben muss.

    Festlegung des Seitentitels benutzt..

  • -
  • uniqueID +
  • uniqueID
  • updatebranch
    diff --git a/fhem/fhem.pl b/fhem/fhem.pl index b1527034d..01f3d05a9 100755 --- a/fhem/fhem.pl +++ b/fhem/fhem.pl @@ -204,7 +204,7 @@ $modules{Global}{AttrList} = "verbose:1,2,3,4,5 mseclog:1,0 version nofork:1,0 logdir holiday2we " . "autoload_undefined_devices:1,0 dupTimeout latitude longitude " . "backupcmd backupdir backupsymlink backup_before_update " . - "exclude_from_update motd updatebranch uniqueID sendStatistics ". + "exclude_from_update motd updatebranch uniqueID sendStatistics:onUpdate,manually,never ". "showInternalValues:1,0 "; $modules{Global}{AttrFn} = "GlobalAttr";