98_GAEBUS.pm: use utf-8 coding for values read from .csv files

git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@9254 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
jamesgo 2015-09-15 08:33:14 +00:00
parent 71a983530d
commit 02f8ab101a

View File

@ -11,7 +11,7 @@
# 11.09.2015 : A.Goebel : add set w~ commands to set attributes for writing # 11.09.2015 : A.Goebel : add set w~ commands to set attributes for writing
# 11.09.2015 : A.Goebel : add set <write-reading> command to write to ebusd # 11.09.2015 : A.Goebel : add set <write-reading> command to write to ebusd
# 13.09.2015 : A.Goebel : increase timeout for reads from ebusd from 1.8 to 5.0 # 13.09.2015 : A.Goebel : increase timeout for reads from ebusd from 1.8 to 5.0
# 13.09.2015 : A.Goebel : use html entities to display values from ".csv" files # 14.09.2015 : A.Goebel : use utf-8 coding to display values from ".csv" files
package main; package main;
@ -20,6 +20,7 @@ use warnings;
use Time::HiRes qw(gettimeofday); use Time::HiRes qw(gettimeofday);
use IO::Socket; use IO::Socket;
use IO::Select; use IO::Select;
use Encode;
sub GAEBUS_Attr(@); sub GAEBUS_Attr(@);
@ -182,6 +183,8 @@ GAEBUS_Set($@)
#Log3 ($hash, 3, "ebus1: reopen $name"); #Log3 ($hash, 3, "ebus1: reopen $name");
#Log3 ($hash, 2, "$name: set $arg $type invalid parameter");
if ($type eq "reopen") { if ($type eq "reopen") {
Log3 ($hash, 3, "ebus1: reopen"); Log3 ($hash, 3, "ebus1: reopen");
GAEBUS_CloseDev($hash); GAEBUS_CloseDev($hash);
@ -608,7 +611,6 @@ GAEBUS_ProcessCSV($$)
} }
else else
{ {
my $line; my $line;
my $buffer = ""; my $buffer = "";
@ -619,28 +621,31 @@ GAEBUS_ProcessCSV($$)
$defCircuit =~ s,^.*/,,; $defCircuit =~ s,^.*/,,;
$defCircuit =~ s/\.csv$//; $defCircuit =~ s/\.csv$//;
binmode(CSV, ':encoding(utf-8)');
while (<CSV>) while (<CSV>)
{ {
next if /^#/; next if /^#/;
next if /^\s$/; next if /^\s$/;
s/\r//; s/\r//;
s/ä/\&auml;/g; #s/ä/\&auml;/g;
s/Ä/\&Auml;/g; #s/Ä/\&Auml;/g;
s/ü/\&uuml;/g; #s/ü/\&Auml;/g;
s/Ü/\&Uuml;/g; #s/Ü/\&Uuml;/g;
s/ö/\&ouml;/g; #s/ö/\&ouml;/g;
s/Ö/\&Ouml;/g; #s/Ö/\&Ouml;/g;
s/ß/\&szlig;/g; #s/ß/\&szlig;/g;
#s/"/\&quot;/g; #s/"/\&quot;/g;
chomp; chomp;
$line = $_; $line = encode("UTF-8", $_);
$line =~ s/ /_/g; # no blanks in names and comments $line =~ s/ /_/g; # no blanks in names and comments
$line =~ s/$delimiter/_/g; # clean up the delimiter within the text $line =~ s/$delimiter/_/g; # clean up the delimiter within the text
#$line =~ s/\|/_/g; # later used as delimiter in arguments #$line =~ s/\|/_/g; # later used as delimiter in arguments
#Log3 ($hash, 2, "READ $file $line");
my ($io, $circuit, $vname, $comment, @params) = split (",", $line, 5); my ($io, $circuit, $vname, $comment, @params) = split (",", $line, 5);
# handle defaults: "^*" # handle defaults: "^*"