add support for synology station

This commit is contained in:
Marko Oldenburg 2021-01-04 14:06:22 +01:00
parent 48758f31ab
commit 6c715e9b5d
3 changed files with 49 additions and 36 deletions

View File

@ -57,7 +57,7 @@ sub backupToStorage_Initialize {
. 'bTS_User ' . 'bTS_User '
. 'bTS_Path ' . 'bTS_Path '
. 'bTS_Proto:http ' . 'bTS_Proto:http '
. 'bTS_Type:Nextcloud ' . 'bTS_Type:Nextcloud,SynologyFileStation '
. 'disable:1 ' . 'disable:1 '
. 'disabledForIntervals'; . 'disabledForIntervals';
$hash->{parseParams} = 1; $hash->{parseParams} = 1;

View File

@ -1,2 +1,2 @@
UPD 2020-11-06_14:06:34 6242 FHEM/98_backupToStorage.pm UPD 2020-11-09_13:01:44 6262 FHEM/98_backupToStorage.pm
UPD 2020-11-09_08:14:35 18938 lib/FHEM/backupToStorage.pm UPD 2020-11-09_13:35:28 19356 lib/FHEM/backupToStorage.pm

View File

@ -358,6 +358,12 @@ sub Attr {
InternalTimer( gettimeofday() + 1, InternalTimer( gettimeofday() + 1,
'FHEM::backupToStorage::_CheckIsDisabledAfterSetAttr', $hash, 0 ); 'FHEM::backupToStorage::_CheckIsDisabledAfterSetAttr', $hash, 0 );
} }
elsif ( $attrName eq 'bTS_Type' ) {
InternalTimer( gettimeofday() + 1,
sub { $hash->{STORAGETYPE} = AttrVal($name,'bTS_Type','Nextcloud'); }, $hash, 0 );
}
return;
} }
sub _CheckIsDisabledAfterSetAttr { sub _CheckIsDisabledAfterSetAttr {
@ -399,48 +405,55 @@ sub PushToStorage {
Log3( $name, 4, qq{backupToStorage ($name) - after readings age return} ); Log3( $name, 4, qq{backupToStorage ($name) - after readings age return} );
require "SubProcess.pm"; if ( $hash->{STORAGETYPE} eq 'SynologyFileStation' ) {
my $subprocess = SubProcess->new( { onRun => \&FileUpload } );
}
else {
require "SubProcess.pm";
my $subprocess = SubProcess->new( { onRun => \&FileUpload } );
my $backupFile = ReadingsVal( $name, 'fhemBackupFile', 'none' ); my $backupFile = ReadingsVal( $name, 'fhemBackupFile', 'none' );
my @fileNameAtStorage_array = split( '/', $backupFile ); my @fileNameAtStorage_array = split( '/', $backupFile );
my $fileNameAtStorage = $fileNameAtStorage_array[$#fileNameAtStorage_array]; my $fileNameAtStorage = $fileNameAtStorage_array[$#fileNameAtStorage_array];
$subprocess->{curl} = qx(which curl); $subprocess->{curl} = qx(which curl);
chomp($subprocess->{curl}); chomp($subprocess->{curl});
$subprocess->{type} = $hash->{STORAGETYPE}; $subprocess->{type} = $hash->{STORAGETYPE};
$subprocess->{host} = AttrVal( $name, 'bTS_Host', '' ); $subprocess->{host} = AttrVal( $name, 'bTS_Host', '' );
$subprocess->{user} = AttrVal( $name, 'bTS_User', '' ); $subprocess->{user} = AttrVal( $name, 'bTS_User', '' );
$subprocess->{pass} = ReadPassword( $hash, $name ); $subprocess->{pass} = ReadPassword( $hash, $name );
$subprocess->{path} = AttrVal( $name, 'bTS_Path', '' ); $subprocess->{path} = AttrVal( $name, 'bTS_Path', '' );
$subprocess->{backupfile} = $backupFile; $subprocess->{backupfile} = $backupFile;
$subprocess->{fileNameAtStorage} = $fileNameAtStorage; $subprocess->{fileNameAtStorage} = $fileNameAtStorage;
$subprocess->{proto} = AttrVal( $name, 'bTS_Proto', 'https' ); $subprocess->{proto} = AttrVal( $name, 'bTS_Proto', 'https' );
$subprocess->{loglevel} = AttrVal( $name, 'verbose', 3 ); $subprocess->{loglevel} = AttrVal( $name, 'verbose', 3 );
my $pid = $subprocess->run(); my $pid = $subprocess->run();
readingsSingleUpdate( $hash, 'state', ' file upload in progress', 1 ); readingsSingleUpdate( $hash, 'state', ' file upload in progress', 1 );
if ( !defined($pid) ) { if ( !defined($pid) ) {
Log3( $name, 1, Log3( $name, 1,
qq{backupToStorage ($name) - Cannot execute command asynchronously} ); qq{backupToStorage ($name) - Cannot execute command asynchronously} );
CleanSubprocess($hash); CleanSubprocess($hash);
readingsSingleUpdate( $hash, 'state', readingsSingleUpdate( $hash, 'state',
'Cannot execute command asynchronously', 1 ); 'Cannot execute command asynchronously', 1 );
return undef; return undef;
}
Log3( $name, 4,
qq{backupToStorage ($name) - execute command asynchronously (PID="$pid")}
);
$hash->{".fhem"}{subprocess} = $subprocess;
InternalTimer( gettimeofday() + 1,
"FHEM::backupToStorage::PollChild", $hash );
} }
Log3( $name, 4,
qq{backupToStorage ($name) - execute command asynchronously (PID="$pid")}
);
$hash->{".fhem"}{subprocess} = $subprocess;
InternalTimer( gettimeofday() + 1,
"FHEM::backupToStorage::PollChild", $hash );
Log3( $hash, 4, Log3( $hash, 4,
qq{backupToStorage ($name) - control passed back to main loop.} ); qq{backupToStorage ($name) - control passed back to main loop.} );