Conversation
…de is changed to sunset or the coords change
Should fix: #42627 Issue: Suntimes not updating within the day if the mode changes to SunsetToSunrise Fix: Update suntimes in the service if the mode is changed to Sun mode. Other: small bug fixes (brackets, etc)
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the LightSwitch service to immediately recalculate sun times when the schedule mode changes to SunsetToSunrise or when coordinates change, improving responsiveness to user configuration updates.
- Fixed a logging typo where dark mode was incorrectly logged as "light mode"
- Added tracking variables for previous schedule mode and coordinates to detect changes
- Implemented immediate sun time recalculation when mode or coordinates change
- Added braces to conditional blocks for consistency
| prevMode = settings.scheduleMode; | ||
| prevLat = settings.latitude; | ||
| prevLon = settings.longitude; | ||
| } |
There was a problem hiding this comment.
The tracking variables (prevMode, prevLat, prevLon) are never updated when the mode is Off or when changing to FixedHours mode. If a user changes mode from SunsetToSunrise → Off → SunsetToSunrise with the same coordinates, the code will incorrectly detect this as 'modeChangedToSunset' and recalculate unnecessarily. Similarly, coordinate changes won't be tracked when not in SunsetToSunrise mode. Update prevMode unconditionally after the condition check, and consider tracking coordinates regardless of mode.
| prevMode = settings.scheduleMode; | |
| prevLat = settings.latitude; | |
| prevLon = settings.longitude; | |
| } | |
| } | |
| // Always update tracking variables after checking for changes | |
| prevMode = settings.scheduleMode; | |
| prevLat = settings.latitude; | |
| prevLon = settings.longitude; |
Should fix: microsoft#42627 Issue: Suntimes not updating within the day if the mode changes to SunsetToSunrise Fix: Update suntimes in the service if the mode is changed to Sun mode. Other: small bug fixes (brackets, etc)
Should fix: #42627
Issue: Suntimes not updating within the day if the mode changes to SunsetToSunrise
Fix: Update suntimes in the service if the mode is changed to Sun mode.
Other: small bug fixes (brackets, etc)