Skip to content

Commit 0239a19

Browse files
committed
custom scope detection and initialisation
1 parent 17da845 commit 0239a19

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

python/shared/helper.py

+28-19
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import time
55
import profile, pstats, io
66
import threading
7+
import sys
78

89
#from java.util import UUID
910
#import datetime
@@ -16,36 +17,44 @@
1617

1718
from java.time import ZonedDateTime, Instant, ZoneId
1819
from java.time.format import DateTimeFormatter
19-
20-
from core.jsr223 import scope
20+
21+
#from core.jsr223 import scope
2122
from core.triggers import ItemStateUpdateTrigger, ItemStateChangeTrigger
2223

24+
from org.slf4j import LoggerFactory
25+
26+
from configuration import LOG_PREFIX, allTelegramBots, allTelegramAdminBots
27+
28+
log = LoggerFactory.getLogger(LOG_PREFIX)
29+
30+
scope = sys._getframe(1).f_globals
31+
32+
actions = scope.get("actions")
33+
34+
itemRegistry = scope.get("itemRegistry")
35+
items = scope.get("items")
36+
things = scope.get("things")
37+
38+
events = scope.get("events")
39+
scriptExtension = scope.get("scriptExtension")
40+
41+
scriptExtension.importPreset("RuleSupport")
42+
automationManager = scope.get("automationManager")
43+
44+
scriptExtension.importPreset("RuleSimple")
45+
SimpleRule = scope.get("SimpleRule")
46+
2347
class Telegram(object):
2448
@staticmethod
2549
def sendTelegram(recipient, message):
26-
bot = scope.actions.get("telegram", "telegram:telegramBot:{}".format(recipient))
50+
bot = actions.get("telegram", "telegram:telegramBot:{}".format(recipient))
2751
bot.sendTelegram(message)
2852

2953
@staticmethod
3054
def sendTelegramPhoto(recipient, url, message):
31-
bot = scope.actions.get("telegram", "telegram:telegramBot:{}".format(recipient))
55+
bot = actions.get("telegram", "telegram:telegramBot:{}".format(recipient))
3256
bot.sendTelegramPhoto(url,message)
3357

34-
from org.slf4j import LoggerFactory
35-
36-
from configuration import LOG_PREFIX, allTelegramBots, allTelegramAdminBots
37-
38-
log = LoggerFactory.getLogger(LOG_PREFIX)
39-
40-
scriptExtension = scope.scriptExtension
41-
itemRegistry = scope.itemRegistry
42-
things = scope.things
43-
items = scope.items
44-
events = scope.events
45-
46-
automationManager = scope.automationManager
47-
SimpleRule = scope.SimpleRule
48-
4958
class rule(object):
5059
def __init__(self, name,profile=None):
5160
self.name = name

0 commit comments

Comments
 (0)