From 05b4a153b4cbd46ef47caefb940b062f253eae08 Mon Sep 17 00:00:00 2001 From: hcs-svn Date: Sat, 6 Sep 2014 04:13:42 +0000 Subject: [PATCH] Added the new module 98_CustomReadings.pm git-svn-id: svn://svn.code.sf.net/p/fhem/code/trunk@6503 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 1 + fhem/FHEM/98_CustomReadings.pm | 201 +++++++++++++++++++++++++++++ fhem/MAINTAINER.txt | 1 + fhem/docs/commandref_frame.html | 1 + fhem/docs/commandref_frame_DE.html | 1 + 5 files changed, 205 insertions(+) create mode 100644 fhem/FHEM/98_CustomReadings.pm diff --git a/fhem/CHANGED b/fhem/CHANGED index 7d8960e0e..22f1865b6 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,6 @@ # 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. + - added: 98_CustomReadings.pm (maintainer: HCS) - change: 98_Text2Speech.pm: fix a problem with microseconds in time() by using mp3-templates or playing mp3 directly - feature: state definition and split attribute added to 66_ECMD, diff --git a/fhem/FHEM/98_CustomReadings.pm b/fhem/FHEM/98_CustomReadings.pm new file mode 100644 index 000000000..e66593a29 --- /dev/null +++ b/fhem/FHEM/98_CustomReadings.pm @@ -0,0 +1,201 @@ + +# $Id$ +# +# TODO: + +package main; + +use strict; +use warnings; +use SetExtensions; + +sub +CustomReadings_Initialize($) +{ + my ($hash) = @_; + + $hash->{DefFn} = "CustomReadings_Define"; + $hash->{UndefFn} = "CustomReadings_Undef"; + $hash->{AttrList} = "readingDefinitions " + . "interval " + . "$readingFnAttributes"; +} + +sub +CustomReadings_Define($$) +{ + my ($hash, $def) = @_; + my $name = $hash->{NAME}; + + CustomReadings_read($hash); + + return undef; +} + +sub CustomReadings_read($) +{ + my ($hash) = @_; + my $name = $hash->{NAME}; + + RemoveInternalTimer($hash); + InternalTimer(gettimeofday()+ AttrVal( $name, "interval", 5), "CustomReadings_read", $hash, 0); + + # Get the readingDefinitions and remove all newlines from the attribute + my $readingDefinitions = AttrVal( $name, "readingDefinitions", ""); + $readingDefinitions =~ s/\n//g; + + my @definitionList = split(',', $readingDefinitions); + my @used = ("state"); + + readingsBeginUpdate($hash); + foreach (@definitionList) { + my @definition = split(':', $_, 2); + push(@used, $definition[0]); + + my $value = eval($definition[1]); + if($value) { + $value =~ s/^\s+|\s+$//g; + } + else { + $value = "ERROR"; + } + + readingsBulkUpdate($hash, $definition[0], $value); + } + + readingsEndUpdate($hash, 1); + + foreach my $r (keys %{$hash->{READINGS}}) { + if (not $r ~~ @used ) { + delete $hash->{READINGS}{$r}; + } + } + +} + + +sub +CustomReadings_Undef($$) +{ + my ($hash, $arg) = @_; + my $name = $hash->{NAME}; + + RemoveInternalTimer($hash); + + return undef; +} + + +1; + +=pod +=begin html + + +

CustomReadings

+ + + + +=end html +=cut diff --git a/fhem/MAINTAINER.txt b/fhem/MAINTAINER.txt index d62768ec5..fc849d443 100644 --- a/fhem/MAINTAINER.txt +++ b/fhem/MAINTAINER.txt @@ -236,6 +236,7 @@ FHEM/98_cloneDummy.pm Joachim http://forum.fhem.de Automatis FHEM/98_cmdalias.pm rudolfkoenig http://forum.fhem.de Automatisierung FHEM/98_configdb.pm betateilchen http://forum.fhem.de Sonstiges FHEM/98_copy.pm justme1968 http://forum.fhem.de Sonstiges +FHEM/98_CustomReadings.pm HCS http://forum.fhem.de Unterstuetzende Dienste FHEM/98_dewpoint.pm wherzig http://forum.fhem.de Automatisierung FHEM/98_dummy.pm rudolfkoenig http://forum.fhem.de Automatisierung FHEM/98_fheminfo.pm mfr69bs http://forum.fhem.de Sonstiges diff --git a/fhem/docs/commandref_frame.html b/fhem/docs/commandref_frame.html index b8a083ed9..dd47a37d8 100644 --- a/fhem/docs/commandref_frame.html +++ b/fhem/docs/commandref_frame.html @@ -93,6 +93,7 @@ average   Calendar   configDB   + CustomReadings   DOIF   Dashboard   DbLog   diff --git a/fhem/docs/commandref_frame_DE.html b/fhem/docs/commandref_frame_DE.html index 9c8157465..c097bda16 100644 --- a/fhem/docs/commandref_frame_DE.html +++ b/fhem/docs/commandref_frame_DE.html @@ -40,6 +40,7 @@ configdb   copy   createlog   + CustomReadings   define   delete   deleteattr