51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
"""Fake script simulating Domoticz"""
|
|
#pylint: disable=line-too-long
|
|
import os
|
|
import time
|
|
import Domoticz
|
|
|
|
def function_read_properties(filename:str, sep:str='=', comment_char:str='#')->dict:
|
|
"""Convert a .properties file into a dictionary"""
|
|
dictionary = {}
|
|
|
|
with open(filename, "r", encoding="utf-8") as fproperties:
|
|
for line in fproperties:
|
|
lstrip = line.strip()
|
|
if lstrip and not lstrip.startswith(comment_char):
|
|
key_value = lstrip.split(sep)
|
|
key = key_value[0].strip()
|
|
value = sep.join(key_value[1:]).strip().strip('"')
|
|
dictionary[key] = value
|
|
|
|
return dictionary
|
|
|
|
# """Read Parameter file? Format should be:
|
|
# Address=xxx
|
|
# Port=xxx
|
|
# Username=xxx
|
|
# Password=xxx
|
|
# Mode1=xxx
|
|
# Mode2=xxx
|
|
# Mode3=xxx
|
|
# Mode4=xxx
|
|
# Mode5=xxx
|
|
# Mode6=xxx
|
|
# """
|
|
Parameters = function_read_properties(os.path.join(os.path.dirname(__file__), "parameters.properties"))
|
|
|
|
Images = Domoticz.Images
|
|
Devices = Domoticz.Devices
|
|
|
|
with open("./plugin.py", 'rb') as fileobj:
|
|
exec(compile(fileobj.read(), "plugin.py", 'exec'), globals(), globals()) #pylint: disable=exec-used
|
|
|
|
onStart() #pylint: disable=undefined-variable # type: ignore
|
|
|
|
try:
|
|
while True:
|
|
Domoticz.Log("## Plugin Heartbeat ##")
|
|
onHeartbeat() #pylint: disable=undefined-variable # type: ignore
|
|
time.sleep(Domoticz.domo.GetHeartbeat())
|
|
finally:
|
|
onStop() #pylint: disable=undefined-variable # type: ignore
|