SageTV Community

SageTV Community (http://forums.sagetv.com/forums/index.php)
-   SageTV Studio (http://forums.sagetv.com/forums/forumdisplay.php?f=34)
-   -   Studio and enums (http://forums.sagetv.com/forums/showthread.php?t=64008)

jvl711 01-26-2017 11:02 AM

Studio and enums
 
Hi,

I am not sure if I am just being dense, but I am having an issue utilizing enums in a project I am working on in studio.

Here is the scenario

Method I am calling which returns an enum
Code:


public HVACMode getHVACMode()

The enum
Code:


public enum HVACMode
    {
        OFF("Off", "Off"),
        HEAT_ON("HeatOn", "Heat On"),
        COOL_ON("CoolOn", "Cool On"),
        AUTO_CHANGE_OVER("AutoChangeOver", "Auto Change Over"),
        UNKNOWN("Unknown", "Unknown");
       
        private String mode;
        private String name;
       
        private HVACMode(String mode, String name)
        {
            this.mode = mode;
            this.name = name;
        }
       
        public static HVACMode parseMode(String mode)
        {
            if(mode.equals(OFF.getMode()))
            {
                return OFF;
            }
            else if(mode.equals(HEAT_ON.getMode()))
            {
                return HEAT_ON;
            }
            else if(mode.equals(COOL_ON.getMode()))
            {
                return COOL_ON;
            }
            else if(mode.equals(AUTO_CHANGE_OVER.getMode()))
            {
                return AUTO_CHANGE_OVER;
            }
            else
            {
                return UNKNOWN;
            }
           
        }
       
        public String getMode()
        {
            return mode;
        }
       
        public String getName()
        {
            return name;
        }
    }

So I am trying to do this call and it is saying that is can not reflect the static value

Code:


IF jvl_vera_devices_Thermostat_getHVACMode(instance) == jvl_vera_devices_Thermostat_HVAVMode_OFF


Sage says it does not know what "jvl_vera_devices_Thermostat_HVAVMode_OFF" is. Is this possible. Am I doing something wrong. What do you do if there is an underscore in the name of the enum like "HEAT_OFF"?

Any help would be appreciated.

Josh

Fuzzy 01-26-2017 11:52 AM

I don't think I've seen an enum used in studio - it my simply not be supported. You likely should implement a simpler method that either returns a string, or a series of boolean 'isOff, isOn' etc methods.

jvl711 01-26-2017 12:19 PM

Quote:

Originally Posted by Fuzzy (Post 599811)
I don't think I've seen an enum used in studio - it my simply not be supported. You likely should implement a simpler method that either returns a string, or a series of boolean 'isOff, isOn' etc methods.

Yeah... That is what I have been doing :rolleyes:

Do you know if there is a way to handle method names or variables with an underscore in them?

Fuzzy 01-26-2017 12:31 PM

Quote:

Originally Posted by jvl711 (Post 599815)
Yeah... That is what I have been doing :rolleyes:

Do you know if there is a way to handle method names or variables with an underscore in them?

Same... I don't think you can. From what I remember, Sun recommends against using underscores in method and variable names, and recommends using CamelCase for everything.

jvl711 01-26-2017 12:59 PM

Quote:

Originally Posted by Fuzzy (Post 599816)
Same... I don't think you can. From what I remember, Sun recommends against using underscores in method and variable names, and recommends using CamelCase for everything.

I would generally agree that ubderscores are not common, but in this particular case it 100% follows the java convention. Below is the convention for constants, which is what I would consider the value of an enum.

http://www.oracle.com/technetwork/ja...ns-135099.html

Quote:

Constants:

The names of variables declared class constants and of ANSI constants should be all uppercase with words separated by underscores ("_"). (ANSI constants should be avoided, for ease of debugging.)

static final int MIN_WIDTH = 4;

static final int MAX_WIDTH = 999;

static final int GET_THE_CPU = 1;

Fuzzy 01-26-2017 01:48 PM

Right, just remember that Studio is not Java. It utilized Java for it's expressions, but it is not equivalent to java code completely. It you want to run full java code, you compile that into a .jar, and make calls to that from the STV.

jvl711 01-26-2017 06:02 PM

I figured out my issue. Apparently studio somehow handles variables and methods with underscores without issues. It also can handle enums without issues.

Where my issue was I created my enum as a subclass/innerclass of another class. Sage was having issues creating an instance of the enum or referencing methods of the enum in this manner. I moved it out to its own and it works great!

So in otherwords I am not sure Studio can handle inner classes, or enums inside a class. This might have been my own stupidity, or possible just a weird reflection issue.

Josh


All times are GMT -6. The time now is 11:00 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.
Copyright 2003-2005 SageTV, LLC. All rights reserved.