Einstieg für $hash->{FW_detailFn} gesucht

Begonnen von ritchie, 14 August 2015, 18:55:34

Vorheriges Thema - Nächstes Thema

ritchie

Hallo Zusammen,

ich suche einen guten Einstieg für das Erstellen einer eigenen Routine für "$hash->{FW_detailFn}".

Ich möchte gerne die Darstellung im Web etwas anpassen. Eigenlich würde mir die Standard Routine reichen,
wenn ich hier noch weitere Werte darstellen könnte.

Viele Grüße

R.
IPU662  Ipfire & Fhem (Homematic + MAX) - Produktiv
Cubietruck (1Wire - USB) - Produktiv

justme1968

so etwas wie eine 'standard' routine gibt es nicht. die FW_detailFn ist modul spezifisch und auch nicht wirklich von aussen sinnvoll änderbar.

wenn es dir nur darum geht mehr als einen wert als STATE anzuzeigen schau dir stateFormat (und devStateStyle) an.

wenn es dir darum geht noch flexibler zu sein schau dir readingGroup an.

gruss
  andre
hue, tradfri, alexa-fhem, homebridge-fhem, LightScene, readingsGroup, ...

https://github.com/sponsors/justme-1968

ritchie

Hi,

ich habe mir jetzt zu Testzwecken die Routinen von "weblink" in mein Modul eingebunden und will mal sehen was da so passiert.


sub FOSCAM_Initialize($)
{
    my ($hash) = @_;
    $hash->{DefFn} = "FOSCAM_Define";
    $hash->{UndefFn} = "FOSCAM_Undefine";
    $hash->{ShutdownFn} = "FOSCAM_Shutdown";
    $hash->{AttrFn} = "FOSCAM_Attr";
    $hash->{SetFn} = "FOSCAM_Set";
    $hash->{GetFn} = "FOSCAM_Get";
    $hash->{FW_summaryFn} = "FOSCAM_FwFn";
    $hash->{FW_detailFn}  = "FOSCAM_FwFn";
    $hash->{FW_atPageEnd} = 1;   
    $hash->{AttrList} = "timeout poweronposition timestamp reconnecttime credentials snapshots storage username password ".
    "do_not_notify:0,1 ".$readingFnAttributes;
}


sub FOSCAM_FwDetail($@)
{
  my ($d, $text, $nobr)= @_;
  return "" if(AttrVal($d, "group", ""));
  my $alias= AttrVal($d, "alias", $d);

  my $ret = ($nobr ? "" : "<br>");
  $ret .= "$text " if($text);
  $ret .= FW_pHPlain("detail=$d", $alias) if(!$FW_subdir);
  $ret .= "<br>";
  return $ret;
}

sub FOSCAM_FwFn($$$$)
{
  my ($FW_wname, $d, $room, $pageHash) = @_; # pageHash is set for summaryFn.
  my $hash   = $defs{$d};
  my $link   = $hash->{LINK};
  my $wltype = $hash->{WLTYPE};
  my $ret = "";

     Log 1, "FOSCAM_FwFn: $wltype !";
 
  my $attr = AttrVal($d, "htmlattr", "");
  if($wltype eq "htmlCode") {
    $link = AnalyzePerlCommand(undef, $link) if($link =~ m/^{(.*)}$/);
    $ret = $link;

  } elsif($wltype eq "link") {
    $ret = "<a href=\"$link\" $attr>$d</a>"; # no FW_pH, open extra browser

  } elsif($wltype eq "image") {
    $ret = "<img src=\"$link\" $attr><br>" .
           FOSCAM_FwDetail($d);

  } elsif($wltype eq "iframe") {
    $ret = "<iframe src=\"$link\" $attr>Iframes disabled</iframe>" .
           FOSCAM_FwDetail($d);

  } elsif($wltype eq "cmdList") {

   
    my @lines = split(" ", $link);
    my $row = 1;
    $ret = "<table>";
    $ret .= "<tr><td><div class=\"devType\"><a href=\"/fhem?detail=$d\">".AttrVal($d, "alias", $d)."</a></div></td></tr>";
    $ret .= "<tr><td><table class=\"block wide\">";
    foreach my $line (@lines) {
      my @args = split(":", $line, 3);

      $ret .= "<tr class=\"".(($row++&1)?"odd":"even")."\">";
      $ret .= "<td><a href=\"/fhem?cmd=$args[2]\"><div class=\col1\"><img src=\"/fhem/icons/$args[0]\" width=19 height=19 align=\"center\" alt=\"$args[0]\" title=\"$args[0]\"> $args[1]</div></a></td></td>";
      $ret .= "</tr>";
    }
    $ret .= "</table></td></tr>";
    $ret .= "</table><br>";

  }

  return $ret;
}



Ich hätte jetzt erwartet, das ich entweder eine Fehlermeldung bekomme oder sich die Darstellung ändert.

Zumindestens hätte ich den LogEintrag erwartet, welchen ich in die Routine eingefügt habe.

Nichts von dem :-(   Reload und Shutdown Restart probiert.

Gruss R.
IPU662  Ipfire & Fhem (Homematic + MAX) - Produktiv
Cubietruck (1Wire - USB) - Produktiv

ritchie

#3
Mist Fehler gefunden. Editiere die Datei in einem anderen Rechner :-(.


Jetzt ist es aber so wie ich mir das vorgestellt habe. Ich kann ich darauf aufbauen:


015.08.14 19:41:02 1: FOSCAM_FwFn:  !
2015.08.14 19:41:04 1: FOSCAM_FwFn:  !
2015.08.14 19:41:04 1: FOSCAM_FwFn:  !


Gruss R.
IPU662  Ipfire & Fhem (Homematic + MAX) - Produktiv
Cubietruck (1Wire - USB) - Produktiv

ritchie

Hi,

für die Darstellung eines Bildes meiner WebCAM war es hier notwenig, diese Routine abzuändern.

Hier zeige ich direkt ein Bild von der Kamera an (Das macht automatisch mein Modul  (FOSCAM), wenn
ein Bild da ist. Ansonsten wird nur der Status dargestellt.

Im nächsten Schritt kommt evtl. noch der Stream als Option in dieser Anzeige.


sub FOSCAM_summaryFn($$$$)
{
my ($FW_wname, $Tagname, $room, $pageHash) = @_; # pageHash is set for summaryFn.
my $hash   = $defs{$Tagname};
my $ret = "";
my $lastSnapshot = "";
my $modpath = $attr{global}{modpath};
my $storage = (defined($attr{$Tagname}{storage}) ? $attr{$Tagname}{storage} : "$modpath/www/snapshots");

  $ret = $hash->{READINGS}{state}{VAL};

  if($hash->{STATE} eq 'online') 
    {
    my $Filename = $hash->{READINGS}{"lastsnapshot"}{VAL};
    if( length($Filename) > 0 )
      {
      $lastSnapshot = $storage."/".$hash->{READINGS}{"lastsnapshot"}{VAL};
      if(-e $lastSnapshot)
{
$lastSnapshot=replace("/opt/","./",$lastSnapshot);
$ret .= "<br><img src=\"$lastSnapshot\" ALT=\"CAM : $Tagname:$lastSnapshot\" WIDTH=\"$attr{$Tagname}{width}\" HEIGHT=\"$attr{$Tagname}{height}\"\" ><br>";
}
      }
    }
 
return $ret;
}



Vielleicht ja jemand, warum ich beim Schreiben der Datei den vollen Path brauche "/opt/fhem/www/snapshots" und wenn ich das ganze als Bild darstellen will, muss ich das relative (ohne /opt  -> ./fhem) angeben.  /opt  -> benötigt Root Rechte

Gruss R.
IPU662  Ipfire & Fhem (Homematic + MAX) - Produktiv
Cubietruck (1Wire - USB) - Produktiv