From bc18022177596f36b0506d05f043d500b885e73e Mon Sep 17 00:00:00 2001 From: Marko Oldenburg Date: Wed, 17 Jun 2020 15:39:29 +0200 Subject: [PATCH] =?UTF-8?q?fix=20first=20start=20and=20set=20state=20readi?= =?UTF-8?q?ng=20=09ge=C3=A4ndert:=20=20=20=20=20=20=20lib/FHEM/backupToSto?= =?UTF-8?q?rage.pm?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controls_backupToStorage.txt | 2 +- lib/FHEM/backupToStorage.pm | 41 ++++++++++++++++++++++++------------ 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/controls_backupToStorage.txt b/controls_backupToStorage.txt index ae4a9f0..4a418ea 100644 --- a/controls_backupToStorage.txt +++ b/controls_backupToStorage.txt @@ -1,2 +1,2 @@ UPD 2020-06-17_15:03:50 3368 FHEM/98_backupToStorage.pm -UPD 2020-06-17_15:30:50 10123 lib/FHEM/backupToStorage.pm +UPD 2020-06-17_15:39:04 10502 lib/FHEM/backupToStorage.pm diff --git a/lib/FHEM/backupToStorage.pm b/lib/FHEM/backupToStorage.pm index cab4666..f0cb904 100644 --- a/lib/FHEM/backupToStorage.pm +++ b/lib/FHEM/backupToStorage.pm @@ -79,17 +79,6 @@ sub Define { $hash->{VERSION} = version->parse($VERSION)->normal; $hash->{NOTIFYDEV} = 'global'; - readingsSingleUpdate( $hash, 'state', - ( - (AttrVal( $name, 'bTS_Host', 'none' ) eq 'none' - || AttrVal( $name, 'bTS_User', 'none' ) eq 'none' - || !defined( ReadPassword( $hash, $name ) ) ) - ? 'please set storage account credentials first' - : 'ready' - ) - , 1 - ); - Log3( $name, 3, "backupToStorage ($name) - defined" ); return; @@ -143,20 +132,44 @@ sub Notify { . Dumper $events); # mit Dumper PushToStorage($hash) - if ( grep /^backup.done/, + if ( grep m{^backup.done}xms, @{$events} && $devname eq 'global' && $init_done ); CheckAttributsForCredentials($hash) if ( ( - grep /^DELETEATTR.$name.(bTS_Host|bTS_User)$/, + grep m{^DELETEATTR.$name.(bTS_Host|bTS_User)$}xms, @{$events} - or grep /^ATTR.$name.(bTS_Host|bTS_User).\S+$/, + or grep m{^ATTR.$name.(bTS_Host|bTS_User).\S+$}xms, @{$events} ) && $devname eq 'global' && $init_done ); + + readingsSingleUpdate( $hash, 'state', + ( + (AttrVal( $name, 'bTS_Host', 'none' ) eq 'none' + || AttrVal( $name, 'bTS_User', 'none' ) eq 'none' + || !defined( ReadPassword( $hash, $name ) ) ) + ? 'please set storage account credentials first' + : 'ready' + ) + , 1 + ) + if ( + ( + grep m{^DEFINED.$name$}xms, + @{$events} && $devname eq 'global' && $init_done + ) + || ( + grep m{^INITIALIZED$}xms, + @{$events} or grep m{^REREADCFG$}xms, + @{$events} or grep m{^MODIFIED.$name$}xms, + @{$events} + ) + && $devname eq 'global' + ); return; }