2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-28 17:12:32 +00:00

73_km200.pm: Bugfix double service. Feature service info.

git-svn-id: https://svn.fhem.de/fhem/trunk@12146 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
sailor-fhem 2016-09-12 18:34:16 +00:00
parent 665607db58
commit 7a3612b003

View File

@ -122,6 +122,7 @@ sub km200_Define($$)
"/recordings",
"/solarCircuits",
"/system",
"/dhwCircuits",
);
####END####### Define known services of gateway ############################################################END#####
@ -330,7 +331,6 @@ sub km200_DbLog_splitFn($$)
### Log entries for debugging
Log3 $name, 5, $name. " : km200_DbLog_splitFn - Content of event : " . $event;
Log3 $name, 5, $name. " : km200_DbLog_splitFn - Content of argument[0] : " . $argument[0];
Log3 $name, 5, $name. " : km200_DbLog_splitFn - Content of argument[1] : " . $argument[1];
@ -722,13 +722,13 @@ sub km200_Decrypt($)
my $decryptData = $hash->{temp}{decodedcontent};
### Log entries for debugging purposes
Log3 $name, 5, $name. " : km200 - decryptData2 - decryptData : " .$decryptData;
#Log3 $name, 5, $name. " : km200 - decryptData2 - decryptData : " .$decryptData;
# Remove additional encoding with base64
$decryptData = decode_base64($decryptData);
### Log entries for debugging purposes
Log3 $name, 5, $name. " : km200 - decryptData2 - base64decode : " .$decryptData;
#Log3 $name, 5, $name. " : km200 - decryptData2 - base64decode : " .$decryptData;
# Check whether the length of the decryptData is NOT multiplies of 16
if ((length($decryptData)&0xF) != 0)
@ -1919,7 +1919,7 @@ sub km200_ParseHttpResponseInit($)
if($err ne "")
{
### Create Log entry
Log3 $name, 2, $name . " : km200_ParseHttpResponseInit - ERROR - Service: ".$Service. ": No proper Communication with Gateway: " .$err;
Log3 $name, 2, $name . " : km200_ParseHttpResponseInit - ERROR : ".$Service. ": No proper Communication with Gateway: " .$err;
### Set status of km200 fhem module
$hash->{STATE} = "ERROR - Initial Connection failed... Try to re-connect in 10s";
@ -1928,8 +1928,8 @@ sub km200_ParseHttpResponseInit($)
InternalTimer(gettimeofday()+10, "km200_GetInitService", $hash, 1);
### Create Log entry
Log3 $name, 2, $name . " : km200_ParseHttpResponseInit - ERROR - Timer restarted to try again in 10s";
Log3 $name, 2, $name . " : km200_ParseHttpResponseInit - ERROR : Timer restarted to try again in 10s";
Log3 $name, 5, $name . "______________________________________________________________________________________________________________________";
return "ERROR";
}
@ -1965,6 +1965,12 @@ sub km200_ParseHttpResponseInit($)
### Add service to the list of responding services
push (@KM200_RespondingServices, $Service);
### Delete double entries in the list of responding services and sort in alphabetical order
my %FilteredKM200RespondingServices;
$FilteredKM200RespondingServices{$_}=0 for @KM200_RespondingServices;
@KM200_RespondingServices = (keys %FilteredKM200RespondingServices);
@KM200_RespondingServices = sort @KM200_RespondingServices;
### Save json-hash for DbLog-Split
$hash->{temp}{ServiceDbLogSplitHash} = $json;
@ -2007,6 +2013,12 @@ sub km200_ParseHttpResponseInit($)
### Add service to the list of responding services
push (@KM200_RespondingServices, $Service);
### Delete double entries in the list of responding services and sort in alphabetical order
my %FilteredKM200RespondingServices;
$FilteredKM200RespondingServices{$_}=0 for @KM200_RespondingServices;
@KM200_RespondingServices = (keys %FilteredKM200RespondingServices);
@KM200_RespondingServices = sort @KM200_RespondingServices;
### Log file entry for debugging
my $LogMessage = " : The following Service can be read";
@ -2239,6 +2251,12 @@ sub km200_ParseHttpResponseInit($)
### Add service to the list of responding services
push (@KM200_RespondingServices, $Service);
### Delete double entries in the list of responding services and sort in alphabetical order
my %FilteredKM200RespondingServices;
$FilteredKM200RespondingServices{$_}=0 for @KM200_RespondingServices;
@KM200_RespondingServices = (keys %FilteredKM200RespondingServices);
@KM200_RespondingServices = sort @KM200_RespondingServices;
### Log file entry for debugging
my $LogMessage = " : The following Service can be read";
@ -2246,7 +2264,6 @@ sub km200_ParseHttpResponseInit($)
if ($json->{writeable} == 1)
{
$LogMessage = $LogMessage . " and is writeable ";
push (@KM200_WriteableServices, $Service);
}
else
@ -2298,7 +2315,7 @@ sub km200_ParseHttpResponseInit($)
my @JsonReferences = $json->{references};
### Log file entry for debugging
Log3 $name, 5, $name. "The following Service is an empty parent directory : " . $JsonId;
Log3 $name, 5, $name. " : The following Service is an empty parent directory : " . $JsonId;
### For each item found in this empty parent directory
foreach my $item (@{ $json->{references} })
@ -2323,6 +2340,61 @@ sub km200_ParseHttpResponseInit($)
### Sort the list of all services alphabetically
@{$hash ->{Secret}{KM200ALLSERVICES}} = sort @{$hash ->{Secret}{KM200ALLSERVICES}};
}
### Check whether the type is a systeminfo
elsif ($json -> {type} eq "systeminfo")
{
my $JsonId = $json->{id};
my $JsonType = $json->{type};
my @JsonValues = $json->{values};
### Log entries for debugging purposes
Log3 $name, 5, $name. " : km200_ParseHttpResponseInit - value found for : " .$Service;
Log3 $name, 5, $name. " : km200_ParseHttpResponseInit - id : " .$JsonId;
Log3 $name, 5, $name. " : km200_ParseHttpResponseInit - type : " .$JsonType;
Log3 $name, 5, $name. " : km200_ParseHttpResponseInit - value : " .@JsonValues;
### Add service to the list of responding services
push (@KM200_RespondingServices, $Service);
### Delete double entries in the list of responding services and sort in alphabetical order
my %FilteredKM200RespondingServices;
$FilteredKM200RespondingServices{$_}=0 for @KM200_RespondingServices;
@KM200_RespondingServices = (keys %FilteredKM200RespondingServices);
@KM200_RespondingServices = sort @KM200_RespondingServices;
### Log file entry for debugging
Log3 $name, 4, $name . " : The following Service can be read : " .$JsonId;
### Initialise ArrayCounter
my $ArrayCounter = 0;
foreach my $ArrayItem (@{ $json->{values} })
{
### Incrementation of ArrayCounter
$ArrayCounter++;
### Log file entry for debugging
Log3 $name, 5, $name . " : The ArrayItem is : " . $ArrayItem ;
Log3 $name, 5, $name . " : The keys ArrayItem is : " . (keys $ArrayItem) ;
### Get array from scalar
my %ArrayHash = %{$ArrayItem};
while( my( $SystemInfoHashKey, $SystemInfoHashValue ) = each %ArrayHash )
{
### Log file entry for debugging
Log3 $name, 5, $name . " : The ArrayHashKey is : " . $SystemInfoHashKey;
Log3 $name, 5, $name . " : The ArrayHashValue is : " . $SystemInfoHashValue;
### Create new Service and write reading for fhem
my $TempJsonId = $JsonId . "/" . sprintf ('%02d', $ArrayCounter) . "/" . $SystemInfoHashKey;
readingsSingleUpdate( $hash, $TempJsonId, $SystemInfoHashValue, 1);
### Log file entry for debugging
Log3 $name, 5, $name . " : The following Service can be read : " . $TempJsonId;
}
}
}
### Check whether the type is unknown
else
{
@ -2338,8 +2410,8 @@ sub km200_ParseHttpResponseInit($)
}
### Log entries for debugging purposes
Log3 $name, 5, $name. " : km200_ParseHttpResponseInit : response : " .$data;
#Log3 $name, 5, $name. " : km200_ParseHttpResponseInit : response : " .$data;
Log3 $name, 5, $name . "______________________________________________________________________________________________________________________";
### Get the size of the array
@KM200_InitServices = @{$hash ->{Secret}{KM200ALLSERVICES}};
$NumberInitServices = @KM200_InitServices;
@ -2731,6 +2803,38 @@ sub km200_ParseHttpResponseDyn($)
readingsSingleUpdate( $hash, $TempServiceString, $TempErrorMessage, 1);
}
}
### Check whether the type is a systeminfo
elsif ($json -> {type} eq "systeminfo")
{
my $JsonId = $json->{id};
my $JsonType = $json->{type};
my @JsonValues = $json->{values};
### Log entries for debugging purposes
Log3 $name, 5, $name. " : km200_ParseHttpResponseInit - value found for : " .$Service;
Log3 $name, 5, $name. " : km200_ParseHttpResponseInit - id : " .$JsonId;
Log3 $name, 5, $name. " : km200_ParseHttpResponseInit - type : " .$JsonType;
### Initialise ArrayCounter
my $ArrayCounter = 0;
foreach my $ArrayItem (@{ $json->{values} })
{
### Incrementation of ArrayCounter
$ArrayCounter++;
### Get array from scalar
my %ArrayHash = %{$ArrayItem};
while( my( $SystemInfoHashKey, $SystemInfoHashValue ) = each %ArrayHash )
{
### Create new Service and write reading for fhem
my $TempJsonId = $JsonId . "/" . sprintf ('%02d', $ArrayCounter) . "/" . $SystemInfoHashKey;
readingsSingleUpdate( $hash, $TempJsonId, $SystemInfoHashValue, 1);
}
}
}
### Check whether the type is unknown
else
{
@ -2743,7 +2847,7 @@ sub km200_ParseHttpResponseDyn($)
Log3 $name, 5, $name. " : km200_parseHttpResponseDyn - Data not available on km200 for http://" . $param->{url};
}
Log3 $name, 5, $name . "______________________________________________________________________________________________________________________";
### Clear up temporary variables
$hash->{temp}{decodedcontent} = "";
$hash->{temp}{service} = "";
@ -2770,6 +2874,8 @@ sub km200_ParseHttpResponseDyn($)
readingsSingleUpdate( $hash, "fullResponse", "OK", 1);
$hash->{status}{FlagDynRequest} = false;
Log3 $name, 5, $name . "______________________________________________________________________________________________________________________";
}
return undef;
}