Improve rule enabling reliability

- Add 0.5s delay before enabling rule to let device process rule content
- Use retry logic for rule enable command (3 attempts with 1s delay)
- Change failed enable from warning to error and fail the command
- Ensures rules are both set AND enabled for switches to work
This commit is contained in:
Mike Geppert 2026-01-07 20:36:28 -06:00
parent 70e0b038e6
commit 12ebdbf3e9

View File

@ -207,6 +207,9 @@ class ConsoleSettingsManager:
if param_name.lower().startswith('rule'):
rule_number = param_name.lower().replace('rule', '')
if rule_number.isdigit():
# Wait for device to process the rule before enabling
time.sleep(0.5)
# Use Rule{N} 4 to enable without setting Once flag
# Rule 1 = Enable + Once ON (WRONG - causes single-fire issue)
# Rule 4 = Enable only (CORRECT - allows repeated firing)
@ -214,12 +217,17 @@ class ConsoleSettingsManager:
self.logger.debug(f"{device_name}: Enabling rule{rule_number} (Once=OFF)")
result, success = send_tasmota_command(
device_ip, enable_command, timeout=5, logger=self.logger
result, success = retry_command(
lambda: send_tasmota_command(device_ip, enable_command, timeout=5, logger=self.logger),
max_attempts=3,
delay=1.0,
logger=self.logger,
device_name=device_name
)
if not success:
self.logger.warning(f"{device_name}: Failed to enable rule{rule_number}")
self.logger.error(f"{device_name}: Failed to enable rule{rule_number} after 3 attempts")
return False
time.sleep(0.3) # Brief delay between commands
return True