# $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; } sub CustomReadings_GetHTML ($) { my ($name) = @_; my $hash = $main::defs{$name}; my $result = ""; $result .= ""; foreach my $reading (keys %{$hash->{READINGS}}) { $result .= ""; $result .= ""; $result .= ""; } $result .= "
$reading: " . ReadingsVal($name, $reading, "???") . "
"; return $result; } 1; =pod =begin html

CustomReadings

=end html =cut