Skip to content

Commit

Permalink
✨ Add return to idle feature
Browse files Browse the repository at this point in the history
See #27
  • Loading branch information
cp2004 committed May 23, 2021
1 parent 469e546 commit 9538dff
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 5 deletions.
1 change: 1 addition & 0 deletions octoprint_wled/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ def get_settings_defaults(self) -> Dict[str, Any]:
"development": False,
"features": {
"atcommand": True,
"return_to_idle": 0,
},
}

Expand Down
18 changes: 18 additions & 0 deletions octoprint_wled/events.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import copy
import logging
import threading
from typing import Dict, Optional

from octoprint.events import Events
Expand All @@ -25,6 +26,7 @@ def __init__(self, plugin):
}

self.last_event: Optional[str] = None
self._return_to_idle: Optional[threading.Timer] = None

def on_event(self, event, payload) -> None:
# noinspection PyProtectedMember
Expand All @@ -38,9 +40,25 @@ def on_event(self, event, payload) -> None:

elif event in self.event_to_effect.keys():
self.last_event = event
if self._return_to_idle and self._return_to_idle.is_alive():
self._return_to_idle.cancel()

# This is async, no need for threading
self.update_effect(effect=self.event_to_effect[event])

# Start 'return to idle' timer if neccessary
if event == Events.PRINT_DONE:
# noinspection PyProtectedMember
idle_timeout = self.plugin._settings.get_int(["features", "return_to_idle"])
if idle_timeout > 0:
if self._return_to_idle and self._return_to_idle.is_alive():
self._return_to_idle.cancel()

self._return_to_idle = threading.Timer(
idle_timeout, self.update_effect, kwargs={"effect": "idle"}
)
self._return_to_idle.start()

def update_effect(self, effect) -> None:
"""
Updates the effect running on the specified segment in WLED
Expand Down
17 changes: 12 additions & 5 deletions octoprint_wled/static/src/wled.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ $animation-duration: 0.3s;
.gap-right {
margin-right: $gap-spacer;
}
.text-align-center {
text-align: center;
}
.text-align-left {
text-align: left;
@each $direction in (center, left, right){
.text-align-#{$direction}{
text-align: $direction;
}
}

tr.table-heading {
Expand Down Expand Up @@ -127,3 +126,11 @@ d-block {
padding-left: 0.2rem;
}
}

.input-flex-container {
display: flex;
align-items: center;
&> * > input {
margin-left: 0.5rem;
}
}
22 changes: 22 additions & 0 deletions octoprint_wled/templates/wled-settings/features.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,27 @@
</tr>
{% endmacro %}

{% macro return_idle() %}
<tr class="table-heading-2">
<td></td>
<td>
<div class="input-flex-container">
<label for="wled_return_idle" class="fw-bold">
Return to idle after:
</label>
<div class="input-append">
<input id="wled_return_idle" type="text" class="text-align-right input-small" data-bind="value: settingsViewModel.settings.plugins.wled.features.return_to_idle">
<span class="add-on">secs</span>
</div>
</div>
<p class="d-block">
Set to 0 to disable. When enabled, the idle effect will run after the print is finished, after the configured length of time.
</p>
</td>
<td></td>
</tr>
{% endmacro %}

<p>
Enable some optional features for the plugin here.
</p>
Expand All @@ -38,5 +59,6 @@
</thead>
<tbody>
{{ at_command() }}
{{ return_idle() }}
</tbody>
</table>

0 comments on commit 9538dff

Please sign in to comment.