code clean to make faster

This commit is contained in:
Marko Oldenburg
2019-03-04 10:10:53 +01:00
parent 3910a46c5d
commit 6c955f9a88

View File

@@ -881,15 +881,19 @@ sub EventProcessingRoommate($@) {
"AutoShuttersControl ($name) - EventProcessingRoommate: $shuttersDev und Events $events" "AutoShuttersControl ($name) - EventProcessingRoommate: $shuttersDev und Events $events"
); );
my $getModeUp = $shutters->getModeUp;
my $getModeDown = $shutters->getModeDown;
my $getRoommatesLastStatus = $shutters->getRoommatesLastStatus
if ( if (
( $1 eq 'home' or $1 eq 'awoken' ) ( $1 eq 'home' or $1 eq 'awoken' )
and ( $shutters->getRoommatesStatus eq 'home' and ( $shutters->getRoommatesStatus eq 'home'
or $shutters->getRoommatesStatus eq 'awoken' ) or $shutters->getRoommatesStatus eq 'awoken' )
and $ascDev->getAutoShuttersControlMorning eq 'on' and $ascDev->getAutoShuttersControlMorning eq 'on'
and ( $shutters->getModeUp eq 'home' and ( $getModeUp eq 'home'
or $shutters->getModeUp eq 'always' or $getModeUp eq 'always'
or $shutters->getModeDown eq 'home' or $getModeDown eq 'home'
or $shutters->getModeDown eq 'always' ) or $getModeDown eq 'always' )
) )
{ {
Log3( $name, 4, Log3( $name, 4,
@@ -897,13 +901,13 @@ sub EventProcessingRoommate($@) {
); );
if ( if (
( (
$shutters->getRoommatesLastStatus eq 'asleep' $getRoommatesLastStatus eq 'asleep'
or $shutters->getRoommatesLastStatus eq 'awoken' or $getRoommatesLastStatus eq 'awoken'
) )
and IsDay( $hash, $shuttersDev ) and IsDay( $hash, $shuttersDev )
and IsAfterShuttersTimeBlocking( $hash, $shuttersDev ) and IsAfterShuttersTimeBlocking( $hash, $shuttersDev )
and ( $shutters->getModeUp eq 'home' and ( $getModeUp eq 'home'
or $shutters->getModeUp eq 'always' ) or $getModeUp eq 'always' )
) )
{ {
Log3( $name, 4, Log3( $name, 4,
@@ -916,17 +920,17 @@ sub EventProcessingRoommate($@) {
if ( if (
( (
$shutters->getRoommatesLastStatus eq 'absent' $getRoommatesLastStatus eq 'absent'
or $shutters->getRoommatesLastStatus eq 'gone' or $getRoommatesLastStatus eq 'gone'
or $shutters->getRoommatesLastStatus eq 'home' or $getRoommatesLastStatus eq 'home'
) )
and $shutters->getRoommatesStatus eq 'home' and $shutters->getRoommatesStatus eq 'home'
) )
{ {
if ( not IsDay( $hash, $shuttersDev ) if ( not IsDay( $hash, $shuttersDev )
and IsAfterShuttersTimeBlocking( $hash, $shuttersDev ) and IsAfterShuttersTimeBlocking( $hash, $shuttersDev )
and ( $shutters->getModeDown eq 'home' and ( $getModeDown eq 'home'
or $shutters->getModeDown eq 'always' ) or $getModeDown eq 'always' )
) )
{ {
my $position; my $position;
@@ -948,8 +952,8 @@ sub EventProcessingRoommate($@) {
elsif ( IsDay( $hash, $shuttersDev ) elsif ( IsDay( $hash, $shuttersDev )
and $shutters->getStatus == $shutters->getClosedPos and $shutters->getStatus == $shutters->getClosedPos
and IsAfterShuttersTimeBlocking( $hash, $shuttersDev ) and IsAfterShuttersTimeBlocking( $hash, $shuttersDev )
and ( $shutters->getModeUp eq 'home' and ( $getModeUp eq 'home'
or $shutters->getModeUp eq 'always') ) or $getModeUp eq 'always') )
{ {
$shutters->setLastDrive('roommate home'); $shutters->setLastDrive('roommate home');
ShuttersCommandSet( $hash, $shuttersDev, ShuttersCommandSet( $hash, $shuttersDev,
@@ -959,8 +963,8 @@ sub EventProcessingRoommate($@) {
} }
elsif ( elsif (
( (
$shutters->getModeDown eq 'always' $getModeDown eq 'always'
or $shutters->getModeDown eq 'home' or $getModeDown eq 'home'
) )
and ( $1 eq 'gotosleep' or $1 eq 'asleep' ) and ( $1 eq 'gotosleep' or $1 eq 'asleep' )
and $ascDev->getAutoShuttersControlEvening eq 'on' and $ascDev->getAutoShuttersControlEvening eq 'on'
@@ -982,7 +986,7 @@ sub EventProcessingRoommate($@) {
ShuttersCommandSet( $hash, $shuttersDev, $position ); ShuttersCommandSet( $hash, $shuttersDev, $position );
} }
elsif ( $shutters->getModeDown eq 'absent' elsif ( $getModeDown eq 'absent'
and $1 eq 'absent' and $1 eq 'absent'
and not IsDay( $hash, $shuttersDev ) ) and not IsDay( $hash, $shuttersDev ) )
{ {
@@ -998,6 +1002,10 @@ sub EventProcessingResidents($@) {
my $name = $device; my $name = $device;
my $reading = $ascDev->getResidentsReading; my $reading = $ascDev->getResidentsReading;
my $getModeUp = $shutters->getModeUp;
my $getModeDow = $getModeDown;
my $getResidentsLastStatus = $ascDev->getResidentsLastStatus;
if ( $events =~ m#$reading:\s(absent)# ) { if ( $events =~ m#$reading:\s(absent)# ) {
foreach my $shuttersDev ( @{ $hash->{helper}{shuttersList} } ) { foreach my $shuttersDev ( @{ $hash->{helper}{shuttersList} } ) {
$shutters->setShuttersDev($shuttersDev); $shutters->setShuttersDev($shuttersDev);
@@ -1008,8 +1016,8 @@ sub EventProcessingResidents($@) {
and $shutters->getSelfDefenseExclude eq 'off' and $shutters->getSelfDefenseExclude eq 'off'
or ( or (
( (
$shutters->getModeDown eq 'absent' $getModeDown eq 'absent'
or $shutters->getModeDown eq 'always' or $getModeDown eq 'always'
) )
and not IsDay( $hash, $shuttersDev ) and not IsDay( $hash, $shuttersDev )
and IsAfterShuttersTimeBlocking( $hash, $shuttersDev ) and IsAfterShuttersTimeBlocking( $hash, $shuttersDev )
@@ -1042,10 +1050,10 @@ sub EventProcessingResidents($@) {
} }
elsif ( elsif (
$events =~ m#$reading:\s(home)# $events =~ m#$reading:\s(home)#
and ( $ascDev->getResidentsLastStatus eq 'absent' and ( $getResidentsLastStatus eq 'absent'
or $ascDev->getResidentsLastStatus eq 'gone' or $getResidentsLastStatus eq 'gone'
or $ascDev->getResidentsLastStatus eq 'asleep' or $getResidentsLastStatus eq 'asleep'
or $ascDev->getResidentsLastStatus eq 'awoken' ) or $getResidentsLastStatus eq 'awoken' )
) )
{ {
foreach my $shuttersDev ( @{ $hash->{helper}{shuttersList} } ) { foreach my $shuttersDev ( @{ $hash->{helper}{shuttersList} } ) {
@@ -1055,10 +1063,10 @@ sub EventProcessingResidents($@) {
$shutters->getStatus != $shutters->getClosedPos $shutters->getStatus != $shutters->getClosedPos
and not IsDay( $hash, $shuttersDev ) and not IsDay( $hash, $shuttersDev )
and $shutters->getRoommatesStatus eq 'none' and $shutters->getRoommatesStatus eq 'none'
and ( $shutters->getModeDown eq 'home' and ( $getModeDown eq 'home'
or $shutters->getModeDown eq 'always' ) or $getModeDown eq 'always' )
and ( $ascDev->getResidentsLastStatus ne 'asleep' and ( $getResidentsLastStatus ne 'asleep'
or $ascDev->getResidentsLastStatus ne 'awoken' ) or $getResidentsLastStatus ne 'awoken' )
and IsAfterShuttersTimeBlocking( $hash, $shuttersDev ) and IsAfterShuttersTimeBlocking( $hash, $shuttersDev )
) )
{ {
@@ -1069,10 +1077,10 @@ sub EventProcessingResidents($@) {
$ascDev->getSelfDefense eq 'on' $ascDev->getSelfDefense eq 'on'
and CheckIfShuttersWindowRecOpen($shuttersDev) != 0 and CheckIfShuttersWindowRecOpen($shuttersDev) != 0
and $shutters->getSelfDefenseExclude eq 'off' and $shutters->getSelfDefenseExclude eq 'off'
or ( $ascDev->getResidentsLastStatus eq 'gone' or ( $getResidentsLastStatus eq 'gone'
and $shutters->getShuttersPlace eq 'terrace' ) and $shutters->getShuttersPlace eq 'terrace' )
and ( $shutters->getModeUp eq 'absent' and ( $getModeUp eq 'absent'
or $shutters->getModeUp eq 'off' ) or $getModeUp eq 'off' )
) )
{ {
$shutters->setLastDrive('selfeDefense inactive'); $shutters->setLastDrive('selfeDefense inactive');
@@ -1085,13 +1093,13 @@ sub EventProcessingResidents($@) {
$shutters->getStatus == $shutters->getClosedPos $shutters->getStatus == $shutters->getClosedPos
and IsDay( $hash, $shuttersDev ) and IsDay( $hash, $shuttersDev )
and $shutters->getRoommatesStatus eq 'none' and $shutters->getRoommatesStatus eq 'none'
and ( $shutters->getModeUp eq 'home' and ( $getModeUp eq 'home'
or $shutters->getModeUp eq 'always' ) or $getModeUp eq 'always' )
and IsAfterShuttersTimeBlocking( $hash, $shuttersDev ) and IsAfterShuttersTimeBlocking( $hash, $shuttersDev )
) )
{ {
if ( $ascDev->getResidentsLastStatus eq 'asleep' if ( $getResidentsLastStatus eq 'asleep'
or $ascDev->getResidentsLastStatus eq 'awoken' ) or $getResidentsLastStatus eq 'awoken' )
{ {
$shutters->setLastDrive('residents awoken'); $shutters->setLastDrive('residents awoken');
} }
@@ -1439,25 +1447,27 @@ sub ShadingProcessing($@) {
} }
if ( $shutters->getShading eq 'out' or $shutters->getShading eq 'in' ) { if ( $shutters->getShading eq 'out' or $shutters->getShading eq 'in' ) {
my $getShadingPos = $shutters->getShadingPos;
$shutters->setShading( $shutters->getShading ) $shutters->setShading( $shutters->getShading )
if ( ( int( gettimeofday() ) - $shutters->getShadingTimestamp ) >= if ( ( int( gettimeofday() ) - $shutters->getShadingTimestamp ) >=
( $shutters->getShadingWaitingPeriod / 2 ) ); ( $shutters->getShadingWaitingPeriod / 2 ) );
if ( $shutters->getShading eq 'in' if ( $shutters->getShading eq 'in'
and $shutters->getShadingPos != $shutters->getStatus ) and $getShadingPos != $shutters->getStatus )
{ {
my $queryShuttersShadingPos = ( my $queryShuttersShadingPos = (
$shutters->getShuttersPosCmdValueNegate $shutters->getShuttersPosCmdValueNegate
? $shutters->getStatus > $shutters->getShadingPos ? $shutters->getStatus > $getShadingPos
: $shutters->getStatus < $shutters->getShadingPos : $shutters->getStatus < $getShadingPos
); );
$shutters->setLastDrive('shading in'); $shutters->setLastDrive('shading in');
ShuttersCommandSet( $hash, $shuttersDev, $shutters->getShadingPos ) ShuttersCommandSet( $hash, $shuttersDev, $getShadingPos )
if ( not $queryShuttersShadingPos ); if ( not $queryShuttersShadingPos );
} }
elsif ( $shutters->getShading eq 'out' elsif ( $shutters->getShading eq 'out'
and $shutters->getShadingPos == $shutters->getStatus ) and $getShadingPos == $shutters->getStatus )
{ {
$shutters->setLastDrive('shading out'); $shutters->setLastDrive('shading out');
ShuttersCommandSet( $hash, $shuttersDev, $shutters->getLastPos ); ShuttersCommandSet( $hash, $shuttersDev, $shutters->getLastPos );