Mixing atomicState and state

:point_down::rofl::rofl:

Nothing to contribute here. I've just been following this thread so I could learn more about atomicState vs state variables and since I can't give you a solution I figured I'd give you what asked for :stuck_out_tongue_winking_eye:.

2 Likes

:rofl::joy::rofl:

Maybe it's not such an atomic era

1 Like

what are you using? I guess not pauseExecution ?

I'm using this from an old ST post by Terry (ActionTiles)

  • should I be using pauseExecution ?

    def pause(millis) {
    def passed = 0
    def now = new Date().time
    /* This loop is an impolite busywait. We need to be given a true sleep() method, please. */
    while ( passed < millis ) {
    passed = new Date().time - now
    }
    }

Yes you should be :slight_smile:
The method you posted puts unnecessary load on the hub. I'm wondering how many people are using something like that?

sorry I missed it .. where is it documented ?
Google was not my friend
I assume it takes a single parameter in mS

The post above has a link to it (click on pauseExecution):

Thanks - and no possibility to disable or hide devices ?

I'm not sure what you mean.. you want to hide devices from the user? in the main devices list? If so, then no.

I wanted to hide them from the user or disable them like the 'disable' checkbox does. One way they would be totally hidden except for getChildDevice() etc and the other they just don't function. Not a problem but that would have been an easy solution as there are 150 devices involved (for me) and they clutter the interface currently.

Why donā€™t you just filter the devices at creation time and only create the ones you need?

I for one think it would be a very bad idea for apps and devices to be able to hide devices. That concept has the potential for serious abuse.

2 Likes

Initially it was because I couldnā€™t create a valid input drop down to select from, now using a delay in my device driver I can.

Also still as an obstacle is the deviceID, label and capabilities all arrive separately, and I need to match them up before creating the device. Iā€™m on the way to being able to implement this though now.

Having disable as is already implemented in the UI would be useful but yes, I can also see issues with hidden.

K

It's very difficult to provide feedback without seeing more of your code and you probably don't want or need any....you are obviously a more proficient programmer than I am. But based on the pieces I'm putting together from this thread, it sounds like you are trying to do things in the driver that might be better accomplished in the app portion of the code. For instance, your device list could be stored in a map or list and presented as an enum input where the user could select the drivers they want created.

I realize I am making a lot of assumptions above but it just seems like it should be possible and would make timing the device creation easier and avoid needless cycles creating unneeded devices. Just my 2c.

Thats where I would focus my energy if I were in your position. If you can't change the serial nature of the data coming in, you can at least cache it in state and then create your devices once you have all of the needed components.

Indeed I can now do that using the small inserted delay that has got the list 'stable' - before it was being mangled even using atomicState

I couldn't actually as it arrived asynchronously and too fast so state was inconsistent. Even too fast for atomicState , which is not bullet proof. By using a tiny delay of 50mS I now have it robust though so, once more I'm all set to proceed.

This is the nature of MQTT - if you subscribe to a wildcarded topic to retrieve say a list of devices you will get a load of payloads returned instantaneously in a burst of individual messages. In my case over 150. Payloads e.g. labels' arrive together but the devices they apply to are all interleaved.

I'm on the right track now though.

I've also been considering whether it would be useful to present MQTT devices to other Hub Connect clients directly for selection. Of course creating a device on HE facilitates this anyway.

A word of caution... It you are using atomicState to store data with continuous high-frequency access (reads and writes to the database) you will inevitably create a ā€œhub killerā€ app. Hopefully youā€™re able to avoid that.

As I visualize this I still think you can use state for this with a periodic runIn job to marry up all of the arriving data parts leading to device creation. Itā€™s just a thought based on my very limited of what youā€™re trying to do.

I gave some thought to MQTTA integration with HubConnect but inevitably ran into the same challenges you are facing. I just couldnā€™t visualize how I could emulate the same or at least similar user experience.

Iā€™m open to suggestions if you ever want to take a crack at it.

Fortunately Itā€™s just the startup of the app that needs to model the incoming messages. Maybe the first 30 seconds, and then only if you are using MQTT discovery. Once that is complete I donā€™t think I ongoingly use atomicState at all so this isnā€™t an issue. State would indirectly create much the same effect.

Iā€™ll keep pondering about MQTT and HubConnect...

1 Like