fix(smart v0.1.13): SmartTemp.current optionnel — évite échec parse JSON
Certains NVMe (ASUS TUF A16) ont un champ temperature sans current. Le champ requis current: i64 faisait crasher toute la désérialisation. Correction : #[serde(default)] + and_then au lieu de map. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
fdeb4c2088
commit
d715b452c1
@@ -12,7 +12,10 @@ struct SmartJson {
|
||||
struct SmartStatus { passed: bool }
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct SmartTemp { current: i64 }
|
||||
struct SmartTemp {
|
||||
#[serde(default)]
|
||||
current: Option<i64>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct SmartAttrs { table: Vec<SmartAttr> }
|
||||
@@ -44,7 +47,7 @@ pub fn is_available() -> bool {
|
||||
pub fn parse_json(json: &str) -> Result<crate::payload::SmartMetrics, serde_json::Error> {
|
||||
let s: SmartJson = serde_json::from_str(json)?;
|
||||
|
||||
let temperature = s.temperature.as_ref().map(|t| t.current)
|
||||
let temperature = s.temperature.as_ref().and_then(|t| t.current)
|
||||
.or_else(|| s.nvme_smart_health_information_log.as_ref()?.temperature);
|
||||
|
||||
let mut reallocated = None;
|
||||
|
||||
Reference in New Issue
Block a user