diff --git a/CHANGED b/CHANGED index a548a7309..6d65c0b40 100644 --- a/CHANGED +++ b/CHANGED @@ -1,14 +1,17 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - change: 74_AMAD: change set of STATE has been replaced by Readingsupdate + 'state' + - feature: 74_AMAD: commandref english translation, default $Id$ line - feature: SYSMON: telnet login with no user/pass required - bugfix: 95_Dashboard: the sort order in columns is now correctly read from the sorting attribute. - bugfix: 00_MAXLAN: set time on cube if it has none (by Tom_S) - bugfix: 14_CUL_MAX: work together with a-culfw - bugfix: 70_PushNotifier: bugfix regex deviceID - - feature: new Module 74_AMAD to request Information and control Android - Devices in cooperation with AutomagicApp on the Device (Forum - #39773) (by M. Oldenburg) + - feature: new Module 74_AMAD to request Information and control Android Devices + in cooperation with AutomagicApp on the Device (Forum #39773) + (by M. Oldenburg) - bugfix: 70_PushNotifier.pm: regex error handling - bugfix: 31_MilightDevice.pm: fixed bug that lead to crash on lost bridge connection, added module name prefix to round function diff --git a/FHEM/74_AMAD.pm b/FHEM/74_AMAD.pm index d732e5959..49cda86be 100644 --- a/FHEM/74_AMAD.pm +++ b/FHEM/74_AMAD.pm @@ -1,4 +1,4 @@ -################################################################ +############################################################################### # # Developed with Kate # @@ -20,9 +20,10 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # -################################################################ - - +# +# $Id$ +# +############################################################################### package main; @@ -33,7 +34,7 @@ use Time::HiRes qw(gettimeofday); use HttpUtils; -my $version = "0.6.0"; +my $version = "0.6.1"; @@ -90,8 +91,9 @@ my ( $hash, $def ) = @_; InternalTimer( gettimeofday()+$hash->{INTERVAL}, "AMAD_GetUpdateTimer", $hash, 0 ); - $hash->{STATE} = "initialized"; - readingsSingleUpdate ( $hash, "deviceState", "online", 0 ); + # $hash->{STATE} = "initialized"; # direktes setzen von STATE ist absolete + readingsSingleUpdate ( $hash, "state", "initialized", 1 ); + readingsSingleUpdate ( $hash, "deviceState", "online", 1 ); return undef; } @@ -114,19 +116,22 @@ my ( $cmd, $name, $attrName, $attrVal ) = @_; if( $cmd eq "set" ) { if( $attrVal eq "0" ) { RemoveInternalTimer( $hash ); - InternalTimer( gettimeofday()+2, "AMAD_GetUpdateTimer", $hash, 0 ) if( $hash->{STATE} eq "disabled" ); - $hash->{STATE}='active'; + InternalTimer( gettimeofday()+2, "AMAD_GetUpdateTimer", $hash, 0 ) if( ReadingsVal( $hash->{NAME}, "state", 0 ) eq "disabled" ); + # $hash->{STATE}='active'; # direktes STATE setzen ist absolete + readingsSingleUpdate ( $hash, "state", "active", 1 ); Log3 $name, 3, "AMAD ($name) - enabled"; } else { - $hash->{STATE} = 'disabled'; + # $hash->{STATE} = 'disabled'; + readingsSingleUpdate ( $hash, "state", "disabled", 1 ); RemoveInternalTimer( $hash ); Log3 $name, 3, "AMAD ($name) - disabled"; } } elsif( $cmd eq "del" ) { RemoveInternalTimer( $hash ); - InternalTimer( gettimeofday()+2, "AMAD_GetUpdateTimer", $hash, 0 ) if( $hash->{STATE} eq "disabled" ); - $hash->{STATE}='active'; + InternalTimer( gettimeofday()+2, "AMAD_GetUpdateTimer", $hash, 0 ) if( ReadingsVal( $hash->{NAME}, "state", 0 ) eq "disabled" ); + # $hash->{STATE}='active'; + readingsSingleUpdate ( $hash, "state", "active", 1 ); Log3 $name, 3, "AMAD ($name) - enabled"; } else { @@ -190,7 +195,7 @@ sub AMAD_GetUpdateLocal($) { my ( $hash ) = @_; my $name = $hash->{NAME}; - AMAD_RetrieveAutomagicInfo( $hash ) if( ReadingsVal( $name, "deviceState", "online" ) eq "online" && $hash->{STATE} ne "initialized" && AttrVal( $name, "disable", 0 ) ne "1" ); ### deviceState muß von Hand online/offline gesetzt werden z.B. über RESIDENZ Modul + AMAD_RetrieveAutomagicInfo( $hash ) if( ReadingsVal( $name, "deviceState", "online" ) eq "online" && ReadingsVal( $hash->{NAME}, "state", 0 ) ne "initialized" && AttrVal( $name, "disable", 0 ) ne "1" ); ### deviceState muß von Hand online/offline gesetzt werden z.B. ueber RESIDENZ Modul return 1; } @@ -200,7 +205,7 @@ sub AMAD_GetUpdateTimer($) { my ( $hash ) = @_; my $name = $hash->{NAME}; - AMAD_RetrieveAutomagicInfo( $hash ) if( ReadingsVal( $name, "deviceState", "online" ) eq "online" && AttrVal( $name, "disable", 0 ) ne "1" ); ### deviceState muß von Hand online/offline gesetzt werden z.B. über RESIDENZ Modul + AMAD_RetrieveAutomagicInfo( $hash ) if( ReadingsVal( $name, "deviceState", "online" ) eq "online" && AttrVal( $name, "disable", 0 ) ne "1" ); ### deviceState muß von Hand online/offline gesetzt werden z.B. ueber RESIDENZ Modul InternalTimer( gettimeofday()+$hash->{INTERVAL}, "AMAD_GetUpdateTimer", $hash, 1 ); Log3 $name, 4, "AMAD ($name) - Call AMAD_GetUpdateTimer"; @@ -248,7 +253,7 @@ sub AMAD_Set($$@) { Log3 $name, 5, "AMAD ($name) - set $name $cmd ".join(" ", @val); - return "set command only works if STATE not equal initialized, please wait for next interval run" if( $hash->{STATE} eq "initialized"); + return "set command only works if state not equal initialized, please wait for next interval run" if( ReadingsVal( $hash->{NAME}, "state", 0 ) eq "initialized"); return "Cannot set command, FHEM Device is disabled" if( AttrVal( $name, "disable", "0" ) eq "1" ); return AMAD_SelectSetCmd( $hash, $cmd, @val ) if( @val ) && ( ReadingsVal( $name, "deviceState", "online" ) eq "offline" ) && ( lc $cmd eq 'devicestate' ); @@ -308,7 +313,8 @@ sub AMAD_RetrieveAutomagicInfoFinished($$$) { Log3 $name, 5, "AMAD ($name) - CHECK THE LAST ERROR READINGS FOR MORE INFO, DEVICE IS SET OFFLINE"; readingsBulkUpdate( $hash, "deviceState", "offline" ); - $hash->{STATE} = "AMAD Flows inactive, device set offline"; + # $hash->{STATE} = "AMAD Flows inactive, device set offline"; # STATE direkt setzen ist absolete + readingsBulkUpdate ( $hash, "state", "AMAD Flows inactive, device set offline"); } elsif( $hash->{helper}{infoErrorCounter} > 9 && $hash->{helper}{setCmdErrorCounter} > 4 ) { readingsBulkUpdate( $hash, "lastStatusRequestError", "unknown error, please contact the developer" ); @@ -316,7 +322,9 @@ sub AMAD_RetrieveAutomagicInfoFinished($$$) { Log3 $name, 4, "AMAD ($name) - UNKNOWN ERROR, PLEASE CONTACT THE DEVELOPER, DEVICE DISABLED"; $attr{$name}{disable} = 1; - $hash->{STATE} = "Unknown Error, device disabled"; + # $hash->{STATE} = "Unknown Error, device disabled"; + readingsBulkUpdate ( $hash, "state", "Unknown Error, device disabled"); + $hash->{helper}{infoErrorCounter} = 0; $hash->{helper}{setCmdErrorCounter} = 0; @@ -338,7 +346,8 @@ sub AMAD_RetrieveAutomagicInfoFinished($$$) { Log3 $name, 4, "AMAD ($name) - To many Errors please check your Network or Device Configuration, DEVICE IS SET OFFLINE"; readingsBulkUpdate( $hash, "deviceState", "offline" ); - $hash->{STATE} = "To many Errors, device set offline"; + # $hash->{STATE} = "To many Errors, device set offline"; # STATE direkt setzen ist absolete + readingsBulkUpdate ( $hash, "state", "To many Errors, device set offline"); $hash->{helper}{infoErrorCounter} = 0; } readingsEndUpdate( $hash, 1 ); @@ -346,10 +355,11 @@ sub AMAD_RetrieveAutomagicInfoFinished($$$) { if( defined( $err ) ) { if( $err ne "" ) { - $hash->{STATE} = $err if( $hash->{STATE} ne "initialized" ); + readingsBeginUpdate( $hash ); + # $hash->{STATE} = $err if( $hash->{STATE} ne "initialized" ); + readingsBulkUpdate ( $hash, "state", "$err") if( ReadingsVal( $name, "state", 1 ) ne "initialized" ); $hash->{helper}{infoErrorCounter} = ( $hash->{helper}{infoErrorCounter} + 1 ); - readingsBeginUpdate( $hash ); readingsBulkUpdate( $hash, "lastStatusRequestState", "statusRequest_error" ); if( $err =~ /timed out/ ) { @@ -358,7 +368,7 @@ sub AMAD_RetrieveAutomagicInfoFinished($$$) { elsif( ( $err =~ /Keine Route zum Zielrechner/ ) && $hash->{helper}{infoErrorCounter} > 1 ) { readingsBulkUpdate( $hash,"lastStatusRequestError", "no route to target. bad network configuration or network is down "); } else { - readingsBulkUpdate($hash, "lastStatusRequestError", "$err" ); + readingsBulkUpdate($hash, "lastStatusRequestError", $err ); } readingsEndUpdate( $hash, 1 ); @@ -369,10 +379,11 @@ sub AMAD_RetrieveAutomagicInfoFinished($$$) { } if( $data eq "" and exists( $param->{code} ) ) { - $hash->{STATE} = $param->{code} if( $hash->{STATE} ne "initialized" ); + readingsBeginUpdate( $hash ); + # $hash->{STATE} = $param->{code} if( $hash->{STATE} ne "initialized" ); # direktes setzen von STATE ist absolete + readingsBulkUpdate ( $hash, "state", $param->{code} ) if( ReadingsVal( $name, "state", 1 ) ne "initialized" ); $hash->{helper}{infoErrorCounter} = ( $hash->{helper}{infoErrorCounter} + 1 ); - readingsBeginUpdate( $hash ); readingsBulkUpdate( $hash, "lastStatusRequestState", "statusRequest_error" ); if( $param->{code} ne 200 ) { @@ -388,10 +399,11 @@ sub AMAD_RetrieveAutomagicInfoFinished($$$) { } if( ( $data =~ /Error/i ) and exists( $param->{code} ) ) { - $hash->{STATE} = $param->{code} if( $hash->{STATE} ne "initialized" ); + #$hash->{STATE} = $param->{code} if( $hash->{STATE} ne "initialized" ); ## STATE direkt ist absolete + readingsBeginUpdate( $hash ); + readingsBulkUpdate( $hash, "state", $param->{code} ) if( ReadingsVal( $name, "state" ,0) ne "initialized" ); $hash->{helper}{infoErrorCounter} = ( $hash->{helper}{infoErrorCounter} + 1 ); - readingsBeginUpdate( $hash ); readingsBulkUpdate( $hash, "lastStatusRequestState", "statusRequest_error" ); if( $param->{code} eq 404 && ReadingsVal( $name, "flow_Informations", "inactive" ) eq "inactive" ) { @@ -415,7 +427,8 @@ sub AMAD_RetrieveAutomagicInfoFinished($$$) { $hash->{helper}{infoErrorCounter} = 0; ### Begin Response Processing - $hash->{STATE} = "active" if( $hash->{STATE} eq "initialized" || $hash->{STATE} ne "active" ); + # $hash->{STATE} = "active" if( $hash->{STATE} eq "initialized" || $hash->{STATE} ne "active" ); ## STATE direkt setzen ist absolete + readingsSingleUpdate( $hash, "state", "active", 1) if( ReadingsVal( $name, "state", 0 ) ne "initialized" or ReadingsVal( $name, "state", 0 ) ne "active" ); my @valuestring = split( '@@@@', $data ); my %buffer; @@ -436,12 +449,14 @@ sub AMAD_RetrieveAutomagicInfoFinished($$$) { readingsBulkUpdate( $hash, "lastStatusRequestState", "statusRequest_done" ); - readingsEndUpdate( $hash, 1 ); + $hash->{helper}{infoErrorCounter} = 0; ### End Response Processing - $hash->{STATE} = "active" if( $hash->{STATE} eq "initialized" ); + #$hash->{STATE} = "active" if( $hash->{STATE} eq "initialized" ); ## STATE direkt setzen ist absolete + readingsBulkUpdate( $hash, "state", "active" ) if( ReadingsVal( $name, "state", 0 ) eq "initialized" ); + readingsEndUpdate( $hash, 1 ); return undef; } @@ -451,9 +466,11 @@ sub AMAD_HTTP_POST($$) { my ( $hash, $url ) = @_; my $name = $hash->{NAME}; - my $state = $hash->{STATE}; + #my $state = $hash->{STATE}; + my $state = ReadingsVal( $name, "state", 0 ); - $hash->{STATE} = "Send HTTP POST"; + #$hash->{STATE} = "Send HTTP POST"; + readingsSingleUpdate( $hash, "state", "Send HTTP POST", 1 ); HttpUtils_NonblockingGet( { @@ -467,7 +484,8 @@ sub AMAD_HTTP_POST($$) { ); Log3 $name, 4, "AMAD ($name) - Send HTTP POST with URL $url"; - $hash->{STATE} = $state; + #$hash->{STATE} = $state; + readingsSingleUpdate( $hash, "state", $state, 1 ); return undef; } @@ -489,7 +507,8 @@ sub AMAD_HTTP_POSTerrorHandling($$$) { Log3 $name, 5, "AMAD ($name) - CHECK THE LAST ERROR READINGS FOR MORE INFO, DEVICE IS SET OFFLINE"; readingsBulkUpdate( $hash, "deviceState", "offline" ); - $hash->{STATE} = "AMAD Flows inactive, device set offline"; + #$hash->{STATE} = "AMAD Flows inactive, device set offline"; # STATE direkt setzen ist absolete + readingsBulkUpdate( $hash, "state", "AMAD Flows inactive, device set offline" ); } elsif( $hash->{helper}{infoErrorCounter} > 9 && $hash->{helper}{setCmdErrorCounter} > 4 ) { readingsBulkUpdate($hash, "lastSetCommandError", "unknown error, please contact the developer" ); @@ -497,7 +516,8 @@ sub AMAD_HTTP_POSTerrorHandling($$$) { Log3 $name, 4, "AMAD ($name) - UNKNOWN ERROR, PLEASE CONTACT THE DEVELOPER, DEVICE DISABLED"; $attr{$name}{disable} = 1; - $hash->{STATE} = "Unknown Error, device disabled"; + #$hash->{STATE} = "Unknown Error, device disabled"; + readingsBulkUpdate( $hash, "state", "Unknown Error, device disabled" ); $hash->{helper}{infoErrorCounter} = 0; $hash->{helper}{setCmdErrorCounter} = 0; @@ -519,7 +539,8 @@ sub AMAD_HTTP_POSTerrorHandling($$$) { Log3 $name, 4, "AMAD ($name) - To many Errors please check your Network or Device Configuration, DEVICE IS SET OFFLINE"; readingsBulkUpdate( $hash, "deviceState", "offline" ); - $hash->{STATE} = "To many Errors, device set offline"; + #$hash->{STATE} = "To many Errors, device set offline"; ## STATE direkt setzen ist absolete + readingsBulkUpdate( $hash, "state", "To many Errors, device set offline" ); $hash->{helper}{setCmdErrorCounter} = 0; } readingsEndUpdate( $hash, 1 ); @@ -527,10 +548,11 @@ sub AMAD_HTTP_POSTerrorHandling($$$) { if( defined( $err ) ) { if( $err ne "" ) { - $hash->{STATE} = $err if( $hash->{STATE} ne "initialized" ); + readingsBeginUpdate( $hash ); + #$hash->{STATE} = $err if( $hash->{STATE} ne "initialized" ); ## STATE direkt setzen ist absolete + readingsBulkUpdate( $hash, "state", $err ) if( ReadingsVal( $name, "state", 0 ) ne "initialized" ); $hash->{helper}{setCmdErrorCounter} = ($hash->{helper}{setCmdErrorCounter} + 1); - readingsBeginUpdate( $hash ); readingsBulkUpdate( $hash, "lastSetCommandState", "cmd_error" ); if( $err =~ /timed out/ ) { @@ -550,10 +572,12 @@ sub AMAD_HTTP_POSTerrorHandling($$$) { } if( $data eq "" and exists( $param->{code} ) && $param->{code} ne 200 ) { - $hash->{STATE} = $param->{code} if( $hash->{STATE} ne "initialized" ); - $hash->{helper}{setCmdErrorCounter} = ( $hash->{helper}{setCmdErrorCounter} + 1 ); - readingsBeginUpdate( $hash ); + #$hash->{STATE} = $param->{code} if( $hash->{STATE} ne "initialized" ); ## STATE direkt setzen ist absolete + readingsBulkUpdate( $hash, "state", $param->{code} ) if( ReadingsVal( $hash, "state", 0 ) ne "initialized" ); + + $hash->{helper}{setCmdErrorCounter} = ( $hash->{helper}{setCmdErrorCounter} + 1 ); + readingsBulkUpdate($hash, "lastSetCommandState", "cmd_error" ); readingsBulkUpdate($hash, "lastSetCommandError", "http Error ".$param->{code} ); readingsEndUpdate( $hash, 1 ); @@ -563,11 +587,13 @@ sub AMAD_HTTP_POSTerrorHandling($$$) { return; } - if( ( $data =~ /Error/i ) and exists( $param->{code} ) ) { - $hash->{STATE} = $param->{code} if( $hash->{STATE} ne "initialized" ); - $hash->{helper}{setCmdErrorCounter} = ( $hash->{helper}{setCmdErrorCounter} + 1 ); - + if( ( $data =~ /Error/i ) and exists( $param->{code} ) ) { readingsBeginUpdate( $hash ); + #$hash->{STATE} = $param->{code} if( $hash->{STATE} ne "initialized" ); ## STATE direkt setzen ist absolete + readingsBulkUpdate( $hash, "state", $param->{code} ) if( ReadingsVal( $name, "state", 0 ) ne "initialized" ); + + $hash->{helper}{setCmdErrorCounter} = ( $hash->{helper}{setCmdErrorCounter} + 1 ); + readingsBulkUpdate( $hash, "lastSetCommandState", "cmd_error" ); if( $param->{code} eq 404 ) { @@ -743,8 +769,157 @@ sub AMAD_SelectSetCmd($$@) {
define <name> AMAD <IP-ADDRESS>
+ define TabletLivingRoom AMAD 192.168.0.23