Skip to content

Commit

Permalink
feat: enhance settings saving with BirdNET and range filter notificat…
Browse files Browse the repository at this point in the history
…ions

- Implemented checks to detect changes in BirdNET settings and send notifications for model reloads.
- Added notifications for range filter rebuilds when related settings change.
- Improved error handling and logging during settings updates, ensuring better user feedback and traceability.
- Introduced functions to check for specific changes in BirdNET settings, enhancing configuration management.
  • Loading branch information
tphakala committed Jan 12, 2025
1 parent 46fd654 commit 98d17d5
Showing 1 changed file with 54 additions and 4 deletions.
58 changes: 54 additions & 4 deletions internal/httpcontroller/handlers/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,30 @@ func (h *Handlers) SaveSettings(c echo.Context) error {
return h.NewHandlerError(err, "Error updating settings", http.StatusInternalServerError)
}

// Check if BirdNET settings have changed
if birdnetSettingsChanged(oldSettings, *settings) {
h.SSE.SendNotification(Notification{
Message: "Reloading BirdNET model...",
Type: "info",
})

h.controlChan <- "reload_birdnet"
}

// Check if range filter related settings have changed
if rangeFilterSettingsChanged(oldSettings, *settings) {
//log.Println("Range filter settings changed, sending reload signal")
h.SSE.SendNotification(Notification{
Message: "Rebuilding range filter...",
Type: "info",
})
h.controlChan <- "rebuild_range_filter"
}

// Check the authentication settings and update if needed
h.updateAuthenticationSettings(settings)

// Check if audio equalizer settings have changed
if equalizerSettingsChanged(settings.Realtime.Audio.Equalizer, settings.Realtime.Audio.Equalizer) {
//log.Println("Debug (SaveSettings): Equalizer settings changed, reloading audio filters")
if equalizerSettingsChanged(oldSettings.Realtime.Audio.Equalizer, settings.Realtime.Audio.Equalizer) {
if err := myaudio.UpdateFilterChain(settings); err != nil {
h.SSE.SendNotification(Notification{
Message: fmt.Sprintf("Error updating audio EQ filters: %v", err),
Expand All @@ -88,7 +100,6 @@ func (h *Handlers) SaveSettings(c echo.Context) error {

// Save settings to YAML file
if err := conf.SaveSettings(); err != nil {
// Send error notification if saving settings fails
h.SSE.SendNotification(Notification{
Message: fmt.Sprintf("Error saving settings: %v", err),
Type: "error",
Expand Down Expand Up @@ -574,5 +585,44 @@ func rangeFilterSettingsChanged(oldSettings, currentSettings conf.Settings) bool
return true
}

// Check for changes in BirdNET range filter settings
if !reflect.DeepEqual(oldSettings.BirdNET.RangeFilter, currentSettings.BirdNET.RangeFilter) {
return true
}

// Check for changes in BirdNET latitude and longitude
if oldSettings.BirdNET.Latitude != currentSettings.BirdNET.Latitude || oldSettings.BirdNET.Longitude != currentSettings.BirdNET.Longitude {
return true
}

return false
}

func birdnetSettingsChanged(oldSettings, currentSettings conf.Settings) bool {
// Check for changes in BirdNET locale
if oldSettings.BirdNET.Locale != currentSettings.BirdNET.Locale {
return true
}

// Check for changes in BirdNET threads
if oldSettings.BirdNET.Threads != currentSettings.BirdNET.Threads {
return true
}

// Check for changes in BirdNET model path
if oldSettings.BirdNET.ModelPath != currentSettings.BirdNET.ModelPath {
return true
}

// Check for changes in BirdNET label path
if oldSettings.BirdNET.LabelPath != currentSettings.BirdNET.LabelPath {
return true
}

// Check for changes in BirdNET XNNPACK acceleration
if oldSettings.BirdNET.UseXNNPACK != currentSettings.BirdNET.UseXNNPACK {
return true
}

return false
}

0 comments on commit 98d17d5

Please sign in to comment.