I maybe misinterpreting your question. Tiles (not used in HE) are a dead giveaway that either the developer has not bothered to remove them or the code is intended for ST.
I get that. But there's really not that much diff between the two regarding this driver. Just handling things like physicalgraph vs hubitat, working around oddities, etc. Total diff is only probably 50 lines of code.
I mean more, can you call say (I know this is wrong, but) :
location.hubs.id.toString == "hubitat" vs == "smartthings" and then use if statements based on that?
I write code for a living, there's no convincing me this a good idea...
Put it this way, no one's going to think much of your driver if it's loaded with cruft...
in fairness, it's not mine. I'm asking for someone else who's trying to combine HE and ST code into single driver. I get what you're saying, but I can understand only wanting to maintain a single codebase.
Was just wondering if there was some way to do this... kinda sounds like not. =/
Not sure why we couldn't still provide some way to differentiate between the two... state.hubitat = true, or something... =/
Take a look at @tonesto7's Echo Speaks code. He's managed to get a single, rather large code base working for both platforms. That includes both app code and driver code, I believe.
I do agree with @mike.maxwell in terms of having separate code bases for each platform, but I have to give credit where credit's due when someone does manage to maintain a single code base for two disparate platforms.
great. I think the person has figured out a good check.
private getPlatform() {
def p = "SmartThings"
if (state.hubPlatform == null) {
try { [dummy: "dummyVal"].encodeAsJson(); } catch (e) { p = "Hubitat" }
// p = (location?.hubs[0]?.id?.toString()?.length() > 5) ? "SmartThings" : "Hubitat"
// try { def foo = physicalgraph.device.hubAction.newInstance() } catch (e) { p = "Hubitat" } // Not tested.
state.hubPlatform = p
log.debug "hubPlatform: (${state.hubPlatform})"
}
return state.hubPlatform
}
Some interesting notes. isNumber() and toInteger() are both technically string functions in Groovy. In Smartthings, if you run those against an integer, they just silently fail. In HE, it errors the code. =/
The easiest way for platform detection right now is to evaluate the value of location.hubs[0].name
On Hubitat it returns the hubs MAC Address. However in SmartThings it returns the name the user has given the hub.
For platform detection, this will work every time, unless someone has a SmartThings Hub with 5 colons in the name.