error handling for action queue
This commit is contained in:
		| @@ -137,6 +137,9 @@ sub TeslaPowerwall2AC_Define($$) { | |||||||
|     $hash->{PORT}           = 80; |     $hash->{PORT}           = 80; | ||||||
|     $hash->{VERSION}        = $version; |     $hash->{VERSION}        = $version; | ||||||
|      |      | ||||||
|  |     # ensure actionQueue exists | ||||||
|  |     $hash->{actionQueue} = [] if( not defined($hash->{actionQueue}) ); | ||||||
|  |  | ||||||
|  |  | ||||||
|     $attr{$name}{room} = "Tesla" if( !defined( $attr{$name}{room} ) ); |     $attr{$name}{room} = "Tesla" if( !defined( $attr{$name}{room} ) ); | ||||||
|      |      | ||||||
| @@ -204,10 +207,15 @@ sub TeslaPowerwall2AC_Attr(@) { | |||||||
|      |      | ||||||
|     if( $attrName eq "interval" ) { |     if( $attrName eq "interval" ) { | ||||||
|         if( $cmd eq "set" ) { |         if( $cmd eq "set" ) { | ||||||
|  |             if( $attrVal < 180 ) { | ||||||
|  |                 Log3 $name, 3, "TeslaPowerwall2AC ($name) - interval too small, please use something >= 180 (sec), default is 300 (sec)"; | ||||||
|  |                 return "interval too small, please use something >= 180 (sec), default is 300 (sec)"; | ||||||
|  |              | ||||||
|  |             } else { | ||||||
|                 $hash->{INTERVAL} = $attrVal; |                 $hash->{INTERVAL} = $attrVal; | ||||||
|                 Log3 $name, 3, "TeslaPowerwall2AC ($name) - set interval to $attrVal"; |                 Log3 $name, 3, "TeslaPowerwall2AC ($name) - set interval to $attrVal"; | ||||||
|                 TeslaPowerwall2AC_Timer_GetData($hash) if($init_done); |                 TeslaPowerwall2AC_Timer_GetData($hash) if($init_done); | ||||||
|              |             } | ||||||
|         } elsif( $cmd eq "del" ) { |         } elsif( $cmd eq "del" ) { | ||||||
|             $hash->{INTERVAL} = 300; |             $hash->{INTERVAL} = 300; | ||||||
|             Log3 $name, 3, "TeslaPowerwall2AC ($name) - set interval to default"; |             Log3 $name, 3, "TeslaPowerwall2AC ($name) - set interval to default"; | ||||||
| @@ -224,9 +232,6 @@ sub TeslaPowerwall2AC_Get($@) { | |||||||
|     my $arg; |     my $arg; | ||||||
|  |  | ||||||
|  |  | ||||||
|     # ensure actionQueue exists |  | ||||||
|     $hash->{actionQueue} = [] if( not defined($hash->{actionQueue}) ); |  | ||||||
|  |  | ||||||
|     if( $cmd eq 'statusSOE' ) { |     if( $cmd eq 'statusSOE' ) { | ||||||
|  |  | ||||||
|         $arg    = lc($cmd); |         $arg    = lc($cmd); | ||||||
| @@ -262,6 +267,9 @@ sub TeslaPowerwall2AC_Get($@) { | |||||||
|         return "Unknown argument $cmd, choose one of $list"; |         return "Unknown argument $cmd, choose one of $list"; | ||||||
|     } |     } | ||||||
|      |      | ||||||
|  |     return 'There are still path commands in the action queue' | ||||||
|  |     if( defined($hash->{actionQueue}) and scalar(@{$hash->{actionQueue}}) > 0 ); | ||||||
|  |      | ||||||
|     unshift( @{$hash->{actionQueue}}, $arg ); |     unshift( @{$hash->{actionQueue}}, $arg ); | ||||||
|     TeslaPowerwall2AC_GetData($hash); |     TeslaPowerwall2AC_GetData($hash); | ||||||
|  |  | ||||||
| @@ -274,6 +282,7 @@ sub TeslaPowerwall2AC_Timer_GetData($) { | |||||||
|     my $name    = $hash->{NAME}; |     my $name    = $hash->{NAME}; | ||||||
|      |      | ||||||
|      |      | ||||||
|  |     delete $hash->{actionQueue} = [] if( defined($hash->{actionQueue}) and scalar(@{$hash->{actionQueue}}) > 0 ); | ||||||
|     RemoveInternalTimer($hash); |     RemoveInternalTimer($hash); | ||||||
|      |      | ||||||
|     # ensure actionQueue exists |     # ensure actionQueue exists | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user