Ist es möglich bei Twilight das Attr disable einzubauen? Hintergrund ist, dass ich bei Ausfall des Internets sämtliche Module, welche Daten aus dem Internet holen deaktivieren will. Dazu gehört ja auch Twilight.
Maintainer ist igami
Lustigerweise hatte ich sowas mal angefangen, nicht nur disable sondern auch offline um nur die Kommunikation zeiweise abzuschalten.
Ist allerdings nicht wirklich getestet, hier ist der diff:
Index: 59_Twilight.pm
===================================================================
--- 59_Twilight.pm (revision 17326)
+++ 59_Twilight.pm (working copy)
@@ -53,7 +53,11 @@
$hash->{DefFn} = "Twilight_Define";
$hash->{UndefFn} = "Twilight_Undef";
$hash->{GetFn} = "Twilight_Get";
- $hash->{AttrList}= "$readingFnAttributes " ."useExtWeather";
+ $hash->{AttrList}= "$readingFnAttributes ".
+ "useExtWeather ".
+ "offline:0,1 ".
+ "disable:0,1 ";
+
return undef;
}
################################################################################
@@ -128,6 +132,10 @@
$attr{$name}{verbose} = 4 if ($name =~ /^tst.*$/ );
my $mHash = { HASH=>$hash };
+
+ my $name = $mHash->{NAME};
+ return undef if(IsDisabled($name));
+
Twilight_sunpos($mHash);
Twilight_Midnight($mHash);
@@ -379,6 +387,12 @@
my $hash = myGetHashIndirekt($myHash, (caller(0))[3]);
return if (!defined($hash));
+ my $name = $hash->{NAME};
+ if(IsDisabled($name) || AttrVal($name, "offline", 0) eq 1) {
+ Twilight_StandardTimerSet($hash);
+ return undef;
+ }
+
my $location = $hash->{WEATHER};
my $verbose = AttrVal($hash->{NAME}, "verbose", 3 );
@@ -457,6 +471,10 @@
myRemoveInternalTimer ("Midnight", $hash);
myInternalTimer ("Midnight", $midnight, "Twilight_Midnight", $hash, 0);
+
+ my $name = $hash->{NAME};
+ return undef if(AttrVal($name, "offline", 0) eq 1);
+
Twilight_WeatherTimerSet ($hash);
}
################################################################################
@@ -528,6 +546,17 @@
$cond_code = $resHash->{query}{results}{channel}{item}{condition}{code};
$cond_txt = $resHash->{query}{results}{channel}{item}{condition}{text};
$temperatur = $resHash->{query}{results}{channel}{item}{condition}{temp};
+
+ if (defined($cond_code) ) {
+ readingsBeginUpdate($hash);
+ readingsBulkUpdate ($hash, "temperature", $resHash->{query}{results}{channel}{item}{condition}{temp}) if(defined($resHash->{query}{results}{channel}{item}{condition}{temp}));
+ readingsBulkUpdate ($hash, "humidity", $resHash->{query}{results}{channel}{atmosphere}{humidity}) if(defined($resHash->{query}{results}{channel}{atmosphere}{humidity}));
+ readingsBulkUpdate ($hash, "visibility", $resHash->{query}{results}{channel}{atmosphere}{visibility}) if(defined($resHash->{query}{results}{channel}{atmosphere}{visibility}));
+ readingsBulkUpdate ($hash, "wind", $resHash->{query}{results}{channel}{wind}{speed}) if(defined($resHash->{query}{results}{channel}{wind}{speed}));
+ readingsBulkUpdate ($hash, "fc_high", $resHash->{query}{results}{channel}{item}{forecast}[0]{high}) if(defined($resHash->{query}{results}{channel}{item}{forecast}[0]{high}));
+ readingsBulkUpdate ($hash, "fc_low", $resHash->{query}{results}{channel}{item}{forecast}[0]{low}) if(defined($resHash->{query}{results}{channel}{item}{forecast}[0]{low}));
+ readingsEndUpdate($hash,1);
+ }
}
}
}
@@ -562,10 +591,9 @@
my $hash = myGetHashIndirekt($myHash, (caller(0))[3]);
return if (!defined($hash));
- my $hashName = $hash->{NAME};
+ my $name = $hash->{NAME};
+ return undef if(IsDisabled($name));
- return "" if(AttrVal($hashName, "disable", undef));
-
my $tn = TimeNow();
my ($dSeconds,$dMinutes,$dHours,$iDay,$iMonth,$iYear,$wday,$yday,$isdst) = gmtime(time);
$iMonth++;
@@ -644,7 +672,7 @@
my $twilight_weather ;
- if( (my $ExtWeather = AttrVal($hashName, "useExtWeather", "")) eq "") {
+ if( (my $ExtWeather = AttrVal($name, "useExtWeather", "")) eq "") {
$twilight_weather = int(($dElevation-$hash->{WEATHER_HORIZON}+12.0)/18.0 * 1000)/10;
Log3 $hash, 5, "[$hash->{NAME}] " . "Original weather readings";
} else {
Schau ich mir mal an. Dank dir.