mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-04 11:26:55 +00:00
73_km200: Bugfix for faulty comparison method
git-svn-id: https://svn.fhem.de/fhem/trunk@8613 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
5462350e80
commit
959cbfa856
@ -1,4 +1,4 @@
|
||||
# $Id: 73_km200.pm 0050 2015-05-18 20:00:00Z Matthias_Deeke $
|
||||
# $Id: 73_km200.pm 0051 2015-05-21 20:00:00Z Matthias_Deeke $
|
||||
########################################################################################################################
|
||||
#
|
||||
# 73_km200.pm
|
||||
@ -200,6 +200,8 @@
|
||||
# 0050 18.05.2015 Sailor km200_ParseHttpResponseInit Correcting bug of floating point errors
|
||||
# 0050 18.05.2015 Sailor km200_ParseHttpResponseDyn Correcting bug of floating point errors
|
||||
# 0050 18.05.2015 Sailor km200_PostSingleService Implementing feature of posting complete "string of hash" to switchProgram
|
||||
# 0051 20.05.2015 Sailor km200_GetSingleService Correcting bug of floating point errors
|
||||
# 0051 21.05.2015 Sailor km200_PostSingleService Implementing switchPoint-hash by switchPoint-hash comparison
|
||||
########################################################################################################################
|
||||
|
||||
|
||||
@ -269,7 +271,7 @@ sub km200_Define($$)
|
||||
my $url = $a[2];
|
||||
my $km200_gateway_password = $a[3];
|
||||
my $km200_private_password = $a[4];
|
||||
my $ModuleVersion = "0050";
|
||||
my $ModuleVersion = "0051";
|
||||
|
||||
$hash->{NAME} = $name;
|
||||
$hash->{STATE} = "define";
|
||||
@ -1282,10 +1284,73 @@ sub km200_PostSingleService($)
|
||||
$ReReadContent =~ s/{"switchPoints"://;
|
||||
$ReReadContent =~ s/]}/]/g;
|
||||
|
||||
### Transform back into array of hashes
|
||||
eval
|
||||
{
|
||||
$ReReadContent = decode_json(encode_utf8($ReReadContent));
|
||||
$JsonContent = decode_json(encode_utf8($JsonContent));
|
||||
1;
|
||||
}
|
||||
or do
|
||||
{
|
||||
};
|
||||
|
||||
### Return value
|
||||
my $ReturnValue = "";
|
||||
if ($ReReadContent eq $JsonContent)
|
||||
### Set Counter for found items in SwitchPrograms
|
||||
my $FoundJsonItem = 0;
|
||||
|
||||
|
||||
### For every item of the array of SwitchPrograms to be send
|
||||
foreach my $ReReadItem (@{$ReReadContent})
|
||||
{
|
||||
### Set Counter for found items of ReRead values
|
||||
my $FoundReReadItem = 0;
|
||||
|
||||
### For every item of the array of SwitchPrograms after Re-Reading
|
||||
foreach my $JsonItem (@{$JsonContent})
|
||||
{
|
||||
|
||||
### If the current Switchprogram - hash does not have the same amount of keys
|
||||
if (%$ReReadItem != %$JsonItem)
|
||||
{
|
||||
### Do nothing
|
||||
#print "they don't have the same number of keys\n";
|
||||
}
|
||||
### If the current Switchprogram - hash do have the same amount of keys
|
||||
else
|
||||
{
|
||||
### Compare key names and values
|
||||
my %cmp = map { $_ => 1 } keys %$ReReadItem;
|
||||
for my $key (keys %$JsonItem)
|
||||
{
|
||||
last unless exists $cmp{$key};
|
||||
last unless $$ReReadItem{$key} eq $$JsonItem{$key};
|
||||
delete $cmp{$key};
|
||||
}
|
||||
if (%cmp)
|
||||
{
|
||||
### Do nothing
|
||||
#print "they don't have the same keys or values\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
### Inkrement Counter
|
||||
$FoundReReadItem = 1;
|
||||
#print "they have the same keys and values\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
### If item has been found
|
||||
if ($FoundReReadItem == 1)
|
||||
{
|
||||
### Inkrement Counter for found identical SwitchPoints
|
||||
$FoundJsonItem++;
|
||||
}
|
||||
}
|
||||
|
||||
my $ReturnValue;
|
||||
|
||||
if ($FoundJsonItem == @{$ReReadContent})
|
||||
{
|
||||
$ReturnValue = "The service " . $Service . " has been changed succesfully!";
|
||||
if ($hash->{CONSOLEMESSAGE} == true) {print("Writing $Service succesfully \n");}
|
||||
@ -1351,9 +1416,73 @@ sub km200_PostSingleService($)
|
||||
$ReReadContent =~ s/{"switchPoints"://;
|
||||
$ReReadContent =~ s/]}/]/g;
|
||||
|
||||
### Return value
|
||||
my $ReturnValue = "";
|
||||
if ($ReReadContent eq $JsonContent)
|
||||
### Transform back into array of hashes
|
||||
eval
|
||||
{
|
||||
$ReReadContent = decode_json(encode_utf8($ReReadContent));
|
||||
$JsonContent = decode_json(encode_utf8($JsonContent));
|
||||
1;
|
||||
}
|
||||
or do
|
||||
{
|
||||
};
|
||||
|
||||
### Set Counter for found items in SwitchPrograms
|
||||
my $FoundJsonItem = 0;
|
||||
|
||||
|
||||
### For every item of the array of SwitchPrograms to be send
|
||||
foreach my $ReReadItem (@{$ReReadContent})
|
||||
{
|
||||
### Set Counter for found items of ReRead values
|
||||
my $FoundReReadItem = 0;
|
||||
|
||||
### For every item of the array of SwitchPrograms after Re-Reading
|
||||
foreach my $JsonItem (@{$JsonContent})
|
||||
{
|
||||
|
||||
### If the current Switchprogram - hash does not have the same amount of keys
|
||||
if (%$ReReadItem != %$JsonItem)
|
||||
{
|
||||
### Do nothing
|
||||
#print "they don't have the same number of keys\n";
|
||||
}
|
||||
### If the current Switchprogram - hash do have the same amount of keys
|
||||
else
|
||||
{
|
||||
### Compare key names and values
|
||||
my %cmp = map { $_ => 1 } keys %$ReReadItem;
|
||||
for my $key (keys %$JsonItem)
|
||||
{
|
||||
last unless exists $cmp{$key};
|
||||
last unless $$ReReadItem{$key} eq $$JsonItem{$key};
|
||||
delete $cmp{$key};
|
||||
}
|
||||
if (%cmp)
|
||||
{
|
||||
### Do nothing
|
||||
#print "they don't have the same keys or values\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
### Inkrement Counter
|
||||
$FoundReReadItem = 1;
|
||||
#print "they have the same keys and values\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
### If item has been found
|
||||
if ($FoundReReadItem == 1)
|
||||
{
|
||||
### Inkrement Counter for found identical SwitchPoints
|
||||
$FoundJsonItem++;
|
||||
}
|
||||
}
|
||||
|
||||
my $ReturnValue;
|
||||
|
||||
if ($FoundJsonItem == @{$ReReadContent})
|
||||
{
|
||||
$ReturnValue = "The service " . $Service . " has been changed succesfully!";
|
||||
if ($hash->{CONSOLEMESSAGE} == true) {print("Writing $Service succesfully \n");}
|
||||
@ -1643,9 +1772,11 @@ sub km200_GetSingleService($)
|
||||
foreach my $item (@{ $json->{switchPoints} })
|
||||
{
|
||||
### Create string for time and switchpoint in fixed format and write part of Reading String
|
||||
my $temptime = $item->{time} / 60;
|
||||
|
||||
my $time = $item->{time};
|
||||
my $temptime = $time / 60;
|
||||
my $temptimeHH = int($temptime);
|
||||
my $temptimeMM = ($temptime - $temptimeHH) * 60;
|
||||
my $temptimeMM = ($time - ($temptimeHH * 60));
|
||||
|
||||
$temptimeHH = sprintf ('%02d', $temptimeHH);
|
||||
$temptimeMM = sprintf ('%02d', $temptimeMM);
|
||||
@ -2437,6 +2568,8 @@ sub km200_ParseHttpResponseInit($)
|
||||
@{$hash->{Secret}{KM200DYNSERVICES}} = @KM200_DynServices;
|
||||
@{$hash->{Secret}{KM200STATSERVICES}} = @KM200_StatServices;
|
||||
|
||||
|
||||
### Reset flag for initialisation
|
||||
$hash->{status}{FlagInitRequest} = false;
|
||||
|
||||
|
||||
@ -2495,12 +2628,12 @@ sub km200_GetDynService($)
|
||||
my ($hash, $def) = @_;
|
||||
my $km200_gateway_host = $hash->{URL};
|
||||
my $name = $hash->{NAME};
|
||||
$hash->{status}{FlagDynRequest} = true;
|
||||
$hash->{STATE} = "Polling";
|
||||
my @KM200_DynServices = @{$hash->{Secret}{KM200DYNSERVICES}};
|
||||
my $ServiceCounterDyn = $hash->{temp}{ServiceCounterDyn};
|
||||
my $PollingTimeout = $hash->{POLLINGTIMEOUT};
|
||||
|
||||
### If at least one service to be polled is available
|
||||
if (@KM200_DynServices != 0)
|
||||
{
|
||||
my $Service = $KM200_DynServices[$ServiceCounterDyn];
|
||||
@ -2524,8 +2657,13 @@ sub km200_GetDynService($)
|
||||
callback => \&km200_ParseHttpResponseDyn
|
||||
};
|
||||
|
||||
### Set Status Flag in order state running dynamic request
|
||||
$hash->{status}{FlagDynRequest} = true;
|
||||
|
||||
### Get data
|
||||
HttpUtils_NonblockingGet($param);
|
||||
}
|
||||
### If no service to be polled is available
|
||||
else
|
||||
{
|
||||
Log3 $name, 5, $name . " : No dynamic values available to be read. Skipping download.";
|
||||
@ -2550,6 +2688,9 @@ sub km200_ParseHttpResponseDyn($)
|
||||
|
||||
Log3 $name, 5, $name. " : Parsing response of dynamic service received for: " . $Service;
|
||||
|
||||
### Reset Status Flag
|
||||
$hash->{status}{FlagDynRequest} = false;
|
||||
|
||||
if($err ne "")
|
||||
{
|
||||
Log3 $name, 2, $name . " : ERROR: Service: ".$Service. ": No proper Communication with Gateway: " .$err;
|
||||
@ -2886,6 +3027,11 @@ sub km200_GetStatService($)
|
||||
header => "agent: TeleHeater/2.2.3\r\nUser-Agent: TeleHeater/2.2.3\r\nAccept: application/json",
|
||||
callback => \&km200_ParseHttpResponseStat
|
||||
};
|
||||
|
||||
### Set Status Flag in order state running static request
|
||||
$hash->{status}{FlagStatRequest} = true;
|
||||
|
||||
### Get data
|
||||
HttpUtils_NonblockingGet($param);
|
||||
}
|
||||
else
|
||||
@ -2912,6 +3058,9 @@ sub km200_ParseHttpResponseStat($)
|
||||
|
||||
Log3 $name, 5, $name. " : Parsing response of static service received for: " . $Service;
|
||||
|
||||
### Reset Status Flag
|
||||
$hash->{status}{FlagStatRequest} = false;
|
||||
|
||||
if($err ne "")
|
||||
{
|
||||
Log3 $name, 2, $name . " : ERROR: Service: ".$Service. ": No proper Communication with Gateway: " .$err;
|
||||
|
Loading…
x
Reference in New Issue
Block a user