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()
}