oh-my-posh: Battery info not displaying when unplugged

Prerequisites

  • I have read and understand the CONTRIBUTING guide
  • I looked for duplicate issues before submitting this one

Description

When I unplug my laptop, the battery segment indicates an error state. When I run this powershell command locally I get a valid reponse:

(Get-WmiObject win32_battery).estimatedChargeRemaining

Environment

  • Oh my Posh version: 3
  • Theme: Custom
  • Operating System: Windows 10
  • Shell: Powershell
  • Terminal: Windows Terminal

Steps to Reproduce

  1. Unplug laptop from powersource
  2. Have battery the following battery segment in your theme
{
          "type": "battery",
          "style": "plain",
          "foreground": "#193549",
          "background": "#2f2f2f",
          "properties": {
              "battery_icon": "",
              "discharging_icon": "\uE231 ",
              "charging_icon": "\uE234 ",
              "charged_icon": "\uE22F ",
              "color_background": true,
              "charged_color": "#4caf50",
              "charging_color": "#40c4ff",
              "discharging_color": "#ff5722",
              "prefix": "<#4caf50,transparent>\uE0B6</> ",
              "postfix": "\u003c#193549\u003e%\u003c/\u003e\u003c#FFFFFF\u003e \u003c/\u003e",
              "display_charging": true,
              "display_error": true
            }
        },

  1. Execute command in shell

Expected behavior: [What you expected to happen] I expect to see battery level information displayed. I expect to see that the battery is not currently charging.

Actual behavior: [What actually happened] Error [{ChargeRate:Unknown value received}]%

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 29 (27 by maintainers)

Most upvoted comments

@Khaos66 if we can distinguish that from other errors, yes please let’s add that.

I attempted to run the executable several ways but I always get the same block:

image

@justin-vogt please run the following, it will help us troubleshoot the actual error battery.exe.zip

@lnu I already made that change to the repo 😃 And that fix is currently in main. I’l try to build a small utility this evening.

Yep missed the fork. Since it’s a fork, you could also merge the fix for the ‘Not charging’ status I’m having now and then since a few days: https://github.com/distatus/battery/pull/16

@lnu I can create an executable that prints the output so we can see if we make a minor change to the code and deploy as such. It’s already using a fork anyways for another issue that simply doesn’t get merged but is fixed on our end.