Here's a device that reads a value from one of my own web-based services that returns a JSON object. It takes a look at the sky to determine how much blue, white or grey. This gives me a real-time readout of cloud cover without building some fancy laser cloud sensor.
When the device is enabled, and has successfully refreshed itself, this is what the states look like. Observe that timestamp and results values are float, as expected.
- Code: Select all
>>> print a.states
States : (dict)
deviceIsOnline : true (bool)
deviceIsOnline.ui : Updated (string)
deviceLastUpdated : 09/24/2020 at 10:26 (string)
deviceTimestamp : 1600968360.149234 (real)
parse_error : false (bool)
results_blue : 0.6102564102564103 (real)
results_blue.ui : 0.6102564102564103 (string)
results_grey : 0 (real)
results_grey.ui : 0 (string)
results_white : 0 (real)
results_white.ui : 0 (string)
status : ok (string)
status.ui : ok (string)
But, if I disable comms on this device, and then re-enable, the states look like this:
- Code: Select all
>>> print x.states
States : (dict)
deviceIsOnline : true (string)
deviceIsOnline.ui : Started (string)
deviceLastUpdated : 09/24/2020 at 12:26 (string)
deviceTimestamp : 1600975580.082948 (string) <======
parse_error : false (string)
results_blue : 0.8632478632478633 (string) <=======
results_blue.ui : 0.8632478632478633 (string)
results_grey : 0 (string) <======
results_grey.ui : 0 (string)
results_white : 0 (string) <======
results_white.ui : 0 (string)
status : ok (string)
status.ui : ok (string)
>>>
See how they are all strings? After some time, when it gets a chance to refresh, then the data types are reset back to valid types (bool, float, etc.). I was getting type-mismatch errors and was going nuts trying to figure out how this could possibly be wrong, until I noticed that yes, indeed, those values are strings!