From 27e20d2e0787e917943e9a6536269d7015b0bac3 Mon Sep 17 00:00:00 2001 From: Marko Oldenburg Date: Mon, 11 Nov 2019 19:16:47 +0100 Subject: [PATCH] add advent support from 1. Advent to 6th january --- 73_AutoShuttersControl.pm | 108 ++++++++++++++++++++++++++++++++++---- 1 file changed, 97 insertions(+), 11 deletions(-) diff --git a/73_AutoShuttersControl.pm b/73_AutoShuttersControl.pm index 5ac7c60..4302978 100644 --- a/73_AutoShuttersControl.pm +++ b/73_AutoShuttersControl.pm @@ -250,7 +250,8 @@ my %userAttrList = ( 'ASC_DriveUpMaxDuration' => '-', 'ASC_WindProtection:on,off' => '-', 'ASC_RainProtection:on,off' => '-', - 'ASC_ExternalTrigger' => '-' + 'ASC_ExternalTrigger' => '-', + 'ASC_Adv:on,off' => '-' ); my %posSetCmds = ( @@ -623,6 +624,10 @@ sub Set($$@) { return "usage: $cmd" if ( @args > 1 ); readingsSingleUpdate( $hash, $cmd, join( ' ', @args ), 1 ); } + elsif ( lc $cmd eq 'advdrivedown' ) { + return "usage: $cmd" if ( @args != 0 ); + EventProcessingAdvShuttersClose($hash); + } elsif ( lc $cmd eq 'shutterascenabletoggle' ) { return "usage: $cmd" if ( @args > 1 ); readingsSingleUpdate( @@ -644,7 +649,7 @@ sub Set($$@) { else { my $list = 'scanForShutters:noArg'; $list .= -' renewAllTimer:noArg partyMode:on,off hardLockOut:on,off sunriseTimeWeHoliday:on,off controlShading:on,off selfDefense:on,off ascEnable:on,off wiggle:all,' +' renewAllTimer:noArg advDriveDown:noArg partyMode:on,off hardLockOut:on,off sunriseTimeWeHoliday:on,off controlShading:on,off selfDefense:on,off ascEnable:on,off wiggle:all,' . join( ',', @{ $hash->{helper}{shuttersList} } ) . ' shutterASCenableToggle:' . join( ',', @{ $hash->{helper}{shuttersList} } ) @@ -2433,7 +2438,7 @@ sub ShadingProcessingDriveCommand($$) { } sub EventProcessingPartyMode($) { - my ($hash) = @_; + my $hash = shift; my $name = $hash->{NAME}; foreach my $shuttersDev ( @{ $hash->{helper}{shuttersList} } ) { @@ -2482,6 +2487,30 @@ sub EventProcessingPartyMode($) { } } +sub EventProcessingAdvShuttersClose($) { + my $hash = shift; + my $name = $hash->{NAME}; + + foreach my $shuttersDev ( @{ $hash->{helper}{shuttersList} } ) { + $shutters->setShuttersDev($shuttersDev); + next + if ( not $shutters->getAdv + and not $shutters->getAdvDelay ); + + $shutters->setLastDrive('adv delay close'); + $shutters->setAdvDelay(1); + ShuttersCommandSet( + $hash, + $shuttersDev, + ( + $shutters->getDelayCmd ne 'none' + ? $shutters->getDelayCmd + : $shutters->getClosedPos + ) + ); + } +} + sub EventProcessingShutters($@) { my ( $hash, $shuttersDev, $events ) = @_; my $name = $hash->{NAME}; @@ -2659,9 +2688,6 @@ sub ShuttersCommandSet($$$) { } else { $shutters->setDriveCmd($posValue); - $shutters->setDelayCmd('none') - if ( $shutters->getDelayCmd ne 'none' ) - ; # setzt den Wert auf none da der Rolladen nun gesteuert werden kann. $ascDev->setLastPosReading; Log3( $name, 4, "AutoShuttersControl ($name) - ShuttersCommandSet setDriveCmd wird aufgerufen" @@ -4183,6 +4209,28 @@ sub PrivacyDownTime($$) { return $shuttersSunsetUnixtime; } +sub _IsAdv { + my ( undef, undef, undef, $monthday, $month, $year, undef, undef, undef ) = + localtime( gettimeofday() ); + my $adv = 0; + $year += 1900; + + if ( $month < 1 ) { + if ( $monthday < 7 ) { + $adv = 1; + } + } + else { + my $time = HTTP::Date::str2time( $year . '-12-25' ); + my $wday = ( localtime($time) )[6]; + $wday = $wday ? $wday : 7; + $time -= ( $wday + 21 ) * 86400; + $adv = 1 if ( $time < time ); + } + + return $adv; +} + ###################################### ###################################### ########## Begin der Klassendeklarierungen für OOP (Objektorientierte Programmierung) ######################### @@ -4286,20 +4334,29 @@ sub setDriveCmd { my $offSet; my $offSetStart; - if ( $shutters->getPartyMode eq 'on' - and $ascDev->getPartyMode eq 'on' ) + if ( + ( $shutters->getPartyMode eq 'on' and $ascDev->getPartyMode eq 'on' ) + or ( $shutters->getAdv + and not $shutters->getQueryShuttersPos($posValue) + and not $shutters->getAdvDelay ) + ) { - $shutters->setDelayCmd($posValue); $ascDev->setDelayCmdReading; $shutters->setNoDelay(0); FHEM::AutoShuttersControl::ASC_Debug( 'setDriveCmd: ' . $shutters->getShuttersDev - . ' - Die Fahrt wird zurückgestellt. Grund kann ein geöffnetes Fenster sein oder ein aktivierter Party Modus' + . ' - Die Fahrt wird zurückgestellt. Grund kann ein geöffnetes Fenster sein oder ein aktivierter Party Modus oder Weihnachtszeit' ); } else { + $shutters->setAdvDelay(0) + if ( $shutters->getAdvDelay ); + $shutters->setDelayCmd('none') + if ( $shutters->getDelayCmd ne 'none' ) + ; # setzt den Wert auf none da der Rolladen nun gesteuert werden kann. + ### antifreeze Routine if ( $shutters->getFreezeStatus > 0 ) { if ( $shutters->getFreezeStatus != 1 ) { @@ -4488,6 +4545,23 @@ sub setPrivacyUpStatus { return 0; } +sub setAdvDelay { + my ( $self, $advDelay ) = @_; + + $self->{ $self->{shuttersDev} }->{AdvDelay} = $advDelay; + return 0; +} + +sub getAdvDelay { + my $self = shift; + + return ( + defined( $self->{ $self->{shuttersDev} }->{AdvDelay} ) + ? $self->{ $self->{shuttersDev} }->{AdvDelay} + : 0 + ); +} + sub getPrivacyDownStatus { my $self = shift; @@ -5141,6 +5215,16 @@ sub getWiggleValue { return AttrVal( $self->{shuttersDev}, 'ASC_WiggleValue', 5 ); } +sub getAdv { + my $self = shift; + + return ( + AttrVal( $self->{shuttersDev}, 'ASC_Adv', 'off' ) eq 'on' + ? ( FHEM::AutoShuttersControl::_IsAdv ? 1 : 0 ) + : 0 + ); +} + ### Begin Beschattung sub getShadingPos { my $self = shift; @@ -7473,6 +7557,7 @@ sub getblockAscDrivesAfterManual { Set