2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-02-08 05:15:10 +00:00

55_InfoPanel.pm: code rework to use own package

git-svn-id: https://svn.fhem.de/fhem/trunk@23675 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
betateilchen 2021-02-04 19:41:41 +00:00
parent b6fbf60fd9
commit c5f6854eed

View File

@ -61,34 +61,66 @@
# 2016-09-04 - 12114 - added: movecalculated # 2016-09-04 - 12114 - added: movecalculated
# #
# 2018-05-06 - 16695 - changed: check plotName exists # 2018-05-06 - 16695 - changed: check plotName exists
# 2018-05-28 - $Rev$ - changed: remove misleading link in commandref # 2018-05-28 - 21562 - changed: remove misleading link in commandref
#
# 2021-02-04 - - changed: use own package
# #
############################################## ##############################################
=cut =cut
package main; package FHEM::InfoPanel; ## no critic
use strict; use strict;
use warnings; use warnings;
use Data::Dumper; #use Data::Dumper;
#use HttpUtils;
##############################################
use GPUtils qw(GP_Import GP_Export);
BEGIN {
# Import from main context
GP_Import(
qw( AttrVal
Debug
Log3
data
defs
FileRead
getKeyValue
readingFnAttributes
readingsSingleUpdate
setKeyValue
FW_userAgent
FW_wname
FW_RET
FW_webArgs
FW_pos
FW_plotsize
FW_ME
FW_httpheader
FW_CSRF )
);
#-- Export to main context with different name
GP_Export(
qw( Initialize )
);
}
##############################################
no if $] >= 5.017011, warnings => 'experimental';
use feature qw/switch/; use feature qw/switch/;
use vars qw(%data); use vars qw(%data);
use HttpUtils;
my @valid_valign = qw(auto baseline middle center hanging); my @valid_valign = qw(auto baseline middle center hanging);
my @valid_halign = qw(start middle end); my @valid_halign = qw(start middle end);
my $useImgTools = 1; my $useImgTools = 1;
no if $] >= 5.017011, warnings => 'experimental'; ##############################################
sub btIP_Define;
sub btIP_Undef;
sub btIP_Set;
sub btIP_Get;
sub btIP_Notify;
sub btIP_readLayout;
sub btIP_itemArea; sub btIP_itemArea;
sub btIP_itemButton; sub btIP_itemButton;
@ -130,10 +162,9 @@ sub btIP_HTMLTail;
sub btIP_Overview; sub btIP_Overview;
sub btIP_getURL; sub btIP_getURL;
###################################### ######################################
sub InfoPanel_Initialize { sub Initialize {
my ($hash) = @_; my ($hash) = @_;
## no critic ## no critic
@ -145,11 +176,12 @@ sub InfoPanel_Initialize {
Log3(undef,4,"InfoPanel: Image::Info missing.") unless $useImgTools; Log3(undef,4,"InfoPanel: Image::Info missing.") unless $useImgTools;
## use critic ## use critic
$hash->{DefFn} = "btIP_Define"; $hash->{DefFn} = \&Define;
$hash->{UndefFn} = "btIP_Undef"; $hash->{UndefFn} = \&Undef;
$hash->{SetFn} = "btIP_Set"; $hash->{SetFn} = \&Set;
$hash->{GetFn} = "btIP_Get"; $hash->{GetFn} = \&Get;
$hash->{NotifyFn} = "btIP_Notify"; $hash->{NotifyFn} = \&Notify;
$hash->{AttrList} = "autoreread:1,0 useViewPort:1,0 bgcolor refresh size "; $hash->{AttrList} = "autoreread:1,0 useViewPort:1,0 bgcolor refresh size ";
$hash->{AttrList} .= "mobileApp:none,apple,other "; $hash->{AttrList} .= "mobileApp:none,apple,other ";
$hash->{AttrList} .= "title noscript showTime:1,0 "; $hash->{AttrList} .= "title noscript showTime:1,0 ";
@ -158,7 +190,7 @@ sub InfoPanel_Initialize {
return; return;
} }
sub btIP_Define { sub Define {
my ($hash, $def) = @_; my ($hash, $def) = @_;
my @a = split("[ \t]+", $def); my @a = split("[ \t]+", $def);
return "Usage: define <name> InfoPanel filename" if(int(@a) != 3); return "Usage: define <name> InfoPanel filename" if(int(@a) != 3);
@ -169,14 +201,14 @@ sub btIP_Define {
$hash->{fhem}{div} = ''; $hash->{fhem}{div} = '';
$hash->{LAYOUTFILE} = $filename; $hash->{LAYOUTFILE} = $filename;
btIP_addExtension("btIP_CGI","btip","InfoPanel"); btIP_addExtension("FHEM::InfoPanel::btIP_CGI","btip","InfoPanel");
btIP_readLayout($hash); readLayout($hash);
readingsSingleUpdate($hash,'state','defined',1); readingsSingleUpdate($hash,'state','defined',1);
return; return;
} }
sub btIP_Undef { sub Undef {
my ($hash, $arg) = @_; my ($hash, $arg) = @_;
# check if last device # check if last device
my $url = '/btip'; my $url = '/btip';
@ -184,7 +216,7 @@ sub btIP_Undef {
return; return;
} }
sub btIP_Set { sub Set {
my ($hash, @a) = @_; my ($hash, @a) = @_;
my $name = $a[0]; my $name = $a[0];
@ -208,7 +240,7 @@ sub btIP_Set {
$defs{$name}{fhem}{override}{$a[2]} = 1; $defs{$name}{fhem}{override}{$a[2]} = 1;
} }
when ("reread") { when ("reread") {
btIP_readLayout($hash); readLayout($hash);
} }
default { default {
$ret = $usage; $ret = $usage;
@ -217,7 +249,7 @@ sub btIP_Set {
return $ret; return $ret;
} }
sub btIP_Get { sub Get {
my ($hash, @a) = @_; my ($hash, @a) = @_;
my $name = $a[0]; my $name = $a[0];
@ -245,7 +277,7 @@ sub btIP_Get {
return $ret; return $ret;
} }
sub btIP_Notify { sub Notify {
my ($hash,$dev) = @_; my ($hash,$dev) = @_;
return unless AttrVal($hash->{NAME},'autoreload',1); return unless AttrVal($hash->{NAME},'autoreload',1);
@ -253,11 +285,11 @@ sub btIP_Notify {
return if(!grep(m/^FILEWRITE $hash->{LAYOUTFILE}$/, @{$dev->{CHANGED}})); return if(!grep(m/^FILEWRITE $hash->{LAYOUTFILE}$/, @{$dev->{CHANGED}}));
Log3(undef, 4, "InfoPanel: $hash->{NAME} reread layout after edit."); Log3(undef, 4, "InfoPanel: $hash->{NAME} reread layout after edit.");
undef = btIP_readLayout($hash); undef = readLayout($hash);
return; return;
} }
sub btIP_readLayout { sub readLayout {
my ($hash)= @_; my ($hash)= @_;
my $filename= $hash->{LAYOUTFILE}; my $filename= $hash->{LAYOUTFILE};
my $name= $hash->{NAME}; my $name= $hash->{NAME};
@ -267,7 +299,7 @@ sub btIP_readLayout {
if($err) { if($err) {
# Log 1, "InfoPanel $name: $err"; # Log 1, "InfoPanel $name: $err";
# $hash->{fhem}{layout} = "text ERROR 50 50 \"Error on reading layout!\""; # $hash->{fhem}{layout} = "text ERROR 50 50 \"Error on reading layout!\"";
Log 1, "InfoPanel $name: $err"; Log3(undef, 1, "InfoPanel $name: $err");
$hash->{fhem}{layout} = "text ERROR 50 50 \"Error on reading layout!\""; $hash->{fhem}{layout} = "text ERROR 50 50 \"Error on reading layout!\"";
my ($e,@layout) = FileRead('./FHEM/template.layout'); my ($e,@layout) = FileRead('./FHEM/template.layout');
unless ($e){ unless ($e){
@ -1350,31 +1382,6 @@ sub btIP_addExtension {
$data{FWEXT}{jqueryvticker}{SCRIPT} = "/pgm2/jquery.vticker.min.js" unless $data{FWEXT}{jqueryvticker}{SCRIPT}; $data{FWEXT}{jqueryvticker}{SCRIPT} = "/pgm2/jquery.vticker.min.js" unless $data{FWEXT}{jqueryvticker}{SCRIPT};
} }
sub btIP_CGI{
my ($request) = @_;
my ($name,$ext)= btIP_splitRequest($request);
if(defined($name)) {
if($ext eq "") {
return("text/plain; charset=utf-8", "Illegal extension.");
}
if(!defined($defs{$name})) {
return("text/plain; charset=utf-8", "Unknown InfoPanel device: $name");
}
if($ext eq "png") {
return btIP_returnPNG($name);
}
if($ext eq "info" || $ext eq "html") {
return btIP_returnHTML($name);
}
} else {
return btIP_Overview();
}
}
sub btIP_splitRequest { sub btIP_splitRequest {
my ($request) = @_; my ($request) = @_;
@ -1487,6 +1494,37 @@ sub btIP_getURL {
return $proto."://$FW_httpheader{Host}$FW_ME"; return $proto."://$FW_httpheader{Host}$FW_ME";
} }
####################
#
#package main;
sub btIP_CGI{
my ($request) = @_;
my ($name,$ext)= btIP_splitRequest($request);
if(defined($name)) {
if($ext eq "") {
return("text/plain; charset=utf-8", "Illegal extension.");
}
if(!defined($defs{$name})) {
return("text/plain; charset=utf-8", "Unknown InfoPanel device: $name");
}
if($ext eq "png") {
return btIP_returnPNG($name);
}
if($ext eq "info" || $ext eq "html") {
return btIP_returnHTML($name);
}
} else {
return btIP_Overview();
}
}
1; 1;
# #