perl::critic -5 done

This commit is contained in:
Philipp Wo 2020-04-19 21:46:53 +02:00
parent ba14eee4b1
commit fd70c8b5a4
1 changed files with 12 additions and 38 deletions

View File

@ -88,7 +88,6 @@ sub TadoAPI_Init($$)
my ($hash,$args) = @_; my ($hash,$args) = @_;
my $u = "wrong syntax: define <name> TadoAPI <username> <homeID> [<mobileID>]"; my $u = "wrong syntax: define <name> TadoAPI <username> <homeID> [<mobileID>]";
return $u if(int(@$args) < 2); return $u if(int(@$args) < 2);
return undef;
} }
sub TadoAPI_Define($$) sub TadoAPI_Define($$)
@ -141,7 +140,6 @@ sub TadoAPI_Define($$)
}else{ }else{
$hash->{STATE}="no password set"; $hash->{STATE}="no password set";
} }
return undef;
} }
sub TadoAPI_Set(@) { sub TadoAPI_Set(@) {
@ -369,7 +367,6 @@ sub TadoAPI_Get(@) {
} }
return $message if $message; return $message if $message;
return TadoAPI_Catch($@) if $@; return TadoAPI_Catch($@) if $@;
return undef;
} }
} }
@ -379,17 +376,13 @@ sub TadoAPI_Catch($) {
$exception =~ /^(.*)( at.*FHEM.*)$/; $exception =~ /^(.*)( at.*FHEM.*)$/;
return $1; return $1;
} }
return undef;
} }
sub TadoAPI_Undefine($$) { sub TadoAPI_Undefine($$) {
my ( $hash, $name ) = @_; my ( $hash, $name ) = @_;
RemoveInternalTimer($hash); RemoveInternalTimer($hash);
#todo remove tokenfile #todo remove tokenfile
return undef;
} }
sub TadoAPI_CheckStatus(@){ sub TadoAPI_CheckStatus(@){
@ -408,8 +401,6 @@ sub TadoAPI_CheckStatus(@){
#test if api is reachable #test if api is reachable
Log3 $name, $reqDebug, "TadoAPI $name" . ": " . "Request $AuthURL"; Log3 $name, $reqDebug, "TadoAPI $name" . ": " . "Request $AuthURL";
HttpUtils_NonblockingGet($param); HttpUtils_NonblockingGet($param);
return undef;
} }
sub TadoAPI_LoadToken(@){ sub TadoAPI_LoadToken(@){
@ -422,8 +413,8 @@ sub TadoAPI_LoadToken(@){
if($apiStatus){ if($apiStatus){
eval { eval {
open(TOKENFILE, '<', $tokenFileName) or die("ERROR: $!"); open(my $TOKENFILE, '<', $tokenFileName) or die("ERROR: $!");
$Token = decode_json(<TOKENFILE>)}; $Token = decode_json(<$TOKENFILE>)};
if($@ || $tokenLifeTime < gettimeofday()){ if($@ || $tokenLifeTime < gettimeofday()){
Log3 $name, 5, "TadoAPI $name" . ": " . "Error while loading: $@ ,requesting new one" if $@; Log3 $name, 5, "TadoAPI $name" . ": " . "Error while loading: $@ ,requesting new one" if $@;
Log3 $name, 5, "TadoAPI $name" . ": " . "Token is expired, requesting new one" if $tokenLifeTime < gettimeofday(); Log3 $name, 5, "TadoAPI $name" . ": " . "Token is expired, requesting new one" if $tokenLifeTime < gettimeofday();
@ -437,11 +428,10 @@ sub TadoAPI_LoadToken(@){
$Token = TadoAPI_TokenRefresh($hash); $Token = TadoAPI_TokenRefresh($hash);
} }
} }
close(TOKENFILE); close($TOKENFILE);
return $Token if $Token; return $Token if $Token;
} }
TadoAPI_CheckStatus($hash); TadoAPI_CheckStatus($hash);
return undef;
} }
sub TadoAPI_NewTokenRequest(@) { sub TadoAPI_NewTokenRequest(@) {
@ -486,9 +476,9 @@ sub TadoAPI_NewTokenRequest(@) {
Log3 $name, 3, "TadoAPI $name" . ": " . "NewTokenRequest: decode_json failed, invalid json. error: $@ "; Log3 $name, 3, "TadoAPI $name" . ": " . "NewTokenRequest: decode_json failed, invalid json. error: $@ ";
}else{ }else{
#write token data in file #write token data in file
open(TOKENFILE,">$tokenFileName") or die("ERROR: $!"); open(my $TOKENFILE, q{>} ,$tokenFileName) or die("ERROR: $!");
print TOKENFILE $data . "\n"; print $TOKENFILE $data . "\n";
close(TOKENFILE); close($TOKENFILE);
# token lifetime management # token lifetime management
$hash->{TOKEN_LIFETIME} = gettimeofday() + $decoded_data->{'expires_in'}; $hash->{TOKEN_LIFETIME} = gettimeofday() + $decoded_data->{'expires_in'};
@ -507,8 +497,8 @@ sub TadoAPI_TokenRefresh(@) {
# load token # load token
eval { eval {
open(TOKENFILE, '<', $hash->{TOKEN_FILE}) or die("ERROR: $!"); open(my $TOKENFILE, '<', $hash->{TOKEN_FILE}) or die("ERROR: $!");
$TokenData = decode_json(<TOKENFILE>)}; $TokenData = decode_json(<$TOKENFILE>)};
$data = { $data = {
client_id => $client_id, client_id => $client_id,
@ -546,7 +536,7 @@ sub TadoAPI_TokenRefresh(@) {
$hash->{STATE}="error"; $hash->{STATE}="error";
}else{ }else{
#write token data in file #write token data in file
open(TOKENFILE,">$tokenFileName") or die("ERROR: $!"); open(my $TOKENFILE, q{>}, $tokenFileName) or die("ERROR: $!");
print TOKENFILE $data . "\n"; print TOKENFILE $data . "\n";
close(TOKENFILE); close(TOKENFILE);
@ -580,8 +570,6 @@ sub TadoAPI_Update(@){
# update subs # update subs
TadoAPI_UpdateFn($hash); TadoAPI_UpdateFn($hash);
return undef;
} }
######################## tado methods ######################## ######################## tado methods ########################
@ -788,7 +776,6 @@ sub TadoAPI_callback($){
$hash->{STATE}="error"; $hash->{STATE}="error";
Log3 $name, 3, "TadoAPI $name" . ": " . "API error: apiStatus $apiStatus ($err)"; Log3 $name, 3, "TadoAPI $name" . ": " . "API error: apiStatus $apiStatus ($err)";
} }
return undef;
} }
sub TadoAPI_UpdateAllZoneReadingsCallback($){ sub TadoAPI_UpdateAllZoneReadingsCallback($){
@ -799,7 +786,6 @@ sub TadoAPI_UpdateAllZoneReadingsCallback($){
if($err ne "") if($err ne "")
{ {
Log3 $name, 3, "Error in TadoAPI_UpdateZoneCallback while requesting ".$param->{url}." - $err"; Log3 $name, 3, "Error in TadoAPI_UpdateZoneCallback while requesting ".$param->{url}." - $err";
return undef;
} }
elsif($data ne "") elsif($data ne "")
{ {
@ -856,7 +842,6 @@ sub Tado_UpdateZoneOverlayCallback($)
if($err ne "") if($err ne "")
{ {
Log3 $name, 3, "Error in UpdateZoneOverlayCallback while requesting ".$param->{url}." - $err"; Log3 $name, 3, "Error in UpdateZoneOverlayCallback while requesting ".$param->{url}." - $err";
return undef;
} }
elsif($data ne "") elsif($data ne "")
@ -896,7 +881,6 @@ sub TadoAPI_LogInfoCallback($){
if($err ne "") if($err ne "")
{ {
Log3 $name, 3, "Error in LogInfoCallback while requesting ".$param->{url}." - $err"; Log3 $name, 3, "Error in LogInfoCallback while requesting ".$param->{url}." - $err";
return undef;
} }
elsif($data ne "") elsif($data ne "")
@ -1034,7 +1018,6 @@ sub TadoAPI_GetZoneInfo(@) {
HttpUtils_NonblockingGet($request); HttpUtils_NonblockingGet($request);
} }
} }
return undef;
} }
sub TadoAPI_SetGeoById(@){ sub TadoAPI_SetGeoById(@){
@ -1125,7 +1108,6 @@ sub TadoAPI_GetHomeId(@){
} }
} }
} }
return undef;
} }
sub TadoAPI_GetGeoById(@){ sub TadoAPI_GetGeoById(@){
@ -1176,7 +1158,6 @@ sub TadoAPI_GetGeoById(@){
Log3 $name, 5, "TadoAPI $name" . ": " . "GetGeoById: parsing passed item"; Log3 $name, 5, "TadoAPI $name" . ": " . "GetGeoById: parsing passed item";
return my ($setting, $distance) = TadoAPI_ParseMobileItem($hash, $item); return my ($setting, $distance) = TadoAPI_ParseMobileItem($hash, $item);
} }
return undef;
} }
sub TadoAPI_ParseMobileItem(@){ sub TadoAPI_ParseMobileItem(@){
@ -1252,7 +1233,6 @@ sub TadoAPI_GetMobileDevices(@) {
} }
} }
} }
return undef;
} }
sub TadoAPI_GetZoneCount(@) { sub TadoAPI_GetZoneCount(@) {
@ -1300,7 +1280,6 @@ sub TadoAPI_GetZoneCount(@) {
} }
} }
} }
return undef;
} }
sub TadoAPI_GetZoneNameById(@) { sub TadoAPI_GetZoneNameById(@) {
@ -1316,7 +1295,6 @@ sub TadoAPI_GetZoneNameById(@) {
} }
} }
Log3 $name, 3, "TadoAPI $name" . ": " . "Error GetZoneNameById: Wrong zone ID ($zoneID)"; Log3 $name, 3, "TadoAPI $name" . ": " . "Error GetZoneNameById: Wrong zone ID ($zoneID)";
return undef;
} }
sub TadoAPI_GetZoneReadingsById(@){ sub TadoAPI_GetZoneReadingsById(@){
@ -1370,7 +1348,6 @@ sub TadoAPI_GetZoneReadingsById(@){
} }
} }
} }
return undef;
} }
sub TadoAPI_GetTadoDevices(@) { sub TadoAPI_GetTadoDevices(@) {
@ -1416,7 +1393,6 @@ sub TadoAPI_GetTadoDevices(@) {
} }
} }
} }
return undef;
} }
###################################################### ######################################################
@ -1429,7 +1405,7 @@ sub TadoAPI_storePassword($$)
my $key = getUniqueId().$index; my $key = getUniqueId().$index;
my $e_pwd = ""; my $e_pwd = "";
if (eval "use Digest::MD5;1") if (eval {use Digest::MD5;1})
{ {
$key = Digest::MD5::md5_hex(unpack "H*", $key); $key = Digest::MD5::md5_hex(unpack "H*", $key);
$key .= Digest::MD5::md5_hex($key); $key .= Digest::MD5::md5_hex($key);
@ -1461,12 +1437,11 @@ sub TadoAPI_readPassword($)
if ( defined($error) ) if ( defined($error) )
{ {
Log3 $name,3, "$name, cant't read Tado password from FhemUtils/uniqueID: $error"; Log3 $name,3, "$name, cant't read Tado password from FhemUtils/uniqueID: $error";
return undef;
} }
if ( defined($password) ) if ( defined($password) )
{ {
if (eval "use Digest::MD5;1") if (eval {use Digest::MD5;1})
{ {
$key = Digest::MD5::md5_hex(unpack "H*", $key); $key = Digest::MD5::md5_hex(unpack "H*", $key);
$key .= Digest::MD5::md5_hex($key); $key .= Digest::MD5::md5_hex($key);
@ -1485,7 +1460,6 @@ sub TadoAPI_readPassword($)
else else
{ {
Log3 $name,3,"$name, no Tado password found in FhemUtils/uniqueID"; Log3 $name,3,"$name, no Tado password found in FhemUtils/uniqueID";
return undef;
} }
} }
@ -1569,4 +1543,4 @@ sub TadoAPI_readPassword($)
=end html =end html
# Ende der Commandref # Ende der Commandref
=cut =cut