From f9fde7f5828e0217a339ccab19300db08b24a62d Mon Sep 17 00:00:00 2001 From: HomeAuto_User Date: Fri, 27 Sep 2019 16:50:16 +0000 Subject: [PATCH] 88_Timer: fix code #103848 + added check load file git-svn-id: https://svn.fhem.de/fhem/trunk@20261 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 1 + fhem/FHEM/88_Timer.pm | 59 ++++++++++++++++++++++++++----------------- 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index ab50e7325..94a215c43 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,6 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - bugfix: 88_Timer: fix code #103848 + added check load file - feature: 95_Dashboard: new attr "dashboard_homeTab", "dashboard_webRefresh", new set command activateTab, bugfixes, comref revised - change: 49_SSCam: set compatibility to SVS version 8.2.6 diff --git a/fhem/FHEM/88_Timer.pm b/fhem/FHEM/88_Timer.pm index 9fee73cfd..b6072e275 100644 --- a/fhem/FHEM/88_Timer.pm +++ b/fhem/FHEM/88_Timer.pm @@ -26,17 +26,16 @@ my @names; my @designations; my $description_all; my $cnt_attr_userattr = 0; +my $language = uc(AttrVal("global", "language", "EN")); -if (!$attr{global}{language} || $attr{global}{language} eq "EN") { - @designations = ("sunrise","sunset","local time","","SR","SS"); - $description_all = "all"; # using in RegEx - @names = ("No.","Year","Month","Day","Hour","Minute","Second","Device or label","Action","Mon","Tue","Wed","Thu","Fri","Sat","Sun","active",""); -} - -if ($attr{global}{language} && $attr{global}{language} eq "DE") { +if ($language eq "DE") { @designations = ("Sonnenaufgang","Sonnenuntergang","lokale Zeit","Uhr","SA","SU"); $description_all = "alle"; # using in RegEx @names = ("Nr.","Jahr","Monat","Tag","Stunde","Minute","Sekunde","Gerät oder Bezeichnung","Aktion","Mo","Di","Mi","Do","Fr","Sa","So","aktiv",""); +} else { + @designations = ("SSnrise","SSnset","local time","","SR","SS"); + $description_all = "all"; # using in RegEx + @names = ("No.","Year","Month","Day","Hour","Minute","Second","Device or label","Action","Mon","Tue","Wed","Thu","Fri","Sat","SSn","active",""); } ########################## @@ -147,6 +146,7 @@ sub Timer_Set($$$@) { if ($cmd eq "sortTimer") { my @timers_unsortet; + my @userattr_values; my @attr_values_names; my $timer_nr_new; @@ -168,6 +168,7 @@ sub Timer_Set($$$@) { } my @timers_sort = sort @timers_unsortet; # Timer in neues Array sortieren + for (my $i=0; $i){ - if ($_ =~ /^Timer_\d{2},/) { + $line++; + if ($_ =~ /^(.*),.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,[0-1]$/) { chomp ($_); # Zeilenende entfernen push(@lines_readings,$_); # lines in array my @values = split(",",$_); # split line in array to check - $error++ if (scalar(@values) != 17); + #$error.= "- scalar arrray\n" if (scalar(@values) != 17); push(@attr_values_names, $values[0]."_set") if($values[8] eq "Def"); for (my $i=0;$i<@values;$i++) { - $error++ if ($i == 0 && $values[0] !~ /^Timer_\d{2}$/); - $error++ if ($i == 1 && $values[1] !~ /^\d{4}$|^$description_all$/); + $error.= "- ".$values[0]." is no $name description" if ($i == 0 && $values[0] !~ /^Timer_\d{2}$/); + $error.= "- ".$values[1]." invalid value" if ($i == 1 && $values[1] !~ /^\d{4}$|^$description_all$/); if ($i >= 2 && $i <= 5 && $values[$i] ne "$description_all") { - $error++ if ($i >= 2 && $i <= 3 && $values[$i] !~ /^\d{2}$/); - $error++ if ($i == 2 && ($values[2] * 1) < 1 && ($values[2] * 1) > 12); - $error++ if ($i == 3 && ($values[3] * 1) < 1 && ($values[3] * 1) > 31); + $error.= "- ".$values[$i]." not decimal" if ($i >= 2 && $i <= 3 && $values[$i] !~ /^\d{2}$/); + $error.= "- ".$values[2]." wrong value (allowed 1-12)" if ($i == 2 && ($values[2] * 1) < 1 && ($values[2] * 1) > 12); + $error.= "- ".$values[3]." wrong value (allowed 1-31)" if ($i == 3 && ($values[3] * 1) < 1 && ($values[3] * 1) > 31); if ($i >= 4 && $i <= 5 && $values[$i] ne $designations[4] && $values[$i] ne $designations[5]) { # SA -> 4 SU -> 5 - $error++ if ($i >= 4 && $i <= 5 && $values[$i] !~ /^\d{2}$/); - $error++ if ($i == 4 && ($values[4] * 1) > 23); - $error++ if ($i == 5 && ($values[5] * 1) > 59); + $error.= "- ".$values[$i]." not support" if ($i >= 4 && $i <= 5 && $values[$i] !~ /^\d{2}$/); + $error.= "- ".$values[4]." wrong value (allowed 00-23)" if ($i == 4 && ($values[4] * 1) > 23); + $error.= "- ".$values[5]." wrong value (allowed 00-59)" if ($i == 5 && ($values[5] * 1) > 59); } } - $error++ if ($i == 6 && $values[$i] % 10 != 0); - $error++ if ($i == 8 && not grep { $values[$i] eq $_ } @action); - $error++ if ($i >= 9 && $values[$i] ne "0" && $values[$i] ne "1"); + $error.= "- ".$values[$i]." is no % 10\n" if ($i == 6 && $values[$i] % 10 != 0); + $error.= "- ".$values[$i]." is no allowed action \n" if ($i == 8 && not grep { $values[$i] eq $_ } @action); + $error.= "- ".$values[$i]." is not 0 or 1 \n" if ($i >= 9 && $values[$i] ne "0" && $values[$i] ne "1"); - if ($error != 0) { + if ($error ne "") { close InputFile; Timer_Check($hash); - return "ERROR: your file is NOT valid! ($error)"; + $error.= "\nYour language is wrong! ($language)" if ($error =~ /-\s(all\s|alle\s|SA\s|SU\s|SR\s|SS\s)/); + return "ERROR: your file is NOT valid!\n\nline $line\n$error"; } } } @@ -646,6 +650,13 @@ sub Timer_FW_Detail($$$$) { for(var i=start; i'; @@ -673,6 +684,8 @@ sub FW_pushed_savebutton { Log3 $name, 5, "$name: FW_pushed_savebutton is running"; + return "ERROR: Comma not allowed in description!" if ($cnt_names > 17); + foreach my $d (sort keys %{$hash->{READINGS}}) { if ($d =~ /^Timer_(\d+)$/) { $timers_count++;