diff --git a/controls_backupToStorage.txt b/controls_backupToStorage.txt index bf5e0ed..3c987cd 100644 --- a/controls_backupToStorage.txt +++ b/controls_backupToStorage.txt @@ -1,2 +1,2 @@ UPD 2020-06-17_12:01:37 3338 FHEM/98_backupToStorage.pm -UPD 2020-06-17_12:02:54 8823 lib/FHEM/backupToStorage.pm +UPD 2020-06-17_14:37:42 9679 lib/FHEM/backupToStorage.pm diff --git a/lib/FHEM/backupToStorage.pm b/lib/FHEM/backupToStorage.pm index f9ab3e9..98a0112 100644 --- a/lib/FHEM/backupToStorage.pm +++ b/lib/FHEM/backupToStorage.pm @@ -47,10 +47,6 @@ BEGIN { GP_Import( qw( readingsSingleUpdate - readingsBulkUpdate - readingsBulkUpdateIfChanged - readingsBeginUpdate - readingsEndUpdate defs modules setKeyValue @@ -145,6 +141,18 @@ sub Notify { if ( grep /^backup.done/, @{$events} && $devname eq 'global' && $init_done ); + CheckAttributsForCredentials($hash) + if ( + ( + grep /^DELETEATTR.$name.(bTS_Host|bTS_User)$/, + @{$events} + or grep /^ATTR.$name.(bTS_Host|bTS_User).\S+$/, + @{$events} + ) + && $devname eq 'global' + && $init_done + ); + return; } @@ -352,4 +360,26 @@ sub DeletePassword { return; } +sub CheckAttributsForCredentials { + my $hash = shift; + + my $name = $hash->{NAME}; + + my $ncUser = AttrVal( $name, 'bTS_User', 'none' ); + my $ncPass = ReadPassword( $hash, $name ); + my $ncHost = AttrVal( $name, 'bTS_Host', 'none' ); + my $ncPath = AttrVal( $name, 'bTS_Path', 'none' ); + my $status = 'ready'; + + $status eq 'ready' + && $ncUser eq 'none' ? 'no user credential attribut' + : $status eq 'ready' + && $ncHost eq 'none' ? 'no host credential attribut' + : $status eq 'ready' + && !defined($ncPass) ? 'no password set' + : $status; + + return readingsSingleUpdate( $hash, 'state', $status, 1 ); +} + 1;