Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Battery Magic Variable on Linux Triggering Warning Conistently - Update to accomadate Plugged option for AC dir #1235

Open
3 tasks done
andar1an opened this issue Nov 26, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@andar1an
Copy link

andar1an commented Nov 26, 2024

Checklist before submitting an issue

  • I have searched through the existing closed and open issues for eww and made sure this is not a duplicate
  • I have specifically verified that this bug is not a common user error
  • I am providing as much relevant information as I am able to in this bug report (Minimal config to reproduce the issue for example, if applicable)

Description of the bug

 2024-11-26T12:55:33.867Z WARN  eww::config::system_stats > Failed to get/calculate uWh: the total_avg value of the battery magic var will probably be a garbage value that can not be trusted.

The warning appears to be common in many issues, though the issues I am noting these warning in are for different reasons.

/sys/class/power_supply contains:

AC  BAT0  hidpp_battery_4

/sys/class/power_supply/BAT0 contains the necessary files to read:

alarm                           device              serial_number
capacity                        energy_full         status
capacity_level                  energy_full_design  subsystem
charge_behaviour                energy_now          technology
charge_control_end_threshold    manufacturer        type
charge_control_start_threshold  model_name          uevent
charge_start_threshold          power               voltage_min_design
charge_stop_threshold           power_now           voltage_now
cycle_count                     present                   present

/sys/class/power_supply/hidpp_battery_4 contains the necessary files to trigger first if:

capacity  manufacturer  online  powers  serial_number  subsystem  uevent device model_name    power   scope   status type wakeup53

/sys/class/power_supply/AC does not seem to match a scenario for the loop:

device  online  power  subsystem  type  uevent  wakeup46

Is it expected behavior that AC should be returning a warning, or should it be returning "plugged" or some indicator aligned to being plugged in?

https://github.com/elkowar/eww/blob/master/crates/eww/src/config/system_stats.rs#L186

Reproducing the issue

I am on Alpine linux, but I have noted this in Eww issues search using Arch and other distros.

Launch eww on a linux distro and check logs.

Expected behaviour

Battery Magic Variable returns a value for AC indicating plugged or unplugged.

I believe that this is dependent on if /sys/class/power_supply/AC/online = 1 or 0, would likely be an easy add.

I believe status indicating charging or not charging also needs to accommodate knowing whether AC is online or not, because in that way you could leverage the magic variable to align with indicating on widget a different icon while plugged very easily.

A solution may be along lines of:
(this is not working code - just pseudo)

    struct Data {
        #[serde(flatten)]
        batteries: HashMap<String, BatteryData>,
        total_avg: f64,
        plugged: bool,
    }
    let mut plugged = bool;
    for ... {
    // add an additional condition before warning
    else if let (Ok(online)) =
                (read_to_string(entry.join("online")))
            {
                if online.trim_end_matches('\n').parse::<bool>().unwrap() {
                plugged = true;
                } else {
                plugged = false;
                }
            } 
            ...
            }}

Additional context

No response

Platform and environment

Wayland, Alpine Edge, Hyprland 0.45, eww 0.4.0

@andar1an andar1an added the bug Something isn't working label Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant