2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-05-05 02:19:31 +00:00

HMCCU: Replaced FHEM minmax functions

git-svn-id: https://svn.fhem.de/fhem/trunk@21452 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
zap 2020-03-19 13:16:06 +00:00
parent 6ef942e884
commit 3e674315b5
4 changed files with 42 additions and 26 deletions

View File

@ -4,7 +4,7 @@
#
# $Id$
#
# Version 4.3.022
# Version 4.3.023
#
# Module for communication between FHEM and Homematic CCU2/3.
#
@ -52,7 +52,7 @@ my %HMCCU_CUST_CHN_DEFAULTS;
my %HMCCU_CUST_DEV_DEFAULTS;
# HMCCU version
my $HMCCU_VERSION = '4.3.022';
my $HMCCU_VERSION = '4.3.023';
# Constants and default values
my $HMCCU_MAX_IOERRORS = 100;
@ -353,6 +353,8 @@ sub HMCCU_GetDutyCycle ($);
sub HMCCU_GetHMState ($$$);
sub HMCCU_GetIdFromIP ($$);
sub HMCCU_GetTimeSpec ($);
sub HMCCU_Max ($$);
sub HMCCU_Min ($$);
sub HMCCU_MaxHashEntries ($$);
sub HMCCU_RefToString ($);
sub HMCCU_ResolveName ($$);
@ -1378,7 +1380,7 @@ sub HMCCU_DelayedShutdown ($)
# HMCCU_Log ($hash, 3, "DelayedShutdown()");
my $delay = max (AttrVal ("global", "maxShutdownDelay", 10)-2, 0);
my $delay = HMCCU_Max (AttrVal ("global", "maxShutdownDelay", 10)-2, 0);
# Shutdown RPC server
if (!exists ($hash->{hmccu}{delayedShutdown})) {
@ -7043,7 +7045,7 @@ sub HMCCU_UpdateCB ($$$)
my $c_ok = HMCCU_UpdateMultipleDevices ($hash, \%events);
my $c_err = 0;
$c_err = max($param->{devCount}-$c_ok, 0) if (exists ($param->{devCount}));
$c_err = HMCCU_Max($param->{devCount}-$c_ok, 0) if (exists ($param->{devCount}));
HMCCU_Log ($hash, 2, "Update success=$c_ok failed=$c_err") if ($logcount);
}
@ -7592,6 +7594,20 @@ sub HMCCU_GetHMState ($$$)
return @hmstate;
}
sub HMCCU_Min ($$)
{
my ($a, $b) = @_;
return $a < $b ? $a : $b;
}
sub HMCCU_Max ($$)
{
my ($a, $b) = @_;
return $a > $b ? $a : $b;
}
######################################################################
# Calculate time difference in seconds between current time and
# specified timestamp

View File

@ -4,7 +4,7 @@
#
# $Id$
#
# Version 4.3.010
# Version 4.3.011
#
# (c) 2020 zap (zap01 <at> t-online <dot> de)
#
@ -259,7 +259,7 @@ sub HMCCUCHN_Set ($@)
return HMCCU_SetError ($hash, $usage) if (scalar (keys %dpval) < 1);
$rc = HMCCU_SetMultipleDatapoints ($hash, \%dpval);
return HMCCU_SetError ($hash, min(0, $rc));
return HMCCU_SetError ($hash, HMCCU_Min(0, $rc));
}
elsif ($opt eq 'control') {
return HMCCU_SetError ($hash, -14) if ($cd eq '');
@ -272,7 +272,7 @@ sub HMCCUCHN_Set ($@)
$rc = HMCCU_SetMultipleDatapoints ($hash,
{ "001.$ccuif.$ccuaddr.$cd" => HMCCU_Substitute ($objvalue, $statevals, 1, undef, '') }
);
return HMCCU_SetError ($hash, min(0, $rc));
return HMCCU_SetError ($hash, HMCCU_Min(0, $rc));
}
elsif ($opt =~ /^($hash->{statevals})$/) {
my $cmd = $1;
@ -287,7 +287,7 @@ sub HMCCUCHN_Set ($@)
$rc = HMCCU_SetMultipleDatapoints ($hash,
{ "001.$ccuif.$ccuaddr.$sd" => HMCCU_Substitute ($objvalue, $statevals, 1, undef, '') }
);
return HMCCU_SetError ($hash, min(0, $rc));
return HMCCU_SetError ($hash, HMCCU_Min(0, $rc));
}
elsif ($opt eq 'toggle') {
return HMCCU_SetError ($hash, -15) if ($statevals eq '' || !exists($hash->{statevals}));
@ -322,7 +322,7 @@ sub HMCCUCHN_Set ($@)
$rc = HMCCU_SetMultipleDatapoints ($hash,
{ "001.$objname" => HMCCU_Substitute ($objvalue, $statevals, 1, undef, '') }
);
return HMCCU_SetError ($hash, min(0, $rc));
return HMCCU_SetError ($hash, HMCCU_Min(0, $rc));
}
elsif ($opt eq 'pct' || $opt eq 'up' || $opt eq 'down') {
return HMCCU_SetError ($hash, "Can't find LEVEL datapoint for device type $ccutype")
@ -366,11 +366,11 @@ sub HMCCUCHN_Set ($@)
return HMCCU_SetError ($hash, $rc, $result) if ($rc < 0);
# Set level
my $objvalue = min(max($result+$delta,0),100);
my $objvalue = HMCCU_Min(HMCCU_Max($result+$delta,0),100);
$rc = HMCCU_SetMultipleDatapoints ($hash, { "001.$objname" => $objvalue });
}
return HMCCU_SetError ($hash, min(0, $rc));
return HMCCU_SetError ($hash, HMCCU_Min(0, $rc));
}
elsif ($opt eq 'on-for-timer' || $opt eq 'on-till') {
return HMCCU_SetError ($hash, -15) if ($statevals eq '' || !exists($hash->{statevals}));
@ -395,7 +395,7 @@ sub HMCCUCHN_Set ($@)
"001.$ccuif.$ccuaddr.ON_TIME" => $timespec,
"002.$ccuif.$ccuaddr.$sd" => HMCCU_Substitute ("on", $statevals, 1, undef, '')
});
return HMCCU_SetError ($hash, min(0, $rc));
return HMCCU_SetError ($hash, HMCCU_Min(0, $rc));
}
elsif ($opt eq 'clear') {
my $rnexp = shift @$a;
@ -412,7 +412,7 @@ sub HMCCUCHN_Set ($@)
($ccuobj, undef) = HMCCU_SplitChnAddr ($ccuaddr);
}
($rc, $result) = HMCCU_RPCRequest ($hash, "putParamset", $ccuobj, "MASTER", $h);
return HMCCU_SetError ($hash, min(0, $rc));
return HMCCU_SetError ($hash, HMCCU_Min(0, $rc));
}
elsif ($opt eq 'rpcparameter') {
return HMCCU_SetError ($hash, "Usage: set $name rpcparameter [MASTER|VALUES] {parameter}={value} [...]")
@ -430,7 +430,7 @@ sub HMCCUCHN_Set ($@)
return HMCCU_SetError ($hash, "Key must be MASTER or VALUES");
}
return HMCCU_SetError ($hash, min(0, $rc));
return HMCCU_SetError ($hash, HMCCU_Min(0, $rc));
}
elsif ($opt eq 'defaults') {
$rc = HMCCU_SetDefaults ($hash);

View File

@ -414,7 +414,7 @@ sub HMCCUDEV_Set ($@)
return HMCCU_SetError ($hash, $usage) if (scalar (keys %dpval) < 1);
$rc = HMCCU_SetMultipleDatapoints ($hash, \%dpval);
return HMCCU_SetError ($hash, min(0, $rc));
return HMCCU_SetError ($hash, HMCCU_Min(0, $rc));
}
elsif ($opt eq 'control') {
return HMCCU_SetError ($hash, -12) if ($cc eq '');
@ -429,7 +429,7 @@ sub HMCCUDEV_Set ($@)
$rc = HMCCU_SetMultipleDatapoints ($hash,
{ "001.$ccuif.$ccuaddr:$cc.$cd" => HMCCU_Substitute ($objvalue, $statevals, 1, undef, '') }
);
return HMCCU_SetError ($hash, min(0, $rc));
return HMCCU_SetError ($hash, HMCCU_Min(0, $rc));
}
elsif ($opt =~ /^($hash->{statevals})$/) {
my $cmd = $1;
@ -443,7 +443,7 @@ sub HMCCUDEV_Set ($@)
$rc = HMCCU_SetMultipleDatapoints ($hash,
{ "001.$ccuif.$ccuaddr:$sc.$sd" => HMCCU_Substitute ($objvalue, $statevals, 1, undef, '') }
);
return HMCCU_SetError ($hash, min(0, $rc));
return HMCCU_SetError ($hash, HMCCU_Min(0, $rc));
}
elsif ($opt eq 'toggle') {
return HMCCU_SetError ($hash, -15) if ($statevals eq '' || !exists($hash->{statevals}));
@ -482,7 +482,7 @@ sub HMCCUDEV_Set ($@)
$rc = HMCCU_SetMultipleDatapoints ($hash,
{ "001.$objname" => HMCCU_Substitute ($objvalue, $statevals, 1, undef, '') }
);
return HMCCU_SetError ($hash, min(0, $rc));
return HMCCU_SetError ($hash, HMCCU_Min(0, $rc));
}
elsif ($opt eq 'pct' || $opt eq 'up' || $opt eq 'down') {
return HMCCU_SetError ($hash, -11) if ($sc eq '' && $cc eq '');
@ -538,11 +538,11 @@ sub HMCCUDEV_Set ($@)
return HMCCU_SetError ($hash, $rc, $result) if ($rc < 0);
# Set level
my $objvalue = min(max($result+$delta,0),100);
my $objvalue = HMCCU_Min(HMCCU_Max($result+$delta,0),100);
$rc = HMCCU_SetMultipleDatapoints ($hash, { "001.$objname" => $objvalue });
}
return HMCCU_SetError ($hash, min(0, $rc));
return HMCCU_SetError ($hash, HMCCU_Min(0, $rc));
}
elsif ($opt eq 'on-for-timer' || $opt eq 'on-till') {
return HMCCU_SetError ($hash, -15) if ($statevals eq '' || !exists($hash->{statevals}));
@ -566,7 +566,7 @@ sub HMCCUDEV_Set ($@)
"001.$ccuif.$ccuaddr:$sc.ON_TIME" => $timespec,
"002.$ccuif.$ccuaddr:$sc.$sd" => HMCCU_Substitute ("on", $statevals, 1, undef, '')
});
return HMCCU_SetError ($hash, min(0, $rc));
return HMCCU_SetError ($hash, HMCCU_Min(0, $rc));
}
elsif ($opt eq 'clear') {
my $rnexp = shift @$a;
@ -585,7 +585,7 @@ sub HMCCUDEV_Set ($@)
}
my ($rc, $res) = HMCCU_RPCRequest ($hash, "putParamset", $objname, "MASTER", $h);
return HMCCU_SetError ($hash, min(0, $rc));
return HMCCU_SetError ($hash, HMCCU_Min(0, $rc));
}
elsif ($opt eq 'rpcparameter') {
return HMCCU_SetError ($hash, "Usage: set $name rpcparameter { channel VALUES | [channel] MASTER } {parameter}={value} [...]")
@ -617,7 +617,7 @@ sub HMCCUDEV_Set ($@)
return HMCCU_SetError ($hash, "Key must be MASTER or VALUES");
}
return HMCCU_SetError ($hash, min(0, $rc));
return HMCCU_SetError ($hash, HMCCU_Min(0, $rc));
}
elsif ($opt eq 'defaults') {
my $rc = HMCCU_SetDefaults ($hash);

View File

@ -4,7 +4,7 @@
#
# $Id$
#
# Version 1.9
# Version 1.9.001
#
# Subprocess based RPC Server module for HMCCU.
#
@ -35,7 +35,7 @@ use SetExtensions;
######################################################################
# HMCCURPC version
my $HMCCURPCPROC_VERSION = '1.9';
my $HMCCURPCPROC_VERSION = '1.9.001';
# Maximum number of events processed per call of Read()
my $HMCCURPCPROC_MAX_EVENTS = 100;
@ -440,7 +440,7 @@ sub HMCCURPCPROC_DelayedShutdown ($)
# HMCCU_Log ($hash, 3, "DelayedShutdown()");
my $delay = max (AttrVal ("global", "maxShutdownDelay", 10)-2, 0);
my $delay = HMCCU_Max (AttrVal ("global", "maxShutdownDelay", 10)-2, 0);
# Shutdown RPC server
if (defined ($hmccu_hash) && exists ($hmccu_hash->{hmccu}{interfaces}{$ifname}{manager}) &&