summary history branches tags files
commit:ab1b83dec6af94b660716c8ab1c47923523b192d
author:Trevor Bentley
committer:Trevor Bentley
date:Tue Jan 16 22:40:24 2018 +0100
parents:e3f44d6f2d99ae07ce074b28ae9739ed2773d803
Don't save and load empty alarm configs
diff --git a/src/settings/mod.rs b/src/settings/mod.rs
line changes: +3/-0
index b7a59d2..b5e2da2
--- a/src/settings/mod.rs
+++ b/src/settings/mod.rs
@@ -286,6 +286,9 @@ pub fn save_web_alarm_config(config: BTreeMap<String,String>) -> Result<(), Sett
             _ => {},
         }
     }
+    let entries = entries.iter().filter(|e| {
+        !e.context.is_empty() && !e.device.is_empty()
+    }).collect::<Vec<&AlarmConfig>>();
     for (idx,entry) in entries.iter().enumerate() {
         conf.set_to(Some("alarms"), format!("alarm{}", idx+1), entry.to_string());
     }

diff --git a/src/webapi/mod.rs b/src/webapi/mod.rs
line changes: +3/-0
index 79e2c19..0bd957a
--- a/src/webapi/mod.rs
+++ b/src/webapi/mod.rs
@@ -345,6 +345,9 @@ impl FromStr for AlarmConfig {
         let repeat = fields.next().ok_or("Missing repeat")?;
         let context = fields.next().ok_or("Missing context")?;
         let device = fields.next().ok_or("Missing device")?;
+        if device.is_empty() || context.is_empty() || time.is_empty() {
+            return Err("Invalid alarm.".into());
+        }
         let mut time_fields = time.split(":");
         let hour = time_fields.next().ok_or("Missing hour")?;
         let minute = time_fields.next().ok_or("Missing minute")?;