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:
parent
811898f39b
commit
4c701e0549
@ -67,6 +67,7 @@
|
||||
<a href="#setdefaultattr">setdefaultattr</a> <!-- define a default attribute -->
|
||||
<a href="#setreading">setreading</a> <!-- set a reading for a FHEM device -->
|
||||
<a href="#setstate">setstate</a> <!-- set the main state of a FHEM device -->
|
||||
<a href="#setuuid">setuuid</a> <!-- set the FUUID internal -->
|
||||
<a href="#shutdown">shutdown</a> <!-- shut down (terminate) FHEM -->
|
||||
<a href="#sleep">sleep</a> <!-- sleep (delay execution) for a while -->
|
||||
<a href="#trigger">trigger</a> <!-- 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 <device> <uuid></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>
|
||||
|
@ -68,6 +68,7 @@
|
||||
<a href="#setdefaultattr">setdefaultattr</a> <!-- definiert ein "default" Attribut -->
|
||||
<a href="#setreading">setreading</a> <!-- setzt ein Reading für ein FHEM Gerät -->
|
||||
<a href="#setstate">setstate</a> <!-- setzt den Status eines FHEM Geräes -->
|
||||
<a href="#setuuid">setuuid</a> <!-- setzt den internen FUUID Wert -->
|
||||
<a href="#shutdown">shutdown</a> <!-- beendet FHEM -->
|
||||
<a href="#sleep">sleep</a> <!-- verzögerte Ausführung -->
|
||||
<a href="#trigger">trigger</a> <!-- generiert ein FHEM Event -->
|
||||
@ -1380,6 +1381,16 @@ Die folgenden lokalen Attribute werden von mehreren Geräten verwendet:
|
||||
<!-- setstate end -->
|
||||
|
||||
|
||||
<a name="setuuid"></a>
|
||||
<h3>setuuid</h3>
|
||||
<ul>
|
||||
<code>setuuid <device> <uuid></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>
|
||||
|
33
fhem/fhem.pl
33
fhem/fhem.pl
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user