Hallo,
Um in einer Perl-Routine feststellen zu können, ob Fhem initialisiert wurde, habe ich es so gelöst:
define n_init_fhem notify global:INITIALIZED { fhem("set init_done true");; }
attr n_init_fhem group Notify
attr n_init_fhem room Heating
define n_shutdown_fhem notify global:SHUTDOWN { fhem("set init_done false");; }
attr n_shutdown_fhem group Notify
attr n_shutdown_fhem room Heating
define init_done dummy
attr init_done group Control
attr init_done room Control
attr init_done setList true false
In der Perl Routine kann ich dann den Status abfragen.
if (InternalVal("init_done", "NAME", "not found") ne "not found") {
if (Value("init_done") eq "true") {
....
}
}
Gibt es eine einfachere Lösung ohne den Umweg über einen dummy?
$init_done ist eine globale Variable, man muss es also direkt (ohne InternalVal o.ae.) abfragen.
Zitat von: rudolfkoenig am 21 August 2014, 09:25:31
$init_done ist eine globale Variable, man muss es also direkt (ohne InternalVal o.ae.) abfragen.
... dann nur so:
if (Value("init_done") eq "true") {
....
}
Verstehe ich es richtig, eine andere Lösung als mit dem dummy gibt es nicht?
Sowas wie InternalVal('global','init_done',"")
Zitat von: flurin am 21 August 2014, 09:41:06
... dann nur so:
if (Value("init_done") eq "true") {
Nein, das ist falsch.
Richtig wäre:
if ($init_done) {
...
}
Zitat von: flurin am 21 August 2014, 09:41:06
Verstehe ich es richtig
Bisher offenbar nicht.
Fhem stellt diese Variable von Haus aus bereit. Du musst Dich nicht um irgendwelche Wertzuweisungen kümmern,
die Werte werden automatisch gesetzt:$init_done = 1 wenn fhem initialisiert
$init_done = 0 wenn fhem nicht initialisiert ist (das passiert übrigens durchaus auch während des laufenden Betriebs, zum Beispiel während ein rereadcfg ausgeführt wird.
Zitat von: betateilchen am 21 August 2014, 09:48:23
Richtig wäre:
if ($init_done) {
...
}
OK, "$init_done" ist eine globale Variable, verstanden!
Ich wusste es nicht, dass $init_done bereits als globale Variable existierte und habe einen dummy zufällig mit dem gleichen Name "init_done" definiert!
Danke.
... falls jemand hier landet. Man findet globale Variablen wie $init_done in fhem.pl.