Skip to content

Commit 658d5df

Browse files
committed
fix uid if no filename is available
1 parent 9aa3105 commit 658d5df

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
__version__ = "1.0.10" # version string is for backward compatibility with openhab 5.0.0
1+
__version__ = "1.0.11" # version string is for backward compatibility with openhab 5.0.0
22

33
from openhab.helper import rule, logger, Registry

src/helper.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
from java.time import ZonedDateTime as Java_ZonedDateTime, Instant as Java_Instant
3333
from java.lang import Object as Java_Object, Iterable as Java_Iterable, Exception as Java_Exception
34+
from java.util import UUID
3435

3536
from scope import RuleSupport, osgi#, RuleSimple
3637
import scope
@@ -117,10 +118,13 @@ def __call__(self, clazz_or_function: Union[Callable, object]):
117118
#register_interop_type(Java_SimpleRule, clazz)
118119
#subclass = type(clazz.__name__, (clazz, BaseSimpleRule,))
119120

120-
hash=hashlib.md5(file_package.encode('utf-8')).hexdigest()
121121
name = "{}.{}".format(NAME_PREFIX, clazz_or_function.__name__) if proxy.name is None else proxy.name
122-
uid = "{} {}".format(name, hash) if proxy.uid is None else proxy.uid
123-
uid = re.sub(r"\W", "-", uid)
122+
if FILENAME:
123+
hash=hashlib.md5(FILENAME.encode('utf-8')).hexdigest()
124+
uid = "{} {}".format(name, hash) if proxy.uid is None else proxy.uid
125+
uid = re.sub(r"\W", "-", uid)
126+
else:
127+
uid = UUID.randomUUID().toString()
124128

125129
# dummy helper to avoid "org.graalvm.polyglot.PolyglotException: java.lang.IllegalStateException: unknown type com.oracle.truffle.host.HostObject"
126130
class BaseSimpleRule(Java_SimpleRule):

0 commit comments

Comments
 (0)