Real data types reset to strings upon device init comm

Posted on
Thu Sep 24, 2020 1:49 pm
rhanson offline
Posts: 192
Joined: Apr 30, 2013

Real data types reset to strings upon device init comm

I think I discovered a bug in the real device type. When the device is disabled and then enabled, apparently the datatypes get reset to string.

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!

Posted on
Thu Sep 24, 2020 2:05 pm
DaveL17 offline
User avatar
Posts: 6751
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Real data types reset to strings upon device init comm

Wow, that's pretty sneaky. Glad you were able to figure out what the problem was. I will get into the code and see what can be done about that bug.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Thu Sep 24, 2020 2:34 pm
DaveL17 offline
User avatar
Posts: 6751
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Real data types reset to strings upon device init comm

Hmmm. I'm not seeing the same behavior. What I did to try to recreate the problem:

Using the Indigo scripting shell, I ran the following code:

Code: Select all
dev = indigo.devices[12345678].states
indigo.server.log(unicode(dev))
Then I disabled and re-enabled the device and ran the code again.

Before:

Code: Select all
Sep 24, 2020 at 3:23:52 PM
   Interactive Shell               States : (dict)
     City : Chicago (string)
     City.ui : Chicago (string)
     Delay : false (bool)   <======
     Delay.ui : false (string)
     DelayCount : 0 (integer)   <======
     DelayCount.ui : 0 (string)
     IATA : MDW (string)
     IATA.ui : MDW (string)
     ICAO : KMDW (string)
     ICAO.ui : KMDW (string)
     Name : Chicago Midway Intl (string)
     Name.ui : Chicago Midway Intl (string)
     State : IL (string)
     State.ui : IL (string)
     Status_0_Reason : No known delays for this airport (string)
     Status_0_Reason.ui : No known delays for this airport (string)
     SupportedAirport : true (bool)   <======
     SupportedAirport.ui : true (string)
     Weather_Meta_0_Credit : NOAA's National Weather Service (string)
     Weather_Meta_0_Credit.ui : NOAA's National Weather Service (string)
     Weather_Meta_0_Updated : Last Updated on Sep 24 2020, 2:53 pm CDT (string)
     Weather_Meta_0_Updated.ui : Last Updated on Sep 24 2020, 2:53 pm CDT (string)
     Weather_Meta_0_Url : http://weather.gov/ (string)
     Weather_Meta_0_Url.ui : http://weather.gov/ (string)
     Weather_Temp_0 : 79.0 F (26.1 C) (string)
     Weather_Temp_0.ui : 79.0 F (26.1 C) (string)
     Weather_Visibility_0 : 10 (real)   <======
     Weather_Visibility_0.ui : 10 (string)
     Weather_Weather_0_Temp_0 : Partly Cloudy (string)
     Weather_Weather_0_Temp_0.ui : Partly Cloudy (string)
     Weather_Wind_0 : Southwest at 13.8 (string)
     Weather_Wind_0.ui : Southwest at 13.8 (string)
     deviceIsOnline : true (bool)
     deviceIsOnline.ui : Updated (string)
     deviceLastUpdated : 09/24/2020 at 15:16 (string)
     deviceTimestamp : 1600978564.147799 (real)
     parse_error : false (bool)
After:

Code: Select all
Sep 24, 2020 at 3:24:38 PM
   Interactive Shell               States : (dict)
     City : Chicago (string)
     City.ui : Chicago (string)
     Delay : false (bool)   <======
     Delay.ui : false (string)
     DelayCount : 0 (integer)   <======
     DelayCount.ui : 0 (string)
     IATA : MDW (string)
     IATA.ui : MDW (string)
     ICAO : KMDW (string)
     ICAO.ui : KMDW (string)
     Name : Chicago Midway Intl (string)
     Name.ui : Chicago Midway Intl (string)
     State : IL (string)
     State.ui : IL (string)
     Status_0_Reason : No known delays for this airport (string)
     Status_0_Reason.ui : No known delays for this airport (string)
     SupportedAirport : true (bool)   <======
     SupportedAirport.ui : true (string)
     Weather_Meta_0_Credit : NOAA's National Weather Service (string)
     Weather_Meta_0_Credit.ui : NOAA's National Weather Service (string)
     Weather_Meta_0_Updated : Last Updated on Sep 24 2020, 2:53 pm CDT (string)
     Weather_Meta_0_Updated.ui : Last Updated on Sep 24 2020, 2:53 pm CDT (string)
     Weather_Meta_0_Url : http://weather.gov/ (string)
     Weather_Meta_0_Url.ui : http://weather.gov/ (string)
     Weather_Temp_0 : 79.0 F (26.1 C) (string)
     Weather_Temp_0.ui : 79.0 F (26.1 C) (string)
     Weather_Visibility_0 : 10 (real)   <======
     Weather_Visibility_0.ui : 10 (string)
     Weather_Weather_0_Temp_0 : Partly Cloudy (string)
     Weather_Weather_0_Temp_0.ui : Partly Cloudy (string)
     Weather_Wind_0 : Southwest at 13.8 (string)
     Weather_Wind_0.ui : Southwest at 13.8 (string)
     deviceIsOnline : true (bool)
     deviceIsOnline.ui : Updated (string)
     deviceLastUpdated : 09/24/2020 at 15:16 (string)
     deviceTimestamp : 1600978564.147799 (real)
     parse_error : false (bool)

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Fri Sep 25, 2020 10:58 am
rhanson offline
Posts: 192
Joined: Apr 30, 2013

Re: Real data types reset to strings upon device init comm

Huh. That's really weird.

I tried it again... same result. Enabled:

Code: Select all
 Interactive Shell               States : (dict)
     deviceIsOnline : true (bool)
     deviceIsOnline.ui : Updated (string)
     deviceLastUpdated : 09/25/2020 at 09:41 (string)
     deviceTimestamp : 1601052094.742687 (real)
     parse_error : false (bool)
     results_blue : 0.4581196581196581 (real)
     results_blue.ui : 0.4581196581196581 (string)
     results_grey : 0.001709401709401709 (real)
     results_grey.ui : 0.001709401709401709 (string)
     results_white : 0.1213675213675214 (real)
     results_white.ui : 0.1213675213675214 (string)
     status : ok (string)
     status.ui : ok (string)


Disable, enable:

Code: Select all
  Interactive Shell               States : (dict)
     deviceIsOnline : true (string)
     deviceIsOnline.ui : Started (string)
     deviceLastUpdated : 09/25/2020 at 09:41 (string)
     deviceTimestamp : 1601052094.742687 (string)
     parse_error : false (string)
     results_blue : 0.4581196581196581 (string)
     results_blue.ui : 0.4581196581196581 (string)
     results_grey : 0.001709401709401709 (string)
     results_grey.ui : 0.001709401709401709 (string)
     results_white : 0.1213675213675214 (string)
     results_white.ui : 0.1213675213675214 (string)
     status : ok (string)
     status.ui : ok (string)


Then I tried a different device. Same web service, this one looks for trash cans left out after trash pickup so Indigo can harass the kids to bring them in.

Before:

Code: Select all
  Interactive Shell               States : (dict)
     deviceIsOnline : true (bool)
     deviceIsOnline.ui : Updated (string)
     deviceLastUpdated : 09/25/2020 at 09:41 (string)
     deviceTimestamp : 1601052095.137426 (real)
     parse_error : false (bool)
     results_green : 0 (real)
     results_green.ui : 0 (string)
     status : ok (string)
     status.ui : ok (string)


After:

Code: Select all
Interactive Shell               States : (dict)
     deviceIsOnline : true (bool)
     deviceIsOnline.ui : Updated (string)
     deviceLastUpdated : 09/25/2020 at 09:41 (string)
     deviceTimestamp : 1601052095.137426 (real)
     parse_error : false (bool)
     results_green : 0 (real)
     results_green.ui : 0 (string)
     status : ok (string)
     status.ui : ok (string)


So that one does not get affected. Bizarre, so I deleted the original device completely and created a new device.

Brand new device (status = Started, prior to first refresh):

Code: Select all
Interactive Shell               States : (dict)
     deviceIsOnline : false (string)
     deviceIsOnline.ui : Started (string)
     deviceLastUpdated : 09/25/2020 at 09:49 (string)
     deviceTimestamp : 1601052540.331027 (string)
     parse_error : false (string)
     results_blue : 0.5965811965811966 (string)
     results_blue.ui : 0.5965811965811966 (string)
     results_grey : 0 (string)
     results_grey.ui : 0 (string)
     results_white : 0.008547008547008548 (string)
     results_white.ui : 0.008547008547008548 (string)
     status : ok (string)
     status.ui : ok (string)

After refresh:

Code: Select all
Interactive Shell               States : (dict)
     deviceIsOnline : true (bool)
     deviceIsOnline.ui : Updated (string)
     deviceLastUpdated : 09/25/2020 at 09:50 (string)
     deviceTimestamp : 1601052619.821989 (real)
     parse_error : false (bool)
     results_blue : 0.6153846153846154 (real)
     results_blue.ui : 0.6153846153846154 (string)
     results_grey : 0 (real)
     results_grey.ui : 0 (string)
     results_white : 0.003418803418803419 (real)
     results_white.ui : 0.003418803418803419 (string)
     status : ok (string)
     status.ui : ok (string)


Disable, enable:

Code: Select all
  Interactive Shell               States : (dict)
     deviceIsOnline : true (string)
     deviceIsOnline.ui : Started (string)
     deviceLastUpdated : 09/25/2020 at 09:50 (string)
     deviceTimestamp : 1601052619.821989 (string)
     parse_error : false (string)
     results_blue : 0.6153846153846154 (string)
     results_blue.ui : 0.6153846153846154 (string)
     results_grey : 0 (string)
     results_grey.ui : 0 (string)
     results_white : 0.003418803418803419 (string)
     results_white.ui : 0.003418803418803419 (string)
     status : ok (string)
     status.ui : ok (string)


So maybe there's something funny about these particular states?

No matter, I've just ensured that the results are float in the code, so no big deal. I just thought it was weird.

Posted on
Sat Sep 26, 2020 5:04 am
DaveL17 offline
User avatar
Posts: 6751
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Real data types reset to strings upon device init comm

Thanks for taking that extra effort. I'll start by looking at the code where the device is first created and then go from there.

It's something that shouldn't be happening and I definitely want to address it.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Mon Sep 28, 2020 6:13 am
DaveL17 offline
User avatar
Posts: 6751
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Real data types reset to strings upon device init comm

UPDATE: It took a bit of fiddling, but I think I've been able to isolate and address this bug. I've uploaded a new build (v0.4.57) to GitHub. It is not yet an official release and is not available via the Indigo Plugin Store.

NOTE: This new version is several iterations ahead of the latest release and could contain other bugs. I'd recommend saving a copy of the version you currently have before trying this new version just to be safe. You may need to refresh existing Real Type devices to ensure that their states are true to type for the changes to take effect (if they're currently all strings, the changes won't stick until the next refresh)..

https://github.com/IndigoDomotics/GhostXML ===> Select 'Code' and then 'Download ZIP'.

FYI - other differences from the current official release:
Code: Select all
v0.4.57
- Fixes bug where states for Real Type devices were returned as strings when device comm first started.

v0.4.56
- Code refinements.

v0.4.55
- Adds option to turn off curl globbing.

v0.4.54
- Adds code to address tags that start with the 'illegal' @ character.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest

cron