Acknowledged
CIQQA-3115

bug: System.getSystemStats().battery is Number instead of Float

According to the docs: Toybox.System.Stats.battery as Float, but on real fr965 it is a Number or at least it's value is always a Number (without decimal).

function initialize() {
    session = ActivityRecording.createSession({
	 	:name => "test",
	 	:sport => Activity.Sport.SPORT_RUNNING,
	 	:subSport => Activity.SubSport.SUB_SPORT_TREADMILL
	});
    batteryPercentageField = session.createField("battery", 11, FitContributor.DATA_TYPE_FLOAT, { :mesgType => FitContributor.MESG_TYPE_RECORD, :units => "%" });
}

function compute() as Void {
    batteryPercentageField.setData(System.getSystemStats().battery);
}

  • Yes, I messed up with this sentence. What I actually meant was that the value I see is always a whole number. I haven't checked the type. Fortunately my code already is written in a way that it doesn't care if it's type is Number or Float.

  • I created a simple data field with the following compute function:

    function compute(info as Activity.Info) as Numeric or Duration or String or Null {
        var battery = System.getSystemStats().battery;
        return "" + (battery instanceof Float) + " " + battery.toString();
    }

    The output in the sim (fr955) is:

    true 50.000000

    The output on a real fr955 (with latest beta firmware) is:

    true 94.000000

    So it looks to me like:

    - both the sim and the real device return a literal Float (the sim allows you to set the fractional part to non-zero, in Settings > Battery Status)

    - even though the device returns a Float, the fractional part is *probably* always zero. (If I ever observe a battery level with a non-zero fractional part, I'll post back)

  • Btw, if the API is returning SystemStats.battery as a literal Number type, that would be an unambiguous bug, as it would contradict the type information and documentation.

    If the API is returning SystemStats.battery as a literal Float type, but its value is always an integer, that would be annoying (and perhaps limiting for some use cases) but arguably less of a bug.

  • > According to the docs: Toybox.System.Stats.battery as Float, but on real fr965 it is a Number or at least it's value is always a Number (without decimal).

    "or at least it's value is always a Number (without decimal)."

    I think you mean "or at least its value is always an integer (or whole number)"

    To be clear there are two possibilities here:

    - SystemStats.battery is not being returned as a literal Float type (i.e. instanceof Float != true), but instead as a Number (or less likely, a Long). I think this is what you meant by "it is a Number" (referring to the literal type)

    - System.Stats.battery is actually being returned as a literal Float type, but its value is always an integer (or whole number). I think this is what you meant by "it's value is always a Number (without decimal)."

    One statement refers to the object type (where Number or Float are relevant types), while the other statement refers to a property of the value itself (e.g. whether or not the fractional part is ever non-zero)

    I know you know all that, but in context, "or at least it's value is always a Number (without decimal)" is not precise writing (specifically, the use of "Number" isn't correct here).

  • Not that I disagree this is a bug, but didn't you imply this bug isn't important, when somebody else reported it?

    forums.garmin.com/.../system-getsystemstats-battery---xx-0000-instead-of-xx-xxxx-on-newer-generation-watches-enduro3-fenix8-fr965

    This just goes to show that the importance / validity of bug is usually correlated with the dev's personal level of interest in the functionality. If I care about it, it's a bug. If I don't care about it / don't know what it is, it's not a bug.

    See the other response in the thread from someone who thought fractional battery percentage in CIQ was VERY useful 10 years ago (and argued so passionately and convincingly that they changed the mind of someone who thought whole numbers are good enough for anyone), but in 2025 they think whole numbers are good enough for anyone.