2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-10 09:16:53 +00:00

fhem.pl: check reading names for illegal characters (Forum #45788)

git-svn-id: https://svn.fhem.de/fhem/trunk@10204 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2015-12-19 16:07:11 +00:00
parent afea7a121a
commit f269739b86
2 changed files with 27 additions and 1 deletions

View File

@ -185,6 +185,7 @@ FHT_Initialize($)
$hash->{DefFn} = "FHT_Define";
$hash->{UndefFn} = "FHT_Undef";
$hash->{ParseFn} = "FHT_Parse";
$hash->{StateFn} = "FHT_State";
$hash->{AttrList} = "IODev do_not_notify:1,0 model:fht80b dummy:1,0 " .
"showtime:1,0 retrycount " .
"minfhtbuffer lazy tmpcorr ignore:1,0 ".
@ -566,7 +567,7 @@ FHT_Parse($$)
Log3 $name, 4, "FHT $name windowsensor: $valSensor";
}
$cmd = "FHZ:$cmd" if(substr($msg,24,1) eq "7");
$cmd = "FHZ_$cmd" if(substr($msg,24,1) eq "7");
readingsBulkUpdate($def, $cmd, $val);
if($cmd eq "measured-temp") {
@ -704,6 +705,21 @@ getFhtBuffer($)
}
}
#####################################
# Remap the old FHZ: readingnames to FHZ_
sub
FHT_State($$$$)
{
my ($hash, $tim, $rname, $rval) = @_;
return undef if($rname !~ m/^FHZ:/);
my $newname = $rname;
$newname =~ s/:/_/g;
setReadingsVal($hash, $newname, $rval, $tim);
return "FHT: renamed reading $rname to $newname for $hash->{NAME}";
}
1;
=pod

View File

@ -2548,6 +2548,10 @@ CommandSetstate($$)
next;
}
Log3 $d, 3, "WARNING: unsupported character in reading $sname ".
"(not A-Za-z\\d_\\.-), notify the $d->{TYPE} module maintainer."
if($sname !~ m/^[A-Za-z\d_\.-]+$/);
if(!defined($d->{READINGS}{$sname}) ||
!defined($d->{READINGS}{$sname}{TIME}) ||
$d->{READINGS}{$sname}{TIME} lt $tim) {
@ -3796,6 +3800,12 @@ readingsBeginUpdate($)
my ($hash)= @_;
my $name = $hash->{NAME};
if(!$name) {
Log 1, "ERROR: empty name in readingsBeginUpdate";
stacktrace();
return;
}
# get timestamp
my $now = gettimeofday();
my $fmtDateTime = FmtDateTime($now);