diverse Flowanpassungen, Bugfixes für null Values

This commit is contained in:
Marko Oldenburg
2017-06-01 21:25:07 +02:00
parent 7af196bada
commit 04e73fd3c2
3 changed files with 793 additions and 811 deletions

View File

@@ -68,8 +68,8 @@ use TcpServerUtils;
eval "use JSON;1" or $missingModul .= "JSON ";
my $modulversion = "3.9.52";
my $flowsetversion = "3.9.52";
my $modulversion = "3.9.55";
my $flowsetversion = "3.9.55";
@@ -111,7 +111,6 @@ sub AMADCommBridge_Initialize($) {
$hash->{AttrFn} = "AMADCommBridge_Attr";
$hash->{AttrList} = "expertMode:1 ".
"port ".
"disable:1 ".
$readingFnAttributes;
@@ -196,29 +195,6 @@ sub AMADCommBridge_Attr(@) {
}
}
elsif( $attrName eq "port" ) {
if( $cmd eq "set" ) {
$hash->{PORT} = $attrVal;
delete $modules{AMADCommBridge}{defptr}{BRIDGE};
TcpServer_Close( $hash );
Log3 $name, 3, "AMADCommBridge ($name) - CommBridge Port changed. CommBridge are closed and new open!";
AMADCommBridge_CommBridge_Open( $hash );
} else {
$hash->{PORT} = 8090;
delete $modules{AMADCommBridge}{defptr}{BRIDGE};
TcpServer_Close( $hash );
Log3 $name, 3, "AMADCommBridge ($name) - CommBridge Port changed. CommBridge are closed and new open!";
AMADCommBridge_Open( $hash );
}
}
return undef;
}
@@ -286,14 +262,14 @@ sub AMADCommBridge_ErrorHandling($$$) {
if( $dhash->{helper}{infoErrorCounter} > 0 ) {
readingsBeginUpdate( $dhash );
readingsBulkUpdate( $dhash, "lastStatusRequestState", "statusRequest_error" );
readingsBulkUpdateIfChanged( $dhash, "lastStatusRequestState", "statusRequest_error", 1 );
if( ReadingsVal( $dname, "flow_Informations", "active" ) eq "inactive" && ReadingsVal( $dname, "flow_SetCommands", "active" ) eq "inactive" ) {
Log3 $dname, 5, "AMADCommBridge ($dname) - statusRequestERROR: CHECK THE LAST ERROR READINGS FOR MORE INFO, DEVICE IS SET OFFLINE";
readingsBulkUpdate( $dhash, "deviceState", "offline" );
readingsBulkUpdate ( $dhash, "state", "AMAD Flows inactive, device set offline");
readingsBulkUpdateIfChanged( $dhash, "deviceState", "offline", 1 );
readingsBulkUpdateIfChanged ( $dhash, "state", "AMAD Flows inactive, device set offline",1);
}
elsif( $dhash->{helper}{infoErrorCounter} > 7 && $dhash->{helper}{setCmdErrorCounter} > 4 ) {
@@ -301,7 +277,7 @@ sub AMADCommBridge_ErrorHandling($$$) {
Log3 $dname, 5, "AMADCommBridge ($dname) - statusRequestERROR: UNKNOWN ERROR, PLEASE CONTACT THE DEVELOPER, DEVICE DISABLED";
$attr{$dname}{disable} = 1;
readingsBulkUpdate ( $dhash, "state", "Unknown Error, device disabled");
readingsBulkUpdateIfChanged ( $dhash, "state", "Unknown Error, device disabled", 1);
$dhash->{helper}{infoErrorCounter} = 0;
$dhash->{helper}{setCmdErrorCounter} = 0;
@@ -318,8 +294,8 @@ sub AMADCommBridge_ErrorHandling($$$) {
Log3 $dname, 5, "AMADCommBridge ($dname) - statusRequestERROR: To many Errors please check your Network or Device Configuration, DEVICE IS SET OFFLINE";
readingsBulkUpdate( $dhash, "deviceState", "offline" );
readingsBulkUpdate ( $dhash, "state", "To many Errors, device set offline");
readingsBulkUpdateIfChanged( $dhash, "deviceState", "offline", 1 );
readingsBulkUpdateIfChanged ( $dhash, "state", "To many Errors, device set offline", 1);
$dhash->{helper}{infoErrorCounter} = 0;
}
@@ -335,10 +311,10 @@ sub AMADCommBridge_ErrorHandling($$$) {
if( $err ne "" ) {
readingsBeginUpdate( $dhash );
readingsBulkUpdate ( $dhash, "state", "$err") if( ReadingsVal( $dname, "state", 1 ) ne "initialized" );
readingsBulkUpdateIfChanged ( $dhash, "state", "$err") if( ReadingsVal( $dname, "state", 1 ) ne "initialized" );
$dhash->{helper}{infoErrorCounter} = ( $dhash->{helper}{infoErrorCounter} + 1 );
readingsBulkUpdate( $dhash, "lastStatusRequestState", "statusRequest_error" );
readingsBulkUpdateIfChanged( $dhash, "lastStatusRequestState", "statusRequest_error", 1 );
if( $err =~ /timed out/ ) {
@@ -365,10 +341,10 @@ sub AMADCommBridge_ErrorHandling($$$) {
if( $data eq "" and exists( $param->{code} ) && $param->{code} ne 200 ) {
readingsBeginUpdate( $dhash );
readingsBulkUpdate ( $dhash, "state", $param->{code} ) if( ReadingsVal( $dname, "state", 1 ) ne "initialized" );
readingsBulkUpdateIfChanged ( $dhash, "state", $param->{code}, 1 ) if( ReadingsVal( $dname, "state", 1 ) ne "initialized" );
$dhash->{helper}{infoErrorCounter} = ( $dhash->{helper}{infoErrorCounter} + 1 );
readingsBulkUpdate( $dhash, "lastStatusRequestState", "statusRequest_error" );
readingsBulkUpdateIfChanged( $dhash, "lastStatusRequestState", "statusRequest_error", 1 );
if( $param->{code} ne 200 ) {
@@ -384,10 +360,10 @@ sub AMADCommBridge_ErrorHandling($$$) {
if( ( $data =~ /Error/i ) and exists( $param->{code} ) ) {
readingsBeginUpdate( $dhash );
readingsBulkUpdate( $dhash, "state", $param->{code} ) if( ReadingsVal( $dname, "state" ,0) ne "initialized" );
readingsBulkUpdateIfChanged( $dhash, "state", $param->{code}, 1 ) if( ReadingsVal( $dname, "state" ,0) ne "initialized" );
$dhash->{helper}{infoErrorCounter} = ( $dhash->{helper}{infoErrorCounter} + 1 );
readingsBulkUpdate( $dhash, "lastStatusRequestState", "statusRequest_error" );
readingsBulkUpdateIfChanged( $dhash, "lastStatusRequestState", "statusRequest_error", 1 );
if( $param->{code} eq 404 && ReadingsVal( $dname, "flow_Informations", "inactive" ) eq "inactive" ) {
@@ -421,14 +397,14 @@ sub AMADCommBridge_ErrorHandling($$$) {
if( $dhash->{helper}{setCmdErrorCounter} > 2 ) {
readingsBeginUpdate( $dhash );
readingsBulkUpdate( $dhash, "lastSetCommandState", "statusRequest_error" );
readingsBulkUpdateIfChanged( $dhash, "lastSetCommandState", "statusRequest_error", 1 );
if( ReadingsVal( $dname, "flow_Informations", "active" ) eq "inactive" && ReadingsVal( $dname, "flow_SetCommands", "active" ) eq "inactive" ) {
Log3 $dname, 5, "AMADCommBridge ($dname) - setCommandERROR: CHECK THE LAST ERROR READINGS FOR MORE INFO, DEVICE IS SET OFFLINE";
readingsBulkUpdate( $dhash, "deviceState", "offline" );
readingsBulkUpdate( $dhash, "state", "AMAD Flows inactive, device set offline" );
readingsBulkUpdateIfChanged( $dhash, "deviceState", "offline", 1 );
readingsBulkUpdateIfChanged( $dhash, "state", "AMAD Flows inactive, device set offline", 1 );
}
elsif( $dhash->{helper}{infoErrorCounter} > 7 && $dhash->{helper}{setCmdErrorCounter} > 4 ) {
@@ -436,7 +412,7 @@ sub AMADCommBridge_ErrorHandling($$$) {
Log3 $dname, 5, "AMADCommBridge ($dname) - setCommandERROR: UNKNOWN ERROR, PLEASE CONTACT THE DEVELOPER, DEVICE DISABLED";
$attr{$dname}{disable} = 1;
readingsBulkUpdate( $dhash, "state", "Unknown Error, device disabled" );
readingsBulkUpdateIfChanged( $dhash, "state", "Unknown Error, device disabled", 1 );
$dhash->{helper}{infoErrorCounter} = 0;
$dhash->{helper}{setCmdErrorCounter} = 0;
@@ -452,8 +428,8 @@ sub AMADCommBridge_ErrorHandling($$$) {
Log3 $dname, 5, "AMADCommBridge ($dname) - setCommandERROR: To many Errors please check your Network or Device Configuration, DEVICE IS SET OFFLINE";
readingsBulkUpdate( $dhash, "deviceState", "offline" );
readingsBulkUpdate( $dhash, "state", "To many Errors, device set offline" );
readingsBulkUpdateIfChanged( $dhash, "deviceState", "offline", 1 );
readingsBulkUpdateIfChanged( $dhash, "state", "To many Errors, device set offline", 1 );
$dhash->{helper}{setCmdErrorCounter} = 0;
}
@@ -468,10 +444,10 @@ sub AMADCommBridge_ErrorHandling($$$) {
if( defined( $err ) ) {
if( $err ne "" ) {
readingsBeginUpdate( $dhash );
readingsBulkUpdate( $dhash, "state", $err ) if( ReadingsVal( $dname, "state", 0 ) ne "initialized" );
readingsBulkUpdateIfChanged( $dhash, "state", $err, 1 ) if( ReadingsVal( $dname, "state", 0 ) ne "initialized" );
$dhash->{helper}{setCmdErrorCounter} = ($dhash->{helper}{setCmdErrorCounter} + 1);
readingsBulkUpdate( $dhash, "lastSetCommandState", "setCmd_error" );
readingsBulkUpdateIfChanged( $dhash, "lastSetCommandState", "setCmd_error", 1 );
if( $err =~ /timed out/ ) {
@@ -498,11 +474,11 @@ sub AMADCommBridge_ErrorHandling($$$) {
if( $data eq "" and exists( $param->{code} ) && $param->{code} ne 200 ) {
readingsBeginUpdate( $dhash );
readingsBulkUpdate( $dhash, "state", $param->{code} ) if( ReadingsVal( $dhash, "state", 0 ) ne "initialized" );
readingsBulkUpdateIfChanged( $dhash, "state", $param->{code}, 1 ) if( ReadingsVal( $dhash, "state", 0 ) ne "initialized" );
$dhash->{helper}{setCmdErrorCounter} = ( $dhash->{helper}{setCmdErrorCounter} + 1 );
readingsBulkUpdate($dhash, "lastSetCommandState", "setCmd_error" );
readingsBulkUpdateIfChanged($dhash, "lastSetCommandState", "setCmd_error", 1 );
readingsEndUpdate( $dhash, 1 );
@@ -514,15 +490,15 @@ sub AMADCommBridge_ErrorHandling($$$) {
if( ( $data =~ /Error/i ) and exists( $param->{code} ) ) {
readingsBeginUpdate( $dhash );
readingsBulkUpdate( $dhash, "state", $param->{code} ) if( ReadingsVal( $dname, "state", 0 ) ne "initialized" );
readingsBulkUpdateIfChanged( $dhash, "state", $param->{code}, 1 ) if( ReadingsVal( $dname, "state", 0 ) ne "initialized" );
$dhash->{helper}{setCmdErrorCounter} = ( $dhash->{helper}{setCmdErrorCounter} + 1 );
readingsBulkUpdate( $dhash, "lastSetCommandState", "setCmd_error" );
readingsBulkUpdateIfChanged( $dhash, "lastSetCommandState", "setCmd_error", 1 );
if( $param->{code} eq 404 ) {
readingsBulkUpdate( $dhash, "lastSetCommandError", "" );
readingsBulkUpdateIfChanged( $dhash, "lastSetCommandError", "", 1 );
Log3 $dname, 5, "AMADCommBridge ($dname) - setCommandERROR: setCommands flow is inactive on your device!";
} else {
@@ -728,7 +704,7 @@ sub AMADCommBridge_ResponseProcessing($$) {
$decode_json = eval{decode_json($json)};
if($@){
Log3 $bname, 3, "AMADCommBridge ($name) - ERROR while request: $@";
Log3 $bname, 4, "AMADCommBridge ($name) - ERROR while request: $@";
readingsSingleUpdate($bhash, "JSON info", "JSON ERROR", 1);
$response = "header lines: \r\n AMADCommBridge receive a JSON error\r\n AMADCommBridge to do nothing\r\n";
$c = $hash->{CD};
@@ -816,8 +792,8 @@ sub AMADCommBridge_ResponseProcessing($$) {
my $fhemCmd = $decode_json->{payload}{voiceinputdata};
readingsBeginUpdate( $bhash);
readingsBulkUpdate( $bhash, "receiveVoiceCommand", $fhemCmd );
readingsBulkUpdate( $bhash, "receiveVoiceDevice", $fhemDevice );
readingsBulkUpdateIfChanged( $bhash, "receiveVoiceCommand", $fhemCmd, 1 );
readingsBulkUpdateIfChanged( $bhash, "receiveVoiceDevice", $fhemDevice, 1 );
readingsEndUpdate( $bhash, 1 );
Log3 $bname, 4, "AMADCommBridge ($name) - AMADCommBridge_CommBridge: set reading receive voice command: $fhemCmd from Device $fhemDevice";