add trigger for password setter

geändert:       lib/FHEM/backupToStorage.pm
This commit is contained in:
Marko Oldenburg 2020-06-17 16:08:05 +02:00
parent bc18022177
commit 87c2d95a20
2 changed files with 58 additions and 39 deletions

View File

@ -1,2 +1,2 @@
UPD 2020-06-17_15:03:50 3368 FHEM/98_backupToStorage.pm UPD 2020-06-17_15:03:50 3368 FHEM/98_backupToStorage.pm
UPD 2020-06-17_15:39:04 10502 lib/FHEM/backupToStorage.pm UPD 2020-06-17_16:07:42 10965 lib/FHEM/backupToStorage.pm

View File

@ -77,7 +77,7 @@ sub Define {
my $name = shift @$aArg; my $name = shift @$aArg;
$hash->{VERSION} = version->parse($VERSION)->normal; $hash->{VERSION} = version->parse($VERSION)->normal;
$hash->{NOTIFYDEV} = 'global'; $hash->{NOTIFYDEV} = 'global,' . $name;
Log3( $name, 3, "backupToStorage ($name) - defined" ); Log3( $name, 3, "backupToStorage ($name) - defined" );
@ -137,6 +137,8 @@ sub Notify {
CheckAttributsForCredentials($hash) CheckAttributsForCredentials($hash)
if ( if (
(
(
( (
grep m{^DELETEATTR.$name.(bTS_Host|bTS_User)$}xms, grep m{^DELETEATTR.$name.(bTS_Host|bTS_User)$}xms,
@{$events} @{$events}
@ -144,18 +146,29 @@ sub Notify {
@{$events} @{$events}
) )
&& $devname eq 'global' && $devname eq 'global'
)
|| (
(
$devname eq $name && grep m{^password:.(add|remove)$}xms,
@{$events}
)
)
)
&& $init_done && $init_done
); );
readingsSingleUpdate( $hash, 'state', readingsSingleUpdate(
$hash, 'state',
( (
(AttrVal( $name, 'bTS_Host', 'none' ) eq 'none' (
AttrVal( $name, 'bTS_Host', 'none' ) eq 'none'
|| AttrVal( $name, 'bTS_User', 'none' ) eq 'none' || AttrVal( $name, 'bTS_User', 'none' ) eq 'none'
|| !defined( ReadPassword( $hash, $name ) ) ) || !defined( ReadPassword( $hash, $name ) )
)
? 'please set storage account credentials first' ? 'please set storage account credentials first'
: 'ready' : 'ready'
) ),
, 1 1
) )
if ( if (
( (
@ -222,7 +235,8 @@ sub PushToStorage {
Log3 $name, 4, "backupToStorage ($name) - push to storage function"; Log3 $name, 4, "backupToStorage ($name) - push to storage function";
if ( AttrVal( $name, 'bTSType', 'Nextcloud' ) eq 'Nextcloud' ) { if ( AttrVal( $name, 'bTSType', 'Nextcloud' ) eq 'Nextcloud' ) {
Log3 $name, 4, "backupToStorage ($name) - push to storage function: Nextcloud detected"; Log3 $name, 4,
"backupToStorage ($name) - push to storage function: Nextcloud detected";
ncUpload( $hash, ReadingsVal( $name, 'fhemBackupFile', 'none' ) ); ncUpload( $hash, ReadingsVal( $name, 'fhemBackupFile', 'none' ) );
} }
@ -330,6 +344,8 @@ sub StorePassword {
} }
my $err = setKeyValue( $index, $enc_pwd ); my $err = setKeyValue( $index, $enc_pwd );
DoTrigger( $name, 'password add' );
return "error while saving the password - $err" if ( defined($err) ); return "error while saving the password - $err" if ( defined($err) );
return "password successfully saved"; return "password successfully saved";
@ -382,7 +398,10 @@ sub ReadPassword {
sub DeletePassword { sub DeletePassword {
my $hash = shift; my $hash = shift;
setKeyValue( $hash->{TYPE} . "_" . $hash->{NAME} . "_passwd", undef ); my $name = $hash->{NAME};
setKeyValue( $hash->{TYPE} . "_" . $name . "_passwd", undef );
DoTrigger( $name, 'password remove' );
return; return;
} }
@ -398,13 +417,13 @@ sub CheckAttributsForCredentials {
my $ncPath = AttrVal( $name, 'bTS_Path', 'none' ); my $ncPath = AttrVal( $name, 'bTS_Path', 'none' );
my $status = 'ready'; my $status = 'ready';
$status = ($status eq 'ready' $status = (
&& $ncUser eq 'none' ? 'no user credential attribut' $status eq 'ready' && $ncUser eq 'none' ? 'no user credential attribut'
: $status eq 'ready' : $status eq 'ready'
&& $ncHost eq 'none' ? 'no host credential attribut' && $ncHost eq 'none' ? 'no host credential attribut'
: $status eq 'ready' : $status eq 'ready' && !defined($ncPass) ? 'no password set'
&& !defined($ncPass) ? 'no password set' : $status
: $status); );
return readingsSingleUpdate( $hash, 'state', $status, 1 ); return readingsSingleUpdate( $hash, 'state', $status, 1 );
} }