1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main;
use strict;
use warnings;
use POSIX qw(strftime floor);
use Scalar::Util qw(looks_like_number);
use Switch;
sub MyFhem($) {
my ($cmd) = @_;
if ( $cmd =~ /([-_\w]+):([-_\w]+):([-_\w]+)(:([-_\w]+))?/ ) {
$cmd = "set $1 $2 $3";
my $check = { dev => $1, reading => $2, level => $3, retry => 0 };
smInternalTimer( "c_".$1."_".$2, time+( $5 // 3 )*60, "CheckActionDone", $check, 1 );
}
fhem($cmd);
}
my ( $notifytable_sec, $notifytable_min, $notifytable_hour, $notifytable_mday, $notifytable_mon,
$notifytable_year, $notifytable_wday, $notifytable_yday, $notifytable_isdst);
sub MyReadingsVal($$$) {
my ($dev, $rdg, $def) = @_;
my $r='';
if ( $dev eq "TIME" ) {
switch ($rdg) {
case 'hour' { $r = $notifytable_hour }
case 'hfhour' { $r = $notifytable_hour << 1 + ( $notifytable_min > 29 ? 1 : 0 ) }
case 'qhour' { $r = $notifytable_hour << 2 + floor( $notifytable_min/15 ) }
case 'minute' { $r = $notifytable_min }
case 0 { $r = $notifytable_min }
else { $r = undef }
}
} else {
$r = ReadingsVal( $dev, $rdg, $def );
}
return $r;
}
1 2 3 4 5 6 7 8 9 10 11
my $r = undef; my %codes = ( hour => sub{ $r = $notifytable_hour }, hfhour => sub{ $r = $notifytable_hour << 1 + ( $notifytable_min > 29 ? 1 : 0 ) }, qhour => sub{ $r = $notifytable_hour << 2 + floor( $notifytable_min/15 ) }, minute => sub{ $r = $notifytable_min }, 0 => sub{ $r = $notifytable_min }, ); $codes->{$rdg}->() if($codes->{$rdg}) ;
1 2 3 4 5 6 7 8 9
my $r = undef; my %codes = ( 'hour' => $notifytable_hour, 'hfhour' => $notifytable_hour << 1 + ( $notifytable_min > 29 ? 1 : 0 ), 'qhour' => $notifytable_hour << 2 + floor( $notifytable_min / 15 ), 'minute' => $notifytable_min, 0 => $notifytable_min ); if ( exists($codes{$rdg}) ) { $r = $codes{rdg}; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
sub MyReadingsVal { my ($dev, $rdg, $def) = @_; if ( $dev eq "TIME" ) { $rdg eq 'hour' and return $notifytable_hour; $rdg eq 'hfhour' and return $notifytable_hour << 1 + ( $notifytable_min > 29 ? 1 : 0 ); $rdg eq 'qhour' and return $notifytable_hour << 2 + floor( $notifytable_min/15 ); $rdg eq 'minute' and return $notifytable_min; $rdg eq 0 and return $notifytable_min; return undef; } else { return ReadingsVal( $dev, $rdg, $def ); } }
Guest SMarc@rosti: Wie gesagt komme ich aus einer anderen Ecke und bin für jede Anregung dankbar. Leider kann ich nicht einschätzen, was den Code z.B. Perl-Version abhängig macht. Eine Erklärung, was es tun soll, ist aber ebenfalls schwierig, da es ein Teil einer meiner Erweiterungen für das sehr umfangreiche FHEM-Projekt ist... Was findest Du denn z.B. gruselig?
Guest SMarcWas ist denn das Problem mit "Funktionsprototypen"
QuoteWarum erzeugt ( $5 // 3 ) ein Syntaxfehler?