From c897299103ea8efb15dc37c5a256f4e2baf47182 Mon Sep 17 00:00:00 2001 From: Marko Oldenburg Date: Fri, 30 Oct 2020 15:19:18 +0100 Subject: [PATCH] add mor support for disable and disabledForIntervals add check IsDisabled function --- controls_backupToStorage.txt | 2 +- lib/FHEM/backupToStorage.pm | 35 ++++++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/controls_backupToStorage.txt b/controls_backupToStorage.txt index 9a5482f..091a520 100644 --- a/controls_backupToStorage.txt +++ b/controls_backupToStorage.txt @@ -1,2 +1,2 @@ UPD 2020-10-28_19:14:19 6242 FHEM/98_backupToStorage.pm -UPD 2020-10-28_19:13:53 17356 lib/FHEM/backupToStorage.pm +UPD 2020-10-30_15:17:14 18433 lib/FHEM/backupToStorage.pm diff --git a/lib/FHEM/backupToStorage.pm b/lib/FHEM/backupToStorage.pm index ee031f0..50a3fbe 100644 --- a/lib/FHEM/backupToStorage.pm +++ b/lib/FHEM/backupToStorage.pm @@ -204,6 +204,7 @@ sub Notify { my $devtype = $dev->{TYPE}; my $events = deviceEvents( $dev, 1 ); + _CheckIsDisabledAfterSetAttr($hash); return if ( !$events || IsDisabled($name) ); @@ -322,15 +323,43 @@ sub Attr { my $cmd = shift; my $name = shift; + my $hash = $defs{$name}; my $attrName = shift; my $attrVal = shift; - if ( $cmd eq 'set' ) { - - + + if ( $attrName eq 'disable' + || $attrName eq 'disabledForIntervals' ) { + + if ( $cmd eq 'set' ) { + if ( $attrName eq 'disabledForIntervals' ) { + return + 'check disabledForIntervals Syntax HH:MM-HH:MM or HH:MM-HH:MM HH:MM-HH:MM ...' + if ( $attrVal !~ /^((\d{2}:\d{2})-(\d{2}:\d{2})\s?)+$/ ); + Log3( $name, 3, "backupToStorage ($name) - disabledForIntervals" ); + } + elsif ( $attrName eq 'disable' ) { + Log3( $name, 3, "backupToStorage ($name) - disabled" ); + } + } + + InternalTimer( gettimeofday() + 1, + 'FHEM::backupToStorage::_CheckIsDisabledAfterSetAttr', $hash, 0 ); } } +sub _CheckIsDisabledAfterSetAttr { + my $hash = shift; + + my $name = $hash->{NAME}; + my $state = ( IsDisabled($name) + ? 'disabled' + : 'ready' ); + + readingsSingleUpdate($hash, 'state', $state, 1) + if ( ReadingsVal($name, 'state', 'ready' ) ne $state ); +} + sub Rename { my $new = shift; my $old = shift;