dry-ed the to_json so only one json conversion

This commit is contained in:
Nickiel12 2021-12-20 14:14:04 -08:00
parent cff1067ccf
commit d64a3622b5

View file

@ -71,69 +71,34 @@ impl StateUpdate {
} }
pub fn to_json(&self) -> serde_json::Value { pub fn to_json(&self) -> serde_json::Value {
match self { let (update_type, data) = match self {
StateUpdate::StreamRunning(is_true) => { StateUpdate::StreamRunning(is_true) => {
serde_json::json!({ ("Stream_Running", is_true.to_string())},
"type": "button",
"button": "Stream_Running",
"data": is_true
})},
StateUpdate::StreamIsMuted(is_true) => { StateUpdate::StreamIsMuted(is_true) => {
serde_json::json!({ ("Stream_Is_Muted", is_true.to_string())},
"type": "button",
"button": "Stream_Is_Muted",
"data": is_true
})},
StateUpdate::ComputerSoundIsOn(is_true) => { StateUpdate::ComputerSoundIsOn(is_true) => {
serde_json::json!({ ("Computer_Sound_Is_On", is_true.to_string())},
"type": "button",
"button": "Computer_Sound_Is_On",
"data": is_true,
})},
StateUpdate::ChangeSceneOnChangeSlide(is_true) => { StateUpdate::ChangeSceneOnChangeSlide(is_true) => {
serde_json::json!({ ("Change_With_Clicker", is_true.to_string())},
"type": "button",
"button": "Change_With_Clicker",
"data": is_true,
})},
StateUpdate::SceneIsAugmented(is_true) => { StateUpdate::SceneIsAugmented(is_true) => {
serde_json::json!({ ("Scene_Is_Augmented", is_true.to_string())},
"type": "button",
"type": "Scene_Is_Augmented",
"data": is_true,
})},
StateUpdate::TimerCanRun(is_true) => { StateUpdate::TimerCanRun(is_true) => {
serde_json::json!({ ("Timer_Can_Run", is_true.to_string())},
"type": "button",
"button": "Timer_Can_Run",
"data": is_true,
})},
StateUpdate::TimerLength(length) => { StateUpdate::TimerLength(length) => {
serde_json::json!({ ("Timer_Length", length.to_string())},
"type": "button",
"button": "Timer_Length",
"data": length,
})},
StateUpdate::TimerText(text) => { StateUpdate::TimerText(text) => {
serde_json::json!({ ("Timer_Text", text.clone())},
"type": "button",
"button": "Timer_Text",
"data": text,
})},
StateUpdate::SubScene(scene) => { StateUpdate::SubScene(scene) => {
serde_json::json!({ ("SubScene", scene.to_string())},
"type": "button",
"button": "SubScene",
"SubScene": scene.to_string(),
})},
StateUpdate::Scene(scene) => { StateUpdate::Scene(scene) => {
serde_json::json!({ ("Scene", scene.to_string())},
"type": "button",
"button": "Scene",
"Scene": scene.to_string(),
})},
StateUpdate::ComputerMediaDoPause(is_true) => todo!(), StateUpdate::ComputerMediaDoPause(is_true) => todo!(),
StateUpdate::UpdateClient => todo!(), StateUpdate::UpdateClient => todo!(),
} };
serde_json::json!({
"type": "button",
"button": update_type,
"data": data,
})
} }
} }