2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-12 14:47:26 +00:00

10_ZWave.pm: add pepper device images (Forum #43218)

git-svn-id: https://svn.fhem.de/fhem/trunk@9719 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2015-10-29 20:49:22 +00:00
parent 87244a34ad
commit 2052f1b0bd
3 changed files with 95 additions and 1 deletions

View File

@ -8,6 +8,7 @@ use warnings;
use SetExtensions;
use Compress::Zlib;
use Time::HiRes qw( gettimeofday );
use HttpUtils;
sub ZWave_Cmd($$@);
sub ZWave_Get($@);
@ -20,6 +21,7 @@ sub ZWave_secEnd($);
use vars qw(%zw_func_id);
use vars qw(%zw_type6);
use vars qw($FW_ME);
my %zwave_id2class;
my %zwave_class = (
@ -442,6 +444,8 @@ use vars qw(%zwave_deviceSpecial);
my $zwave_cryptRijndael = 0;
my $zwave_lastHashSent;
my %zwave_pepperLink;
my %zwave_pepperImg;
sub
ZWave_Initialize($)
@ -466,6 +470,29 @@ ZWave_Initialize($)
} else {
$zwave_cryptRijndael = 1;
}
################
# Read in the pepper translation table
my $fn = $attr{global}{modpath}."/FHEM/lib/zwave_pepperlinks.csv.gz";
my $gz = gzopen($fn, "rb");
if($gz) {
my $line;
while($gz->gzreadline($line)) {
chomp($line);
my @a = split(",",$line);
$zwave_pepperLink{$a[0]} = $a[1];
$zwave_pepperImg{$a[0]} = $a[2];
}
$gz->gzclose();
} else {
Log 3, "Can't open $fn: $!";
}
# Create cache directory
$fn = $attr{global}{modpath}."/www/deviceimages";
if(! -d $fn) { mkdir($fn) || Log 3, "Can't create $fn"; }
$fn .= "/zwave";
if(! -d $fn) { mkdir($fn) || Log 3, "Can't create $fn"; }
}
@ -2921,8 +2948,30 @@ ZWave_fhemwebFn($$$$)
{
my ($FW_wname, $d, $room, $pageHash) = @_; # pageHash is set for summaryFn.
my $pl=""; # Pepper link and image
my $model = ReadingsVal($d, "modelId", "");
if($model) {
$pl .= "<div class='zwavepepper' style='float:right'>";
my $img = $zwave_pepperImg{$model};
if($img) {
$pl .= "<img style='width:160px;' src='$FW_ME/deviceimages/zwave/$img'>";
my $fn = $attr{global}{modpath}."/www/deviceimages/zwave/$img";
if(!-f $fn) { # Cache the picture
my $data = GetFileFromURL("http://fhem.de/deviceimages/zwave/$img");
if($data && open(FH,">$fn")) {
print FH $data;
close(FH)
}
}
}
my $link = $zwave_pepperLink{$model};
$pl .= "<br><a href='http://www.pepper1.net/zwavedb/device/".
"$link'>Details in pepper1.net</a>" if($link);
$pl .= "</div>";
}
return
'<div id="ZWHelp" class="makeTable help"></div>'.
'<div id="ZWHelp" class="makeTable help"></div>'.$pl.
'<script type="text/javascript">'.
"var d='$d';" . <<'JSEND'
$(document).ready(function() {

Binary file not shown.

View File

@ -0,0 +1,45 @@
#!/usr/bin/perl
# Details in Forum #35416
if(@ARGV == 0) {
print "Usage:\n".
" mkdir -p <fhem>/www/deviceimages/zwave\n".
" cd <fhem>/www/deviceimages/zwave\n".
" wget http://www.pepper1.net/zwavedb/device/export/device_archive.zip\n".
" unzip device_archive.zip\n".
" perl <fhem>/contrib/zwave_pepperconvert.pl *.xml\n".
" sh getpics.sh\n".
" rm *.xml *.txt *.sh *.zip\n".
" mv zwave_pepperlinks.csv <fhem>/FHEM/lib\n";
exit 1;
}
open(F1, ">zwave_pepperlinks.csv") || die("zwave_pepperlinks.csv: $!\n");
open(F2, ">getpics.sh") || die("getpics.sh: $!\n");
my $d="";
my %toget;
while(my $l = <>) {
if($l =~ m,<deviceImage\s*url="(.*)"\s*/>,) {
$d = $1;
$d =~ s/^\s*//;
$d =~ s/\s*$//;
}
if($l =~ m,</ZWaveDevice,i) {
my $lf = $d;
$lf =~ s,^.*/,,;
if($ARGV =~ m/^([0-9A-F]+)-([0-9A-F]+)-([0-9A-F]+)-([0-9A-F]+)-/i) {
print F1 "$2-$3-$4,$1,$lf\n";
} else {
print F1 "$ARGV\n";
}
if($lf && !-f $lf && !$toget{$lf}) {
printf F2 "wget $d\n";
$toget{$lf} = 1;
}
$d="";
}
}
close(F1);
close(F2);