#client #service #lhm-client #lhm

lhm-client

Client for using the LHM service

3 releases (breaking)

Uses new Rust 2024

new 0.2.0 May 16, 2025
0.1.0 May 15, 2025
0.0.0 May 12, 2025

#336 in #service

Download history 126/week @ 2025-05-07

126 downloads per month

MIT license

24KB
507 lines

LHM Client

Client that can consume the LHM Service from user-land

use lhm_client::{ComputerOptions, Hardware, HardwareType, LHMClient, SensorType};

let mut client = LHMClient::connect().await.unwrap();

client
    .set_options(ComputerOptions {
        controller_enabled: true,
        cpu_enabled: true,
        gpu_enabled: true,
        motherboard_enabled: true,
        ..Default::default()
    })
    .await
    .unwrap();

client.update().await.unwrap();

let hardware = client.get_hardware().await.unwrap();

let cpus: Vec<&Hardware> = hardware
    .iter()
    .filter(|value| matches!(value.ty, HardwareType::Cpu))
    .collect();

let cpu_temps = cpus
    .iter()
    .flat_map(|value| {
        value
            .sensors
            .iter()
            .filter(|value| matches!(value.ty, SensorType::Temperature))
    })
    .collect::<Vec<_>>();

let temp = cpu_temps
    .iter()
    .find(|sensor| sensor.name.eq("CPU Package"));

let temp = temp.map(|value| value.value).expect("Unknown CPU Temp");

println!("CPU is {temp}°C");

Dependencies

~5–14MB
~160K SLoC