2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-06 12:46:57 +00:00
fhem-mirror/fhem/FHEM/98_dummy.pm
rudolfkoenig e68bf58f2b 98_dummy.pm: add readingList attribute (Forum #38383)
git-svn-id: https://svn.fhem.de/fhem/trunk@8809 2b470e98-0d58-463d-a4d8-8e2adae1ed80
2015-06-23 18:02:33 +00:00

167 lines
3.4 KiB
Perl

##############################################
# $Id$
package main;
use strict;
use warnings;
sub
dummy_Initialize($)
{
my ($hash) = @_;
$hash->{SetFn} = "dummy_Set";
$hash->{DefFn} = "dummy_Define";
$hash->{AttrList} = "readingList setList ". $readingFnAttributes;
}
###################################
sub
dummy_Set($@)
{
my ($hash, @a) = @_;
my $name = shift @a;
return "no set value specified" if(int(@a) < 1);
my $setList = AttrVal($name, "setList", " ");
return "Unknown argument ?, choose one of $setList" if($a[0] eq "?");
my @rl = split(" ", AttrVal($name, "readingList", ""));
if(@rl && grep /\b$a[0]\b/, @rl) {
my $v = shift @a;
readingsSingleUpdate($hash, $v, join(" ",@a), 1);
return;
}
my $v = join(" ", @a);
Log3 $name, 4, "dummy set $name $v";
readingsSingleUpdate($hash,"state",$v,1);
return undef;
}
sub
dummy_Define($$)
{
my ($hash, $def) = @_;
my @a = split("[ \t][ \t]*", $def);
return "Wrong syntax: use define <name> dummy" if(int(@a) != 2);
return undef;
}
1;
=pod
=begin html
<a name="dummy"></a>
<h3>dummy</h3>
<ul>
Define a dummy. A dummy can take via <a href="#set">set</a> any values.
Used for programming.
<br><br>
<a name="dummydefine"></a>
<b>Define</b>
<ul>
<code>define &lt;name&gt; dummy</code>
<br><br>
Example:
<ul>
<code>define myvar dummy</code><br>
<code>set myvar 7</code><br>
</ul>
</ul>
<br>
<a name="dummyset"></a>
<b>Set</b>
<ul>
<code>set &lt;name&gt; &lt;value&gt</code><br>
Set any value.
</ul>
<br>
<a name="dummyget"></a>
<b>Get</b> <ul>N/A</ul><br>
<a name="dummyattr"></a>
<b>Attributes</b>
<ul>
<li><a name="readingList">readingList</a><br>
Space separated list of readings, which will be set, if the first
argument of the set command matches one of them.</li>
<li><a name="setList">setList</a><br>
Space separated list of commands, which will be returned upon "set name
?", so the FHEMWEB frontend can construct a dropdown and offer on/off
switches. Example: attr dummyName setList on off </li>
<li><a href="#readingFnAttributes">readingFnAttributes</a></li>
</ul>
<br>
</ul>
=end html
=begin html_DE
<a name="dummy"></a>
<h3>dummy</h3>
<ul>
Definiert eine Pseudovariable, der mit <a href="#set">set</a> jeder beliebige
Wert zugewiesen werden kann. Sinnvoll zum Programmieren.
<br><br>
<a name="dummydefine"></a>
<b>Define</b>
<ul>
<code>define &lt;name&gt; dummy</code>
<br><br>
Beispiel:
<ul>
<code>define myvar dummy</code><br>
<code>set myvar 7</code><br>
</ul>
</ul>
<br>
<a name="dummyset"></a>
<b>Set</b>
<ul>
<code>set &lt;name&gt; &lt;value&gt</code><br>
Weist einen Wert zu.
</ul>
<br>
<a name="dummyget"></a>
<b>Get</b> <ul>N/A</ul><br>
<a name="dummyattr"></a>
<b>Attributes</b>
<ul>
<li><a name="readingList">readingList</a><br>
Leerzeichen getrennte Liste mit Readings, die mit "set" gesetzt werden
k&ouml;nnen.</li>
<li><a name="setList">setList</a><br>
Liste mit Werten durch Leerzeichen getrennt. Diese Liste wird mit "set
name ?" ausgegeben. Damit kann das FHEMWEB-Frontend Auswahl-Men&uuml;s
oder Schalter erzeugen.<br> Beispiel: attr dummyName setList on off </li>
<li><a href="#readingFnAttributes">readingFnAttributes</a></li>
</ul>
<br>
</ul>
=end html_DE
=cut