Implement alarm sound

This commit is contained in:
nemunaire 2022-10-14 20:08:03 +02:00
commit df31c4dcd1
15 changed files with 531 additions and 50 deletions

View file

@ -250,6 +250,25 @@ func DeleteAlarmSingle(db *LevelDBStorage, alarm *AlarmSingle) (err error) {
return db.delete(fmt.Sprintf("alarm-single-%s", alarm.Id.ToString()))
}
func RemoveOldAlarmsSingle(db *LevelDBStorage) error {
alarms, err := GetAlarmsSingle(db)
if err != nil {
return err
}
now := time.Now()
for _, alarm := range alarms {
if now.After(time.Time(alarm.Time)) {
err = DeleteAlarmSingle(db, alarm)
if err != nil {
return err
}
}
}
return nil
}
type AlarmException struct {
Id Identifier `json:"id"`
Start *Date `json:"start"`

View file

@ -19,13 +19,13 @@ type Gong struct {
Enabled bool `json:"enabled"`
}
func currentGongPath(cfg *config.Config) string {
func CurrentGongPath(cfg *config.Config) string {
return filepath.Join(cfg.GongsDir, CURRENT_GONG)
}
func LoadGongs(cfg *config.Config) (gongs []*Gong, err error) {
// Retrieve the path of the current gong
current_gong, err := os.Readlink(currentGongPath(cfg))
current_gong, err := os.Readlink(CurrentGongPath(cfg))
if err == nil {
current_gong, _ = filepath.Abs(filepath.Join(cfg.GongsDir, current_gong))
}
@ -65,7 +65,7 @@ func (g *Gong) Rename(newName string) error {
}
func (g *Gong) SetDefault(cfg *config.Config) error {
linkpath := currentGongPath(cfg)
linkpath := CurrentGongPath(cfg)
os.Remove(linkpath)
pabs, err := filepath.Abs(g.Path)

View file

@ -12,6 +12,7 @@ type Settings struct {
GongInterval time.Duration `json:"gong_interval"`
WeatherDelay time.Duration `json:"weather_delay"`
WeatherAction string `json:"weather_action"`
MaxRunTime time.Duration `json:"max_run_time"`
}
// ExistsSettings checks if the settings file can by found at the given path.