Defining a class within a app definition

I am unable to save an app file with a custom class definition in it, with the error

Importing [AWSSRP] is not allowed Expression [MethodCallExpression] is not allowed: org.codehaus.groovy.runtime.InvokerHelper.runScript(Script1, args) at line number -1

class AWSSRP {
....
}


def version() {"1.0.0"}
def appVersion() { return version() }
def appName() { return "Schlage Wifi Locks Support" }

definition(
    name: "${appName()}",
    namespace: "schwark",
    author: "Schwark Satyavolu",
    description: "This adds support for Schlage Wifi Locks",
    category: "Convenience",
    iconUrl: "https://play-lh.googleusercontent.com/7IH82e5JiqI2_a9oWndaDyBETXtV45a-QhW_0f-ekADl6W2A3Q0u_vEWQHfQF0D-Flg=w600-h300-pc0xffffff-pd",
    iconX2Url: "https://play-lh.googleusercontent.com/7IH82e5JiqI2_a9oWndaDyBETXtV45a-QhW_0f-ekADl6W2A3Q0u_vEWQHfQF0D-Flg=w600-h300-pc0xffffff-pd",
    singleInstance: true,
    importUrl: "https://raw.githubusercontent.com/schwark/hubitat-schlage/main/schlage.groovy"
)

Can I not put functionality into a class defined in this file? Is there another way to do this?

1 Like

For anyone else looking for the answer to this question - you cannot. You have to unroll your class into the app or driver..

Correct. I would suggest reading the Developer Overview if you have not already, specifically the "Development Environment" section, which notes this issue (among others you may need to know if you are not used to the sandbox).

Disappointing if one wants to define a simple object to put into a list. My guess is that this is disabled for memory usage concerns, a jillion new objects popping up. Has that actually been a problem?