From 8a79464b760d5247ed4d737fb087d8dd0cf76387 Mon Sep 17 00:00:00 2001 From: rudolfkoenig Date: Sat, 23 Aug 2014 10:09:44 +0000 Subject: [PATCH] Utils.pm: add defInfo (Forum #26395) and move SVG_sec_to_time (Forum #26108) git-svn-id: https://svn.fhem.de/fhem/trunk@6446 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/98_SVG.pm | 22 --------- fhem/FHEM/99_Utils.pm | 109 +++++++++++++++++++++++++++++++++--------- 2 files changed, 87 insertions(+), 44 deletions(-) diff --git a/fhem/FHEM/98_SVG.pm b/fhem/FHEM/98_SVG.pm index 51fd10f48..bbbb17d1a 100755 --- a/fhem/FHEM/98_SVG.pm +++ b/fhem/FHEM/98_SVG.pm @@ -39,7 +39,6 @@ sub SVG_time_align($$); sub SVG_time_to_sec($); sub SVG_openFile($$$); -my ($SVG_lt, $SVG_ltstr); my %SVG_devs; # hash of from/to entries per device ##################################### @@ -1508,27 +1507,6 @@ SVG_render($$$$$$$$$) return $SVG_RET; } -sub -SVG_time_to_sec($) -{ - my ($str) = @_; - if(!$str) { - return 0; - } - my ($y,$m,$d,$h,$mi,$s) = split("[-_:]", $str); - $s = 0 if(!$s); - $mi= 0 if(!$mi); - $h = 0 if(!$h); - $d = 1 if(!$d); - $m = 1 if(!$m); - - if(!$SVG_ltstr || $SVG_ltstr ne "$y-$m-$d-$h") { # 2.5x faster - $SVG_lt = mktime(0,0,$h,$d,$m-1,$y-1900,0,0,-1); - $SVG_ltstr = "$y-$m-$d-$h"; - } - return $s+$mi*60+$SVG_lt; -} - sub SVG_fmtTime($$) { diff --git a/fhem/FHEM/99_Utils.pm b/fhem/FHEM/99_Utils.pm index b162b58ee..0f3028d77 100644 --- a/fhem/FHEM/99_Utils.pm +++ b/fhem/FHEM/99_Utils.pm @@ -83,6 +83,42 @@ abstime2rel($) return sprintf("%02d:%02d:%02d", $diff/3600, ($diff/60)%60, $diff%60); } +sub +defInfo($;$) +{ + my ($search,$internal) = @_; + $internal = 'DEF' unless defined($internal); + my @ret; + my @etDev = devspec2array($search); + foreach my $d (@etDev) { + next unless $d; + push @ret, $defs{$d}{$internal}; + } + return @ret; +} + +my ($SVG_lt, $SVG_ltstr); +sub +SVG_time_to_sec($) +{ + my ($str) = @_; + if(!$str) { + return 0; + } + my ($y,$m,$d,$h,$mi,$s) = split("[-_:]", $str); + $s = 0 if(!$s); + $mi= 0 if(!$mi); + $h = 0 if(!$h); + $d = 1 if(!$d); + $m = 1 if(!$m); + + if(!$SVG_ltstr || $SVG_ltstr ne "$y-$m-$d-$h") { # 2.5x faster + $SVG_lt = mktime(0,0,$h,$d,$m-1,$y-1900,0,0,-1); + $SVG_ltstr = "$y-$m-$d-$h"; + } + return $s+$mi*60+$SVG_lt; +} + ######## trim ##################################################### # What : cuts blankspaces from the beginning and end of a string @@ -203,7 +239,9 @@ IsInt($) # # To avoid this, we recommend following procedure: # -# 1. Create your own file 99_myUtils.pm from the template below +# 1. Create your own file 99_myUtils.pm from the template below, +# e.g. with FHEMWEB, Edit files, Editing 99_Utils.pm, and saving it as +# 99_myUtils.pm # 2. Put this file inside the ./FHEM directory # 3. Put your own functions into this new file # @@ -219,33 +257,60 @@ use POSIX; sub myUtils_Initialize($$) { - my ($hash) = @_; + my ($hash) = @_; } -# start with your own functions below this line - - -# behind your last function, we need the following 1; -# end-of-template + +
- Defined functions

- + Defined functions

+ =end html =cut