From 4c701e0549c987713f31c16c1312b2291a95abec Mon Sep 17 00:00:00 2001
From: rudolfkoenig <>
Date: Fri, 18 Jan 2019 09:27:06 +0000
Subject: [PATCH] fhem.pl: add setuuid (Forum #95902)
git-svn-id: https://svn.fhem.de/fhem/trunk@18310 2b470e98-0d58-463d-a4d8-8e2adae1ed80
---
fhem/docs/commandref_frame.html | 12 +++++++++++
fhem/docs/commandref_frame_DE.html | 11 ++++++++++
fhem/fhem.pl | 33 +++++++++++++++++++++++++++---
3 files changed, 53 insertions(+), 3 deletions(-)
diff --git a/fhem/docs/commandref_frame.html b/fhem/docs/commandref_frame.html
index cc4e15c97..22e8f0e69 100644
--- a/fhem/docs/commandref_frame.html
+++ b/fhem/docs/commandref_frame.html
@@ -67,6 +67,7 @@
setdefaultattr
setreading
setstate
+ setuuid
shutdown
sleep
trigger
@@ -1297,6 +1298,17 @@ The following local attributes are used by a wider range of devices:
+
+
setuuid
+
+ setuuid <device> <uuid>
+
+ System command, used to set the FUUID internal value.
+ Not intended to be used by an end user.
+
+
+
+
shutdown
diff --git a/fhem/docs/commandref_frame_DE.html b/fhem/docs/commandref_frame_DE.html
index 42740e5cd..1f1137a53 100644
--- a/fhem/docs/commandref_frame_DE.html
+++ b/fhem/docs/commandref_frame_DE.html
@@ -68,6 +68,7 @@
setdefaultattr
setreading
setstate
+ setuuid
shutdown
sleep
trigger
@@ -1380,6 +1381,16 @@ Die folgenden lokalen Attribute werden von mehreren Geräten verwendet:
+
+setuuid
+
+ setuuid <device> <uuid>
+
+ Systembefehl, um den FUUID internen Wert zu setzen.
+ Ist nicht vom Benutzer zu verwenden.
+
+
+
shutdown
diff --git a/fhem/fhem.pl b/fhem/fhem.pl
index 353965ec4..cd1e1795b 100755
--- a/fhem/fhem.pl
+++ b/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=>" ,set reading for " },
"setstate"=> { Fn=>"CommandSetstate",
Hlp=>" ,set the state shown in the command list" },
+ "setuuid" => { Fn=>"CommandSetuuid", Hlp=>"" },
"setdefaultattr" => { Fn=>"CommandDefaultAttr",
Hlp=>" ,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;