Is there a way for a driver to get notified when global hub settings are changed?

There is a driver I'm writing for a temperature sensor where it would be very desirable to get a notification when global hub settings are changed.
The temperature comes calculated with the chosen scale from the device (which I'm also developing), and I would like to send a configuration command to device ASAP after a change in the settings.

1 Like

What settings are you looking for?

My guess would be whether the hub is configured for Fahrenheit or Celsius.

1 Like

I don't think there is any such method (presumably because these are settings most users would set once and then forget about).

I thought there was a function that could be called to return that info??? Maybe I am remembering wrong… :thinking:

For sure @mike.maxwell and @gopher.ny will know if it is possible for a driver to know whether or not the hub is configured for F or C. Then it is just a matter of using that information each time parse() is called.

I know the OP wants to send a command to the device to change its setting…. However is is pretty easy to convert in the driver itself.

To return the info, certainly. But to get notified of a change without the driver checking when it's awake for some other reason, including being about to generate an event, is what I don't think exists. Sounds like that's what the question was so events that had already been generated could be "updated"/regenerated, but maybe I read too far into that.

1 Like

Agree 100%. The device is not woken up when a hub setting like that is called, IIRC.

Yep, easy to get the data from the hub, but there isn’t a change event generated AFIK. I wrote a small app some time back that monitors, among other things, IP address changes, but its flow is to wake up and check the current values to what it has stored from a previous cycle.

Thanks for all the inputs! They were really helpful.
I think I'll go with a simple warning to the user, that a manual action will be needed if the temperature scale is changed.

I would just configure the device to always send temperature in the same scale and then use this method to convert it, if needed, based on hub settings:

String convertTemperatureIfNeeded(BigDecimal value, String scale, Integer precision)

4 Likes

This might be over engineering, excessively pedantic, premature optimization, or whatever you call it, but I love optimizing software :slight_smile: and I'm trying to use the hub's CPU as little as possible.
As @bertabcd1234 wisely put, it is very unlikely that this setting will be changed once it has been set.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.