bdwilson / hubitat

Hubitat Contributions
18 stars 19 forks source link

OwnTracks - Swap Display Name with Device Network ID #1

Closed Cjkeenan closed 3 years ago

Cjkeenan commented 3 years ago

This is just a simple swap between using the name to denote who and where the presence is for from the Display Name/Display Label (what most people organize by) to the Device Network ID. This allows for the user to change the display name/label as they please for organization purposes of their devices without breaking any functionality. It would require a modification of the setup-guide however.

Please let me know if I am breaking anything by making this change.

Variable names ideally would be changed around a little for clarity, but I figured I would leave that to you so that I did not screw anything up.

Cjkeenan commented 3 years ago

Alternatively, and this might be better, do not modify the Device Network ID by leaving the generated GUID. Instead add preferences as part of the driver to denote person and location/region. It would require accessing these preferences inside the app however.

Cjkeenan commented 3 years ago

So I am trying to rework it using Preferences and State Variables and I have gotten the driver to successfully save this data, but the app for whatever reason cannot see these state variables. I have tried using the following and nothing seems to be working: def myLocation = myDevice.getDataValue("region") def myLocation = myDevice.state.region def myLocation = myDevice.data.region def myLocation = myDevice.currentValue("region") def myLocation = myDevice.currentState("region")

Virtual Device for reference: image

Added this to the driver:

metadata {
...
        //attribute "region", "text"
        //attribute "user" , "text"

        preferences { 
            input name: "region", type: "text", title: "Location/Region to Track", required: true
            input name: "user", type: "text", title: "User to Track", required: true
        }
}
...
def updated() {
    //sendEvent(name: "user", value: "${user}")
    //sendEvent(name: "region", value: "${region}")
    state.clear()
    state.region = "${region}"
    state.user = "${user}"
}

When I use the attribute and it stores the data in the Current States it is fine and def myLocation = myDevice.currentValue("region") works but I was under the impression State Variables are more setup variables than current values which I think the user and region would be.

Any ideas on what is going wrong or what the next steps might be?

Cjkeenan commented 3 years ago

Replaced by https://github.com/bdwilson/hubitat/pull/3 and https://github.com/bdwilson/hubitat/pull/2