feat: add sunrise/sunset support to Homebridge plugin

Scheduler:
- Import sun.js calculator (already existed, never wired in)
- resolveSecs() maps -2=sunrise/-3=sunset sentinels + offset to actual seconds
- getTodaySun() reads stored location from store
- _loadSchedule(), _resumeAwayLoops(), _startAwayLoop() all resolve sun times

Server:
- Add /sun-times endpoint returning today's sunrise/sunset in seconds

UI:
- Start Time and End Time fields now show Fixed/Sunrise/Sunset dropdown
- Offset field (minutes before/after) shown when sun type selected
- Live preview shows today's base time + fires-at time with offset
- Save handler writes -2/-3 sentinels + startType/endType/startOffset/endOffset
- openDwmEdit() restores sun type and offset when editing existing rules

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
SRS IT
2026-03-28 20:20:32 -04:00
parent b200c45385
commit 951d4c4eaa
4 changed files with 170 additions and 30 deletions
@@ -316,11 +316,39 @@
<div class="flex-row">
<div class="form-group" style="flex:1">
<label>Start Time</label>
<input type="text" id="dwm-start-time" placeholder="e.g. 8:30 PM" />
<select id="dwm-start-type" style="margin-bottom:6px">
<option value="fixed">Fixed Time</option>
<option value="sunrise">Sunrise</option>
<option value="sunset">Sunset</option>
</select>
<div id="dwm-start-fixed">
<input type="text" id="dwm-start-time" placeholder="e.g. 8:30 PM" />
</div>
<div id="dwm-start-sun" style="display:none">
<div style="display:flex;align-items:center;gap:6px">
<input type="number" id="dwm-start-offset" placeholder="0" style="width:70px" />
<span style="font-size:0.8rem;color:#9ca3af">min (+ after, before)</span>
</div>
<div id="dwm-start-preview" style="font-size:0.78rem;color:#4ade80;margin-top:4px"></div>
</div>
</div>
<div class="form-group" style="flex:1">
<label>End Time (optional)</label>
<input type="text" id="dwm-end-time" placeholder="e.g. 11:00 PM" />
<select id="dwm-end-type" style="margin-bottom:6px">
<option value="fixed">Fixed Time</option>
<option value="sunrise">Sunrise</option>
<option value="sunset">Sunset</option>
</select>
<div id="dwm-end-fixed">
<input type="text" id="dwm-end-time" placeholder="e.g. 11:00 PM" />
</div>
<div id="dwm-end-sun" style="display:none">
<div style="display:flex;align-items:center;gap:6px">
<input type="number" id="dwm-end-offset" placeholder="0" style="width:70px" />
<span style="font-size:0.8rem;color:#9ca3af">min (+ after, before)</span>
</div>
<div id="dwm-end-preview" style="font-size:0.78rem;color:#4ade80;margin-top:4px"></div>
</div>
</div>
</div>
<div class="flex-row">