mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 06:39:11 +00:00
50_Signalbot: native SVG plot and DOIF uiTable widget handling
git-svn-id: https://svn.fhem.de/fhem/trunk@25587 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
10e522f13b
commit
38fe672ccd
@ -1,5 +1,6 @@
|
|||||||
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
||||||
# Do not insert empty lines here, update check depends on it.
|
# Do not insert empty lines here, update check depends on it.
|
||||||
|
- feature: 50_Signalbot: native SVG plot and DOIF uiTable widget handling
|
||||||
- change: 32_withings: updated oauth endpoint
|
- change: 32_withings: updated oauth endpoint
|
||||||
- feature: 31_HUEDevice: added v2effect command
|
- feature: 31_HUEDevice: added v2effect command
|
||||||
- bugfix: 14_Hideki.pm: fix match regex - forum:#125679
|
- bugfix: 14_Hideki.pm: fix match regex - forum:#125679
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
##############################################
|
##############################################
|
||||||
#$Id$
|
#$Id$
|
||||||
my $Signalbot_VERSION="3.4";
|
my $Signalbot_VERSION="3.5";
|
||||||
# Simple Interface to Signal CLI running as Dbus service
|
# Simple Interface to Signal CLI running as Dbus service
|
||||||
# Author: Adimarantis
|
# Author: Adimarantis
|
||||||
# License: GPL
|
# License: GPL
|
||||||
@ -401,7 +401,7 @@ sub Signalbot_Set($@) { #
|
|||||||
my @newatt;
|
my @newatt;
|
||||||
foreach my $file (@attachments) {
|
foreach my $file (@attachments) {
|
||||||
if ( -e $file ) {
|
if ( -e $file ) {
|
||||||
if ($file =~ /[tmp\/signalbot]/) {
|
if (! $file =~ /tmp\/signalbot/) {
|
||||||
$file =~ /^.*?\.([^.]*)?$/;
|
$file =~ /^.*?\.([^.]*)?$/;
|
||||||
my $type = $1;
|
my $type = $1;
|
||||||
my $tmpfilename="/tmp/signalbot".gettimeofday().".".$type;
|
my $tmpfilename="/tmp/signalbot".gettimeofday().".".$type;
|
||||||
@ -411,7 +411,9 @@ sub Signalbot_Set($@) { #
|
|||||||
push @newatt, $file;
|
push @newatt, $file;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return "File not found: $file";
|
my $png=Signalbot_getPNG($hash,$file);
|
||||||
|
return "File not found: $file" if !defined $png;
|
||||||
|
push @newatt, $png;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@attachments=@newatt;
|
@attachments=@newatt;
|
||||||
@ -1911,21 +1913,10 @@ sub Signalbot_replaceCommands(@) {
|
|||||||
my ( $isMediaStream, $type ) = Signalbot_IdentifyStream( $hash, $msg );
|
my ( $isMediaStream, $type ) = Signalbot_IdentifyStream( $hash, $msg );
|
||||||
if ($isMediaStream<0) {
|
if ($isMediaStream<0) {
|
||||||
Log3 $hash->{NAME}, 5, $hash->{NAME}.": Media stream found $isMediaStream $type";
|
Log3 $hash->{NAME}, 5, $hash->{NAME}.": Media stream found $isMediaStream $type";
|
||||||
my $tmpfilename="/tmp/signalbot".gettimeofday().".".$type;
|
my $ret=Signalbot_copyToFile($msg,$type);
|
||||||
my $fh;
|
return ("Can't write to temporary file",@processed) if !defined $ret;
|
||||||
#tempfile() would be the better way, but is not readable by signal-cli (how to set world-readable?)
|
|
||||||
#could be changed with "chmod 0666, $tmpfilename;" which should even work on Windows, but what's the point - dbus/signal-cli works on Linux only anyways
|
|
||||||
#my ($fh, $tmpfilename) = tempfile();
|
|
||||||
if(!open($fh, ">", $tmpfilename,)) {
|
|
||||||
#if (!defined $fh) {
|
|
||||||
Log3 $hash->{NAME}, 3, $hash->{NAME}.": Can't write $tmpfilename";
|
|
||||||
#return undef since this is a fatal error
|
|
||||||
return ("Can't write $tmpfilename",@processed);
|
|
||||||
}
|
|
||||||
print $fh $msg;
|
|
||||||
close($fh);
|
|
||||||
#If we created a file return the filename instead
|
#If we created a file return the filename instead
|
||||||
push @processed, $tmpfilename;
|
push @processed, $ret;
|
||||||
} else {
|
} else {
|
||||||
Log3 $hash->{NAME}, 5, $hash->{NAME}.": normal text found:$msg";
|
Log3 $hash->{NAME}, 5, $hash->{NAME}.": normal text found:$msg";
|
||||||
#No mediastream - return what it was
|
#No mediastream - return what it was
|
||||||
@ -1941,6 +1932,144 @@ sub Signalbot_replaceCommands(@) {
|
|||||||
return (undef,@processed);
|
return (undef,@processed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub Signalbot_copyToFile(@) {
|
||||||
|
my ($msg,$type) = @_;
|
||||||
|
my $tmpfilename="/tmp/signalbot".gettimeofday().".".$type;
|
||||||
|
my $fh;
|
||||||
|
if(!open($fh, ">", $tmpfilename,)) {
|
||||||
|
#return undef since this is a fatal error
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
print $fh $msg;
|
||||||
|
close($fh);
|
||||||
|
return $tmpfilename;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub Signalbot_getPNG(@) {
|
||||||
|
my ($hash, $file) = @_;
|
||||||
|
|
||||||
|
my @special=split(",",$file);
|
||||||
|
#does the first part equal to a FHEM device?
|
||||||
|
my $sname = shift @special;
|
||||||
|
my $shash = $defs{$sname};
|
||||||
|
if (defined $shash) {
|
||||||
|
Log3 $hash->{NAME}, 4 , $hash->{NAME}.": Attachment matches device $sname of type $shash->{TYPE}";
|
||||||
|
my $svg;
|
||||||
|
if ($shash->{TYPE} eq "SVG") {
|
||||||
|
$svg=plotAsPng($sname,@special);
|
||||||
|
}
|
||||||
|
if ($shash->{TYPE} eq "DOIF") {
|
||||||
|
$svg=Signalbot_DOIFAsPng($shash,@special);
|
||||||
|
}
|
||||||
|
return undef if !defined $svg;
|
||||||
|
return Signalbot_copyToFile($svg,"png");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub
|
||||||
|
Signalbot_DOIFAsPng($@)
|
||||||
|
{
|
||||||
|
my ($hash,@params) = @_;
|
||||||
|
my (@webs, $mimetype, $svgdata, $rsvg, $pngImg);
|
||||||
|
|
||||||
|
my $matchid=-1;
|
||||||
|
my $sizex=-1;
|
||||||
|
my $sizey=-1;
|
||||||
|
my $zoom=1.0;
|
||||||
|
my $matchdev="";
|
||||||
|
my $matchread="";
|
||||||
|
my $target="uiTable";
|
||||||
|
|
||||||
|
#If no further information given, take the first entry of uitables
|
||||||
|
if (@params == 0) {
|
||||||
|
$matchid=1;
|
||||||
|
} else {
|
||||||
|
foreach my $p (@params) {
|
||||||
|
my @par=split("=",$p);
|
||||||
|
my $cm=shift @par;
|
||||||
|
my $val=shift @par;
|
||||||
|
$matchid=$p if looks_like_number($p);
|
||||||
|
next if (!defined $cm || !defined $val);
|
||||||
|
if ($cm eq "id") {
|
||||||
|
$matchid=$val if looks_like_number($val);
|
||||||
|
} elsif ($cm eq "zoom") {
|
||||||
|
$zoom=$val if looks_like_number($val);
|
||||||
|
} elsif ($cm eq "dev") {
|
||||||
|
$matchdev=$val;
|
||||||
|
} elsif ($cm eq "val") {
|
||||||
|
$matchread=$val;
|
||||||
|
} elsif ($cm eq "sizex") {
|
||||||
|
$sizex=$val if looks_like_number($val);
|
||||||
|
} elsif ($cm eq "sizey") {
|
||||||
|
$sizey=$val if looks_like_number($val);
|
||||||
|
} elsif ($cm eq "state") {
|
||||||
|
$target="uiState";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$target="uiState" if (!defined $hash->{$target}{table});
|
||||||
|
my $table=$hash->{$target}{table};
|
||||||
|
|
||||||
|
# "Error: uiTable/uiState not defined"
|
||||||
|
return undef if (!defined $table);
|
||||||
|
|
||||||
|
my $id=0;
|
||||||
|
my $cmd;
|
||||||
|
OUTER:
|
||||||
|
for (my $i=0;$i < scalar keys %{$table};$i++){
|
||||||
|
for (my $k=0;$k < scalar keys %{$table->{$i}};$k++){
|
||||||
|
for (my $l=0;$l < scalar keys %{$table->{$i}{$k}};$l++){
|
||||||
|
for (my $m=0;$m < scalar keys %{$table->{$i}{$k}{$l}};$m++) {
|
||||||
|
$id++;
|
||||||
|
my $tab=$table->{$i}{$k}{$l}{$m};
|
||||||
|
$tab =~ /.*DOIF_Widget\(.*?,.*?,.*?,(.*),.*\)/;
|
||||||
|
$cmd=$1;
|
||||||
|
next if !defined $cmd;
|
||||||
|
if ($matchid==$id) {
|
||||||
|
last OUTER;
|
||||||
|
} elsif ($matchid==-1) {
|
||||||
|
$cmd =~ /.*ReadingValDoIf\(\$hash,\'(.*?)\',\'(.*?)\'.*\)/;
|
||||||
|
next if ($matchdev ne "" && $matchdev ne $1);
|
||||||
|
next if ($matchread ne "" && $matchread ne $2);
|
||||||
|
last OUTER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#Nothing found, since if something found we skip out with "last"
|
||||||
|
$cmd="";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (defined $cmd && $cmd ne "") {
|
||||||
|
$cmd="package ui_Table;"."$cmd".";";
|
||||||
|
$svgdata=eval($cmd);
|
||||||
|
print $@;
|
||||||
|
} else {
|
||||||
|
#print "Error: uiTable format error (no card)";
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
|
||||||
|
# "Error: getting data from card"
|
||||||
|
return undef if (! defined $svgdata);
|
||||||
|
$svgdata='<?xml version="1.0" encoding="UTF-8"?> <svg>'.$svgdata.'</svg>';
|
||||||
|
|
||||||
|
eval {
|
||||||
|
require Image::LibRSVG;
|
||||||
|
$rsvg = new Image::LibRSVG();
|
||||||
|
if ($sizex != -1 && $sizey !=-1) {
|
||||||
|
$rsvg->loadFromStringAtZoomWithMax($svgdata, $zoom, $zoom, $sizex, $sizey );
|
||||||
|
} else {
|
||||||
|
$rsvg->loadFromStringAtZoom($svgdata, $zoom, $zoom);
|
||||||
|
}
|
||||||
|
$pngImg = $rsvg->getImageBitmap();
|
||||||
|
};
|
||||||
|
if (defined $pngImg && $pngImg ne "") {
|
||||||
|
return $pngImg if $pngImg;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
#Get OSRelease Version
|
#Get OSRelease Version
|
||||||
sub Signalbot_OSRel() {
|
sub Signalbot_OSRel() {
|
||||||
my $fh;
|
my $fh;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
#$Id:$
|
#$Id:$
|
||||||
SCRIPTVERSION="3.3"
|
SCRIPTVERSION="3.5"
|
||||||
# Author: Adimarantis
|
# Author: Adimarantis
|
||||||
# License: GPL
|
# License: GPL
|
||||||
#Install script for signal-cli
|
#Install script for signal-cli
|
||||||
@ -20,7 +20,7 @@ OPERATION=$1
|
|||||||
JAVA_VERSION=11.0
|
JAVA_VERSION=11.0
|
||||||
|
|
||||||
if [ $OPERATION = "experimental" ]; then
|
if [ $OPERATION = "experimental" ]; then
|
||||||
SIGNALVERSION="0.10.1"
|
SIGNALVERSION="0.10.2"
|
||||||
JAVA_VERSION=17.0
|
JAVA_VERSION=17.0
|
||||||
OPERATION=
|
OPERATION=
|
||||||
fi
|
fi
|
||||||
@ -157,13 +157,22 @@ fi
|
|||||||
GLIBC=`ldd --version | grep -m1 -o '[0-9]\.[0-9][0-9]' | head -n 1`
|
GLIBC=`ldd --version | grep -m1 -o '[0-9]\.[0-9][0-9]' | head -n 1`
|
||||||
|
|
||||||
IDENTSTR=$ARCH-glibc$GLIBC-$SIGNALVERSION
|
IDENTSTR=$ARCH-glibc$GLIBC-$SIGNALVERSION
|
||||||
KNOWN=("amd64-glibc2.27-0.9.0" "amd64-glibc2.28-0.9.0" "amd64-glibc2.31-0.9.0" "armhf-glibc2.28-0.9.0" "amd64-glibc2.27-0.9.2" "amd64-glibc2.28-0.9.2" "amd64-glibc2.31-0.9.2" "armhf-glibc2.28-0.9.2" "armhf-glibc2.31-0.9.2" "armhf-glibc2.31-0.10.1")
|
KNOWN=("amd64-glibc2.27-0.9.2" "amd64-glibc2.28-0.9.2" "amd64-glibc2.31-0.9.2" "armhf-glibc2.28-0.9.2" "armhf-glibc2.31-0.9.2" "armhf-glibc2.31-0.10.2" "armhf-glibc2.28-0.10.2" "amd64-glibc2.27-0.10.2" "amd64-glibc2.31-0.10.2")
|
||||||
|
|
||||||
GETLIBS=1
|
GETLIBS=1
|
||||||
if [[ ! " ${KNOWN[*]} " =~ " ${IDENTSTR} " ]]; then
|
if [[ ! " ${KNOWN[*]} " =~ " ${IDENTSTR} " ]]; then
|
||||||
echo "$IDENTSTR is an unsupported combination - signal-cli binary libraries might not work"
|
echo "$IDENTSTR is an unsupported combination - signal-cli binary libraries might not work"
|
||||||
GETLIBS=0
|
if [ $ARCH = "amd64" && $GLIBC < "2.31" ]; then
|
||||||
|
GLIBC=2.28
|
||||||
|
echo "Fallback to GLIBC $GLIBC";
|
||||||
|
elif [ $ARCH = "armhf" && $GLIBC < "2.31" ]; then
|
||||||
|
GLIBC=2.27
|
||||||
|
echo "Fallback to GLIBC $GLIBC";
|
||||||
|
else
|
||||||
|
GETLIBS=0
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
IDENTSTR=$ARCH-glibc$GLIBC-$SIGNALVERSION
|
||||||
|
|
||||||
if [ $OSNAME != "Linux" ]; then
|
if [ $OSNAME != "Linux" ]; then
|
||||||
echo "Only Linux systems are supported (you: $OSNAME), quitting"
|
echo "Only Linux systems are supported (you: $OSNAME), quitting"
|
||||||
@ -284,7 +293,7 @@ if ! [ "$JAVA_VERSION" = "$JVER" ]; then
|
|||||||
rm /tmp/$JAVA_ARC
|
rm /tmp/$JAVA_ARC
|
||||||
echo "done"
|
echo "done"
|
||||||
fi
|
fi
|
||||||
JAVA_HOME=/opt/java
|
export JAVA_HOME=/opt/java
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -352,12 +361,6 @@ if [ $NEEDINSTALL = 1 ]; then
|
|||||||
fi
|
fi
|
||||||
echo "done"
|
echo "done"
|
||||||
rm -f /tmp/signal-cli-$SIGNALVERSION.tar.gz
|
rm -f /tmp/signal-cli-$SIGNALVERSION.tar.gz
|
||||||
cd /opt/signal/bin
|
|
||||||
mv signal-cli signal-cli.org
|
|
||||||
echo "#!/bin/sh" >signal-cli
|
|
||||||
echo "JAVA_HOME=$JAVA_HOME" >>signal-cli
|
|
||||||
cat signal-cli.org >>signal-cli
|
|
||||||
chmod a+x signal-cli
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -411,6 +414,7 @@ After=network-online.target
|
|||||||
[Service]
|
[Service]
|
||||||
Type=dbus
|
Type=dbus
|
||||||
Environment="SIGNAL_CLI_OPTS=-Xms2m"
|
Environment="SIGNAL_CLI_OPTS=-Xms2m"
|
||||||
|
Environment="JAVA_HOME=$JAVA_HOME"
|
||||||
ExecStart=$SIGNALPATH/signal/bin/signal-cli --config $SIGNALVAR daemon --system
|
ExecStart=$SIGNALPATH/signal/bin/signal-cli --config $SIGNALVAR daemon --system
|
||||||
User=$SIGNALUSER
|
User=$SIGNALUSER
|
||||||
BusName=org.asamk.Signal
|
BusName=org.asamk.Signal
|
||||||
|
Loading…
Reference in New Issue
Block a user