1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use std::fmt;
use heim_common::prelude::*;
use heim_common::units::ThermodynamicTemperature;
use crate::sys;
pub struct TemperatureSensor {
pub(crate) unit: String,
pub(crate) label: Option<String>,
pub(crate) current: ThermodynamicTemperature,
pub(crate) high: Option<ThermodynamicTemperature>,
pub(crate) critical: Option<ThermodynamicTemperature>,
}
impl TemperatureSensor {
pub fn unit(&self) -> &str {
&self.unit
}
#[allow(clippy::option_as_ref_deref)]
pub fn label(&self) -> Option<&str> {
self.label.as_ref().map(|s| s.as_str())
}
pub fn current(&self) -> ThermodynamicTemperature {
self.current
}
pub fn high(&self) -> Option<ThermodynamicTemperature> {
self.high
}
pub fn critical(&self) -> Option<ThermodynamicTemperature> {
self.critical
}
}
impl fmt::Debug for TemperatureSensor {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("TemperatureSensor")
.field("unit", &self.unit())
.field("label", &self.label())
.field("current", &self.current())
.field("high", &self.high())
.field("critical", &self.critical())
.finish()
}
}
pub fn temperatures() -> impl Stream<Item = Result<TemperatureSensor>> {
sys::temperatures()
}