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:
@@ -28,6 +28,7 @@ const path = require('path');
|
||||
const DwmStore = require('../lib/store');
|
||||
const wemoClient = require('../lib/wemo-client');
|
||||
const axios = require('axios');
|
||||
const { sunTimes: calcSunTimes } = require('../lib/sun');
|
||||
|
||||
class DibbyWemoUiServer extends HomebridgePluginUiServer {
|
||||
constructor() {
|
||||
@@ -122,6 +123,13 @@ class DibbyWemoUiServer extends HomebridgePluginUiServer {
|
||||
return this._store.getLocation();
|
||||
});
|
||||
|
||||
this.onRequest('/sun-times', async () => {
|
||||
const loc = this._store.getLocation();
|
||||
if (!loc?.lat || !loc?.lng) return { sunrise: null, sunset: null };
|
||||
try { return calcSunTimes(loc.lat, loc.lng); }
|
||||
catch { return { sunrise: null, sunset: null }; }
|
||||
});
|
||||
|
||||
this.onRequest('/location/set', async (loc) => {
|
||||
this._store.setLocation(loc);
|
||||
return { ok: true };
|
||||
|
||||
Reference in New Issue
Block a user