Skeleton app has features I didn't code (and don't look like they should be there)

Here's a strange one I came across starting to write a new app. I started with the skeleton in Building a Simple App | Hubitat Documentation

definition(
    name: "Sample Application",
    namespace: "Example",
    author: "Hubitat Example",
    description: "A skeleton sample app for HE",
    category: "Convenience",
    iconUrl: "",
    iconX2Url: "")

preferences {
}

def installed() {
    log.debug "installed()"
}

def updated() {
    log.debug "updated()"
}

def uninstalled() {}

The app page looks like this (C7 - 2.3.7.138) :

The name assignment feature I guess is OK, might have thought it's standard, but why is the mode selector there?

Adding an empty section to the preferences doesn't change anything, but a page definition makes this stuff go away:

    page(name: "mainPage", title: "Title", install: true, uninstall: true) {}

It's really a minor issue, but was a distraction until I could figure out how to get rid of it.

Mode selector is also standard

1 Like

This is normal. If you don't define any pages yourself (this is sometimes called a "single-page app" even though I think literally defining a single page yourself doesn't do this), the UI automatically provides mode selectors for you and makes them work (just doesn't wake your app when things happen if the mode isn't right).

The way around it is to do exactly what you figured out. The idea, presumably, is that more complicated apps with multiple pages might have fancier things they want to do with modes (and in that case the onus is also on you to actually make the selector, should you offer one somehow, work). Most apps do offer something since modes are a common way to "restrict" apps, and this just makes it easy for single-page apps.

Similar with app name/label.

3 Likes

Ok thanks. Good to know. Is there a reference to this in the docs I missed?

I want to say there should be somewhere, likely not in that particular one; but there will be somewhere if not. :slight_smile:

1 Like

Haha, yeah. This is a carry-over from SmartThings. When we first started out, we tried to make things compatible with the way SmartThings was in 2016-17. At that time we didn't have any documentation to speak of, and most of our users came from SmartThings. They quickly figured out they could just refer to the ST documentation for apps.

The mode selector was basically a simple default restriction.

If you look in our public repo at the example apps, you'll discover that every one of them uses a page definition, so that what you get in the UI is exactly what you put there.

3 Likes