Skip to content

Commit

Permalink
Add unit test for scene serialization and improve device name handlin…
Browse files Browse the repository at this point in the history
…g in settings
  • Loading branch information
samclane committed Jan 12, 2025
1 parent 8aa73be commit 8bee33e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/scenes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,24 @@ mod test {
);
assert_eq!(scene.device_color_pairs[0].1, HSBK32::default());
}

#[test]
fn test_serde_scene() {
let source = 1234;
let target = 5678;
let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 56700);
let mut bulb = BulbInfo::new(source, target, addr);
bulb.update(addr);
let scene = Scene::new(
vec![(DeviceInfo::Bulb(Box::new(bulb.clone())), HSBK32::default())],
"Test Scene".to_string(),
);
let serialized = serde_json::to_string(&scene).unwrap();
let deserialized: Scene = serde_json::from_str(&serialized).unwrap();
assert_eq!(scene.name, deserialized.name);
assert_eq!(
scene.device_color_pairs.len(),
deserialized.device_color_pairs.len()
);
}
}
10 changes: 9 additions & 1 deletion src/settings.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::ffi::CString;

use eframe::egui::{self, Context};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -312,7 +314,13 @@ impl MantleApp {
if ui
.checkbox(
&mut selected,
device.name.data.as_ref().unwrap().to_str().unwrap(),
device
.name
.data
.as_ref()
.unwrap_or(&CString::default())
.to_str()
.unwrap_or("Unknown Device"),
)
.on_hover_text("Select device for the scene")
.changed()
Expand Down

0 comments on commit 8bee33e

Please sign in to comment.