feat: add ON/OFF action config for Countdown and Away rules in Homebridge plugin
- Countdown: new 'Action when timer fires' dropdown (Turn ON / Turn OFF); scheduler uses rule.countdownAction instead of hardcoded 1/0 - Away Mode: scheduler now reads startAction/endAction from the rule (UI already exposed these fields); _stopAwayLoop respects endAction instead of always forcing OFF at window end Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -398,6 +398,13 @@
|
||||
<label>Countdown Duration (minutes)</label>
|
||||
<input type="number" id="dwm-countdown-mins" min="1" max="1440" placeholder="60" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Action when timer fires</label>
|
||||
<select id="dwm-countdown-action">
|
||||
<option value="1">Turn ON (then auto-OFF after duration)</option>
|
||||
<option value="0">Turn OFF (then auto-ON after duration)</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="dwm-alwayson-info" style="display:none;margin-bottom:12px;padding:10px;background:rgba(48,209,88,.1);border:1px solid rgba(48,209,88,.3);border-radius:6px;font-size:0.82rem;color:#4ade80">
|
||||
|
||||
@@ -195,8 +195,9 @@ function dwmRuleSummary(r) {
|
||||
return `⚡ If ${src} → ${when}, then ${action} (${targets})`;
|
||||
}
|
||||
if (r.type === 'Countdown') {
|
||||
const mins = r.countdownTime ? Math.round(r.countdownTime / 60) : null;
|
||||
return mins ? `⏱ ${mins} min auto-off` : '—';
|
||||
const mins = r.countdownTime ? Math.round(r.countdownTime / 60) : null;
|
||||
const action = r.countdownAction === 0 ? 'OFF → auto-ON' : 'ON → auto-OFF';
|
||||
return mins ? `⏱ ${mins} min · ${action}` : '—';
|
||||
}
|
||||
const days = dayLabel(r.days);
|
||||
const devs = (r.targetDevices ?? []).map((td) => esc(td.name ?? td.host)).join(', ') || 'no targets';
|
||||
@@ -442,6 +443,7 @@ function openDwmEdit(id) {
|
||||
document.getElementById('dwm-end-action').value = String(r.endAction ?? -1);
|
||||
document.getElementById('dwm-countdown-mins').value =
|
||||
r.countdownTime ? String(Math.round(r.countdownTime / 60)) : '';
|
||||
document.getElementById('dwm-countdown-action').value = String(r.countdownAction ?? 1);
|
||||
|
||||
_selectedDwmDays = new Set((r.days ?? []).map(Number));
|
||||
|
||||
@@ -474,8 +476,9 @@ function openDwmEdit(id) {
|
||||
document.getElementById('dwm-end-time').value = '';
|
||||
document.getElementById('dwm-start-action').value = '1';
|
||||
document.getElementById('dwm-end-action').value = '-1';
|
||||
document.getElementById('dwm-countdown-mins').value = '';
|
||||
document.getElementById('dwm-trigger-src').value = '';
|
||||
document.getElementById('dwm-countdown-mins').value = '';
|
||||
document.getElementById('dwm-countdown-action').value = '1';
|
||||
document.getElementById('dwm-trigger-src').value = '';
|
||||
document.getElementById('dwm-trigger-event').value = 'any';
|
||||
document.getElementById('dwm-trigger-action').value = 'on';
|
||||
Array.from(document.getElementById('dwm-target-devices').options).forEach((opt) => { opt.selected = false; });
|
||||
@@ -604,7 +607,8 @@ document.getElementById('dwm-form-save-btn').addEventListener('click', async ()
|
||||
if (type === 'Countdown') {
|
||||
const mins = Number(document.getElementById('dwm-countdown-mins').value);
|
||||
if (!mins || mins < 1) { showModalError('Enter countdown duration in minutes'); return; }
|
||||
rule.countdownTime = mins * 60;
|
||||
rule.countdownTime = mins * 60;
|
||||
rule.countdownAction = Number(document.getElementById('dwm-countdown-action').value);
|
||||
} else {
|
||||
const startType = document.getElementById('dwm-start-type').value;
|
||||
const startOffset = parseInt(document.getElementById('dwm-start-offset').value ?? '0', 10) || 0;
|
||||
|
||||
Reference in New Issue
Block a user