Announcement

Collapse
No announcement yet.

plugextradata - errors retreiving 'SOME' data - no issues setting data

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • alexbk66
    replied
    Originally posted by dmurphy View Post


    seemingly the dictionary initializer was updated in c# 6.....so either variant should work...

    https://visualstudiomagazine.com/Blo...tializers.aspx
    Thanks, good to know. I don't see huge advantage in syntax they describe.

    Leave a comment:


  • dmurphy
    replied
    This works thanks spud - addNamed and getNamed have issues.

    Code:
    Dictionary<string, string> changes = new Dictionary<string, string>();
    
    changes.Add("libver", "2.3");
    changes.Add("libver1", "2.3.2");
    changes.Add("sketch", "Kitchen Monitor");
    
    PlugExtraData ped = dev.PlugExtraData;
    
    foreach (KeyValuePair<string, string> change in changes) {
        //ped.AddNamed(change.Key, change.Value);
        ped[change.Key] = change.Value;
    }
    
    Hs.UpdatePropertyByRef(refId, EProperty.PlugExtraData, ped);
    
    AbstractHsDevice updatedDev = Hs.GetDeviceByRef(refId);
    PlugExtraData updatedPed = updatedDev.PlugExtraData;
    
    string libver = updatedPed["libver"];
    string libver1 = updatedPed["libver1"];
    string sketch = updatedPed["sketch"];

    Leave a comment:


  • dmurphy
    replied
    Originally posted by alexbk66 View Post
    The syntax of your dictionary initialiser looks strange, should id simply be just

    seemingly the dictionary initializer was updated in c# 6.....so either variant should work...

    https://visualstudiomagazine.com/Blo...tializers.aspx

    Leave a comment:


  • dmurphy
    replied
    thanks, thought I was losing it again

    Leave a comment:


  • alexbk66
    replied
    I don't use their GetNamed,

    Click image for larger version

Name:	Screenshot 2021-05-14 014657.jpg
Views:	36
Size:	101.5 KB
ID:	1474207

    Leave a comment:


  • alexbk66
    replied
    Yep, can reproduce the problem. They trim quotes from json string, so JsonConvert becomes confused. WTH???

    BTW, that's the reason I always use SDK code, not prebuilt library - so I can debug this mess.

    So I guess it's https://github.com/HomeSeer/Plugin-SDK/issues

    Click image for larger version

Name:	Screenshot 2021-05-14 014145.jpg
Views:	41
Size:	28.1 KB
ID:	1474204

    Leave a comment:


  • dmurphy
    replied
    I created a test with least amount of code.

    Code:
    Dictionary<string, string> changes = new Dictionary<string, string>();
    changes.Add("libver", "2.3");
    changes.Add("libver1", "2.3.2");
    
    PlugExtraData ped = dev.PlugExtraData;
    
    foreach (KeyValuePair<string, string> change in changes) {
        ped.AddNamed(change.Key, change.Value);
    }
    
    Hs.UpdatePropertyByRef(refId, EProperty.PlugExtraData, ped);
    
    AbstractHsDevice updatedDev = Hs.GetDeviceByRef(refId);
    PlugExtraData updatedPed = updatedDev.PlugExtraData;
    
    string libver = updatedPed.GetNamed<string>("libver"); //This works returns "2.3" as expected.
    string libver1 = updatedPed.GetNamed<string>("libver1"); // This throws exception previously noted....I'm using strings not numbers....

    Leave a comment:


  • alexbk66
    replied
    What's your object class definition you are trying to Deserialise? Obviously it expects a number (float, which 2.3 is) - but "2.3.2" is not a number - it's a string.

    Leave a comment:


  • dmurphy
    replied
    So I simplified the code......

    Code:
    Dictionary<string, string> peds = new Dictionary<string, string>();
    peds.Add("libver", "2.3.2");
    Subsequently I try to get the ped the sdk throws a - Newtonsoft.Json.JsonReaderException


    + $exception {"Input string '2.3.2' is not a valid number. Path '', line 1, position 5."} Newtonsoft.Json.JsonReaderException

    BUT if I change the 2.3.2 to 2.3 everything is fine?????? Funny the string is being treated as a number?

    The PED data returned from HS looks fine, but the sdk GetNamed function throws an error (see pic)
    Attached Files

    Leave a comment:


  • alexbk66
    replied
    The syntax of your dictionary initialiser looks strange, should id simply be just


    Code:
    Dictionary<string, string> peds = new Dictionary<string, string>()
    {
        {"nodeid", "10"},
        {"childid", "1"},
    };
    BTW, .NET has StringDictionary class

    Leave a comment:


  • plugextradata - errors retreiving 'SOME' data - no issues setting data

    So I store a bunch of PED info.

    Code:
    Dictionary<string, string> peds = new Dictionary<string, string>() {
         ["nodeid"] = "10",
         ["childid"] = "1",
         ["sketch"] = "kitchen monitor",  
         ["libver"] = "2.3",
         ["sketchver"] = "0.6",
         ["heartbeat"] = "94129",
         ["config"] = "Imperial"
    };
    I can read PED data and review in VS2019 and it looks fine. However when I read the ped data with SDK GetNamed() I get jsondeserializationexception thrown from the sdk.

    it fails on the string "2.3.2" but "2.3" works fine....are there restrictions on what can be in a string for a PED? is it documented somewhere.
Working...
X