mirror of
https://codeberg.org/icewind/taspromto.git
synced 2026-08-02 12:14:45 +02:00
unify formattign
This commit is contained in:
parent
e13243f9a5
commit
ce9c143250
2 changed files with 35 additions and 26 deletions
|
|
@ -34,6 +34,22 @@ pub struct DeviceStates {
|
|||
|
||||
pub trait FormattableDevice {
|
||||
fn format_open_metrics(&self) -> impl Display + '_;
|
||||
|
||||
fn format_dyn(&self) -> DynFormattable<'_> {
|
||||
DynFormattable {
|
||||
inner: Box::new(self.format_open_metrics()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct DynFormattable<'a> {
|
||||
inner: Box<dyn Display + 'a>,
|
||||
}
|
||||
|
||||
impl FormattableDevice for DynFormattable<'_> {
|
||||
fn format_open_metrics(&self) -> impl Display + '_ {
|
||||
&self.inner
|
||||
}
|
||||
}
|
||||
|
||||
impl DeviceStates {
|
||||
|
|
@ -48,12 +64,25 @@ impl DeviceStates {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn devices(&self) -> impl Iterator<Item = &impl FormattableDevice> {
|
||||
self.devices.values()
|
||||
}
|
||||
|
||||
pub fn dsmr_devices(&self) -> impl Iterator<Item = &impl FormattableDevice> {
|
||||
self.dsmr_devices.values()
|
||||
pub fn devices(&self) -> impl Iterator<Item = impl FormattableDevice> {
|
||||
self.devices
|
||||
.values()
|
||||
.map(FormattableDevice::format_dyn)
|
||||
.chain(
|
||||
self.dsmr_devices
|
||||
.values()
|
||||
.map(FormattableDevice::format_dyn),
|
||||
)
|
||||
.chain(
|
||||
self.mi_temp_devices
|
||||
.values()
|
||||
.map(FormattableDevice::format_dyn),
|
||||
)
|
||||
.chain(
|
||||
self.rf_temp_devices
|
||||
.values()
|
||||
.map(FormattableDevice::format_dyn),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn update(&mut self, device: Device, json: JsonValue) {
|
||||
|
|
@ -151,14 +180,6 @@ impl DeviceStates {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn mi_temp(&self) -> impl Iterator<Item = &impl FormattableDevice> {
|
||||
self.mi_temp_devices.values()
|
||||
}
|
||||
|
||||
pub fn rf_temp(&self) -> impl Iterator<Item = &impl FormattableDevice> {
|
||||
self.rf_temp_devices.values()
|
||||
}
|
||||
|
||||
pub fn retain(&mut self, cleanup_time: Instant, ping_time: Instant, client: &AsyncClient) {
|
||||
self.devices.retain(|device, state| {
|
||||
if state.last_seen < cleanup_time {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue