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

Power & Battery show that any connected devices are currently charging #561

Closed
ahoneybun opened this issue Sep 5, 2024 · 3 comments · Fixed by #710
Closed

Power & Battery show that any connected devices are currently charging #561

ahoneybun opened this issue Sep 5, 2024 · 3 comments · Fixed by #710
Milestone

Comments

@ahoneybun
Copy link

Neither my mouse or headphones are currently charging.

screenshot-2024-09-05-16-03-54

@WatchMkr WatchMkr moved this to Alpha 2 Settings in COSMIC Epoch 1 Sep 5, 2024
@WatchMkr WatchMkr added this to the alpha 2 milestone Sep 5, 2024
@WatchMkr WatchMkr modified the milestones: alpha 2, alpha 3 Sep 16, 2024
@l-const
Copy link
Contributor

l-const commented Oct 19, 2024

I might try to debug this if it is not a priority to be picked up from someone else.

@l-const
Copy link
Contributor

l-const commented Oct 19, 2024

❯ dbus-send --print-reply             --system             --dest=org.freedesktop.UPower             /org/freedesktop/UPower             org.freedesktop.UPower.EnumerateDevices
method return time=1729365543.607111 sender=:1.13 -> destination=:1.2647 serial=911 reply_serial=2
   array [
      object path "/org/freedesktop/UPower/devices/battery_hidpp_battery_0"
   ]

Mmm, for my wireless keyboard I am getting this output from UPower:

dbus-send --print-reply \                                                                                                                                             --system \
            --dest=org.freedesktop.UPower \
            /org/freedesktop/UPower/devices/battery_hidpp_battery_0 \
            org.freedesktop.DBus.Properties.GetAll \
            string:org.freedesktop.UPower.Device
method return time=1729356917.502920 sender=:1.13 -> destination=:1.2031 serial=615 reply_serial=2
   array [
      dict entry(
         string "NativePath"
         variant             string "hidpp_battery_0"
      )
      dict entry(
         string "Vendor"
         variant             string ""
      )
      dict entry(
         string "Model"
         variant             string "Wireless Keyboard"
      )
      dict entry(
         string "Serial"
         variant             string "00-00-00-00"
      )
      dict entry(
         string "UpdateTime"
         variant             uint64 1729356895
      )
      dict entry(
         string "Type"
         variant             uint32 6
      )
      dict entry(
         string "PowerSupply"
         variant             boolean false
      )
      dict entry(
         string "HasHistory"
         variant             boolean true
      )
      dict entry(
         string "HasStatistics"
         variant             boolean true
      )
      dict entry(
         string "Online"
         variant             boolean false
      )
      dict entry(
         string "Energy"
         variant             double 0
      )
      dict entry(
         string "EnergyEmpty"
         variant             double 0
      )
      dict entry(
         string "EnergyFull"
         variant             double 0
      )
      dict entry(
         string "EnergyFullDesign"
         variant             double 0
      )
      dict entry(
         string "EnergyRate"
         variant             double 0
      )
      dict entry(
         string "Voltage"
         variant             double 0
      )
      dict entry(
         string "ChargeCycles"
         variant             int32 -1
      )
      dict entry(
         string "Luminosity"
         variant             double 0
      )
      dict entry(
         string "TimeToEmpty"
         variant             int64 0
      )
      dict entry(
         string "TimeToFull"
         variant             int64 0
      )
      dict entry(
         string "Percentage"
         variant             double 55
      )
      dict entry(
         string "Temperature"
         variant             double 0
      )
      dict entry(
         string "IsPresent"
         variant             boolean true
      )
      dict entry(
         string "State"
         variant             uint32 2
      )
      dict entry(
         string "IsRechargeable"
         variant             boolean true
      )
      dict entry(
         string "Capacity"
         variant             double 0
      )
      dict entry(
         string "Technology"
         variant             uint32 0
      )
      dict entry(
         string "WarningLevel"
         variant             uint32 1
      )
      dict entry(
         string "BatteryLevel"
         variant             uint32 6
      )
      dict entry(
         string "IconName"
         variant             string "battery-low-symbolic"
      )
      dict entry(
         string "ChargeStartThreshold"
         variant             uint32 0
      )
      dict entry(
         string "ChargeEndThreshold"
         variant             uint32 100
      )
      dict entry(
         string "ChargeThresholdEnabled"
         variant             boolean false
      )
      dict entry(
         string "ChargeThresholdSupported"
         variant             boolean false
      )
   ]

I am guessing the spec is this one: https://upower.freedesktop.org/docs/Device.html . I am not sure which property can indicate if it charging or not except from 'state' . I think we wrongfully using the wrong zbus interface i think we use this one https://upower.freedesktop.org/docs/UPower.html and in particular the on_battery property which should only used for the PC like it is used in the cosmic-battery-applet, could be wrong though as this is only new to me. The related code on what symcol/icon to show is here:

let charging = if on_battery { "" } else { "charging-" };
let icon_name =
format!("cosmic-applet-battery-level-{battery_percent}-{charging}symbolic",);
Self {
icon_name,
is_present,
percent,
on_battery,

@l-const
Copy link
Contributor

l-const commented Oct 19, 2024

Ok, so I was right about the implementation according to lxqt management issue here: lxqt/lxqt-powermanagement#295 (comment), that uses KDE's solid library abstraction :https://github.com/KDE/solid/blob/master/src/solid/devices/frontend/battery.h#L201-L208

   /**
     * Retrieves the current charge state of the battery. It can be in a stable
     * state (no charge), charging or discharging.
     *
     * @return the current battery charge state
     * @see Solid::Battery::ChargeState
     */
    Solid::Battery::ChargeState chargeState() const;

The problem is that are 6 states and not only chargin/not charging, i guess to be safe for the users we could map only 2 out of 6 (pending_charging, charging) to those icons and the other ones even the unknow state to the icon that doesn't show any charging. Any thoughts on this, @mmstick or am I completely wrong ?

The states are the following:

The battery power state.

0: Unknown
1: Charging
2: Discharging
3: Empty
4: Fully charged
5: Pending charge
6: Pending discharge

or from this repo here : https://github.com/pop-os/upower-dbus/blob/main/src/device.rs#L10

Edit: I found this related MR: https://gitlab.freedesktop.org/upower/upower/-/merge_requests/20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Complete
Development

Successfully merging a pull request may close this issue.

3 participants