Skip to content

Commit 5b6dc4a

Browse files
committed
make refresh interval update right away
1 parent 639e659 commit 5b6dc4a

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

octoprint_external_temp_reader/ExternalTempReaderPlugin.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,27 @@ def on_after_startup(self):
2121
self._logger.info("ExternalTempReader plugin loaded. Loading configuration...")
2222
self.load_configuration()
2323
self.start_polling_thread()
24+
25+
def on_settings_save(self, data):
26+
"""Handle settings save and apply changes immediately."""
27+
# Get the old interval before saving
28+
old_interval = self.polling_interval
29+
30+
# Save the settings using the parent class method
31+
super().on_settings_save(data)
32+
33+
# Reload configuration with new values
34+
self.load_configuration()
35+
36+
# Check if polling interval changed
37+
if old_interval != self.polling_interval:
38+
self._logger.info(f"Polling interval changed from {old_interval}s to {self.polling_interval}s, restarting polling thread")
39+
# Restart the polling thread with new interval
40+
self.restart_polling_thread()
41+
42+
# Check if URL or UUID changed
43+
if 'tag_uuid' in data or 'base_url' in data:
44+
self._logger.info("API configuration changed, next poll will use new settings")
2445

2546
def on_shutdown(self):
2647
self._logger.info("ExternalTempReader plugin unloaded. Stopping polling thread...")
@@ -114,8 +135,17 @@ def stop_polling_thread(self):
114135
"""Stop the polling thread."""
115136
self.stop_polling = True
116137
if self.polling_thread:
117-
self.polling_thread.join()
138+
self.polling_thread.join(timeout=5) # Wait max 5 seconds
118139
self.polling_thread = None
140+
141+
def restart_polling_thread(self):
142+
"""Restart the polling thread with new settings."""
143+
self._logger.info("Restarting temperature polling thread...")
144+
self.stop_polling_thread()
145+
# Small delay to ensure thread is fully stopped
146+
time.sleep(0.5)
147+
self.start_polling_thread()
148+
self._logger.info("Temperature polling thread restarted with new settings")
119149

120150
def get_settings_defaults(self):
121151
"""Default plugin settings."""

0 commit comments

Comments
 (0)