2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 06:39:11 +00:00

fhem.pl: add setuuid (Forum #95902)

git-svn-id: https://svn.fhem.de/fhem/trunk@18310 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2019-01-18 09:27:06 +00:00
parent 811898f39b
commit 4c701e0549
3 changed files with 53 additions and 3 deletions

View File

@ -67,6 +67,7 @@
<a href="#setdefaultattr">setdefaultattr</a> &nbsp; <!-- define a default attribute -->
<a href="#setreading">setreading</a> &nbsp; <!-- set a reading for a FHEM device -->
<a href="#setstate">setstate</a> &nbsp; <!-- set the main state of a FHEM device -->
<a href="#setuuid">setuuid</a> &nbsp; <!-- set the FUUID internal -->
<a href="#shutdown">shutdown</a> &nbsp; <!-- shut down (terminate) FHEM -->
<a href="#sleep">sleep</a> &nbsp; <!-- sleep (delay execution) for a while -->
<a href="#trigger">trigger</a> &nbsp; <!-- generate a FHEM event -->
@ -1297,6 +1298,17 @@ The following local attributes are used by a wider range of devices:
</ul>
<!-- setstate end -->
<a name="setuuid"></a>
<h3>setuuid</h3>
<ul>
<code>setuuid &lt;device&gt; &lt;uuid&gt;</code>
<br><br>
System command, used to set the FUUID internal value.
Not intended to be used by an end user.
</ul>
<!-- setstate end -->
<a name="shutdown"></a>
<h3>shutdown</h3>
<ul>

View File

@ -68,6 +68,7 @@
<a href="#setdefaultattr">setdefaultattr</a> &nbsp; <!-- definiert ein "default" Attribut -->
<a href="#setreading">setreading</a> &nbsp; <!-- setzt ein Reading f&uuml;r ein FHEM Ger&auml;t -->
<a href="#setstate">setstate</a> &nbsp; <!-- setzt den Status eines FHEM Ger&aumles -->
<a href="#setuuid">setuuid</a> &nbsp; <!-- setzt den internen FUUID Wert -->
<a href="#shutdown">shutdown</a> &nbsp; <!-- beendet FHEM -->
<a href="#sleep">sleep</a> &nbsp; <!-- verz&ouml;gerte Ausf&uuml;hrung -->
<a href="#trigger">trigger</a> &nbsp; <!-- generiert ein FHEM Event -->
@ -1380,6 +1381,16 @@ Die folgenden lokalen Attribute werden von mehreren Ger&auml;ten verwendet:
<!-- setstate end -->
<a name="setuuid"></a>
<h3>setuuid</h3>
<ul>
<code>setuuid &lt;device&gt; &lt;uuid&gt;</code>
<br><br>
Systembefehl, um den FUUID internen Wert zu setzen.
Ist nicht vom Benutzer zu verwenden.
</ul>
<!-- setstate end -->
<a name="shutdown"></a>
<h3>shutdown</h3>
<ul>

View File

@ -180,6 +180,7 @@ sub CommandSave($$);
sub CommandSet($$);
sub CommandSetReading($$);
sub CommandSetstate($$);
sub CommandSetuuid($$);
sub CommandShutdown($$;$$);
sub CommandSleep($$);
sub CommandTrigger($$);
@ -438,6 +439,7 @@ my %ra = (
Hlp=>"<devspec> <reading> <value>,set reading for <devspec>" },
"setstate"=> { Fn=>"CommandSetstate",
Hlp=>"<devspec> <state>,set the state shown in the command list" },
"setuuid" => { Fn=>"CommandSetuuid", Hlp=>"" },
"setdefaultattr" => { Fn=>"CommandDefaultAttr",
Hlp=>"<attrname> <attrvalue>,set attr for following definitions" },
"shutdown"=> { Fn=>"CommandShutdown",
@ -1583,9 +1585,21 @@ WriteStatefile()
}
sub
GetDefAndAttr($)
CommandSetuuid($$)
{
my ($d) = @_;
my ($cl, $param) = @_;
return "setuuid cannot be used after FHEM is initialized" if($init_done);
my @a = split(" ", $param);
return "Please define $param first" if(!defined($defs{$a[0]}));
$defs{$a[0]}{FUUID} = $a[1];
return undef;
}
sub
GetDefAndAttr($;$)
{
my ($d, $dumpFUUID) = @_;
my @ret;
if($d ne "global") {
@ -1599,6 +1613,9 @@ GetDefAndAttr($)
}
}
push @ret, "setuuid $d $defs{$d}{FUUID}"
if($dumpFUUID && defined($defs{$d}{FUUID}) && $defs{$d}{FUUID});
foreach my $a (sort {
return -1 if($a eq "userattr"); # userattr must be first
return 1 if($b eq "userattr");
@ -1691,7 +1708,7 @@ CommandSave($$)
next;
}
my @arr = GetDefAndAttr($d);
my @arr = GetDefAndAttr($d, 1);
print $fh join("\n", @arr)."\n" if(@arr);
}
@ -2017,6 +2034,7 @@ CommandDefine($$)
my %hash;
$hash{NAME} = $name;
$hash{FUUID} = genUUID();
$hash{TYPE} = $m;
$hash{STATE} = "???";
$hash{DEF} = $a[2] if(int(@a) > 2);
@ -5830,4 +5848,13 @@ SecurityCheck()
}
}
#
sub genUUID()
{
srand(gettimeofday()) if(!$srandUsed);
$srandUsed = 1;
return sprintf("%08x-f33f-%s-%s-%s", time(), substr(getUniqueId(),-4),
join("",map { unpack "H*", chr(rand(256)) } 1..2),
join("",map { unpack "H*", chr(rand(256)) } 1..8));
}
1;