From 2cb4357ad1704d330cef27ad629066ba750bddeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacek=20Zi=C3=B3=C5=82kowski?= Date: Fri, 27 Sep 2024 02:39:10 +0200 Subject: [PATCH] Misc rule fixes (#291) --- tdmgr/GUI/rules.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/tdmgr/GUI/rules.py b/tdmgr/GUI/rules.py index 760633e..0319724 100644 --- a/tdmgr/GUI/rules.py +++ b/tdmgr/GUI/rules.py @@ -135,7 +135,7 @@ def __init__(self, device: TasmotaDevice, *args, **kwargs): # RuleTimers self.lwRTs = QListWidget() self.lwRTs.setAlternatingRowColors(True) - self.lwRTs.addItems([f"RuleTimer{1}: " for i in range(1, 9)]) + self.lwRTs.addItems([f"RuleTimer{i}: " for i in range(1, 9)]) self.lwRTs.clicked.connect(self.select_rt) self.lwRTs.doubleClicked.connect(self.set_rt) @@ -262,12 +262,9 @@ def display_rule(self, payload, rule): self.actStopOnError.setChecked(payload["StopOnError"] == "ON") def unfold_rule(self, rules: str): - return ( - rules.replace(" on ", "\non ") - .replace(" do ", " do\n\t") - .replace(" endon", "\nendon ") - .rstrip(" ") - ) + for pat, repl in [(r' on ', '\non '), (r' do ', ' do\n\t'), (r' endon', '\nendon ')]: + rules = re.sub(pat, repl, rules, flags=re.IGNORECASE) + return rules.rstrip(" ") @pyqtSlot(Message) def parseMessage(self, msg: Message):