How to get zones from method UserProfile.getPowerZones()

In SDK 9.1.0 four methods were added to UserProfile: getHeartRateZones2(), getPowerZones(), getFunctionalThresholdPower() and getCurrentSport2().
I can get data from three of them but not from getPowerZones(), it returns null.

I tried it in the simulator and on my Edge 1050.
Did anyone try and succeed?

This is what I coded to test the method:

if (UserProfile has :getPowerZones) {
    System.println("Using getPowerZones from UserProfile");
    var sport = UserProfile.getCurrentSport2();
    var pZones;
    System.println("sport: " + sport);
    if (sport != null && sport.size() > 0) {
        System.println("Using getPowerZones for sport: " + sport[0]);
        pZones = UserProfile.getPowerZones(sport[0]);
        System.println("pZones1: " + pZones);
    }
}

  • Where do you try it? Simulator or real device? Do you have power zones set in the user's account?

  • Do you have an external power meter paired with your 1050?

  • There is no setting for powerZones in the simulator of SDK 9.1.0!
    Can‘t work on simulator…

    But it works on real Edge 1050 (just tried)

     (tap on picture icon)

  • I tried it on my Edge in my MTB profile and in my road profile but no luck. I have an external powermeter that is connected to the Edge. I have power zones on my Edge.

    I saw that there were no power zonnes visible in the simulator so that's why I tried it with a data field on a real device.
    What is your code?

    Did I make a mistake?

  • Just a short code without null checks... (you need UserProfile permission)

    class _ComplexBasisView extends WatchUi.DataField {
    
        var lValue;
        var mValue;
        var fieldWidth = 0;
        var fieldHeight = 0;
        var poSport;
        var poZones;
    
    
        function initialize() {
            DataField.initialize();
    
        }
    
    
        // The given info object contains all the current workout information.
        // Calculate a value and save it locally in this method.
        // Note that compute() and onUpdate() are asynchronous, and there is no
        // guarantee that compute() will be called before onUpdate().
        function compute(info as Activity.Info) as Void {
    
            poSport = UserProfile.getCurrentSport2();
            //System.println("poSport: " + poSport);
            poZones = UserProfile.getPowerZones(poSport[0]);
            //System.println("poZones: " + poZones);
    
            lValue = poSport.toString(); 
            mValue = poZones;
    
        }
    
        // Display the value you computed here. This will be called
        // once a second when the data field is visible.
    
        function onUpdate(dc as Dc) as Void {
            fieldWidth = dc.getWidth();
            fieldHeight = dc.getHeight();
            var backgroundColor = getBackgroundColor();
            // set foreground color
            dc.setColor((backgroundColor == Graphics.COLOR_BLACK) ? Graphics.COLOR_WHITE : Graphics.COLOR_BLACK, Graphics.COLOR_TRANSPARENT);
        
            dc.drawText(fieldWidth / 2, 25, Graphics.FONT_SMALL, lValue, Graphics.TEXT_JUSTIFY_CENTER);
            dc.drawText(5, 85 , Graphics.FONT_SMALL, mValue, Graphics.TEXT_JUSTIFY_LEFT);
        
        }
    
    }
    

    I see no problem in your code.

    If you have it in Initialize() - try to move it to Compute()