Announcement

Collapse
No announcement yet.

Master Device creation in C#

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

    #31
    Again stupid mistake Monitor_Info should be Monitor.....

    Comment


      #32
      Hi Lorenjz,

      I couldn't look at youor problem as the forum was down but assuming from your comment above you're all good again?

      Comment


        #33
        Yup back in business. Thanks for checking in!

        Sent from my SM-G988U using Tapatalk

        Comment


          #34
          I'm making slow progress. Thanks to this forum I'm learning a lot and I wanted to say a big thank you especially to russr999!

          I've hit another snag and wanted to get some more input. I've started to code methods to create the devices and features that will communicate with the individual cameras. This is the method that I've been using to create them:

          Code:
           string MonInfo = await ZmServer.MonitorDetails();
          MonRoot m = JsonConvert.DeserializeObject<MonRoot>(MonInfo);
          
          
          foreach (var junk in m.monitors)
          {
          
          
          SortedDictionary<string, double> funcDD = new SortedDictionary<string, double>() { { "None", 0 }, { "Monitor", 1 }, { "Modect", 2 }, { "Record", 3 }, { "Mochord", 4 }, { "Nodect", 5 } };
          Console.WriteLine("Checking Variables.");
          var MonId = junk.Monitor.Id;
          var MonName = junk.Monitor.Name;
          var MonEnable = junk.Monitor.Enabled;
          var MonFunction = junk.Monitor.Function;
          
          
          if (HomeSeerSystem.GetDeviceByAddress("Monitor-" + MonId) == null)
          {
          
          
          
          
          //Create Monitor Device...
          DeviceFactory df = DeviceFactory.CreateDevice(Id);
          df.WithName(MonName);
          df.AsType(EDeviceType.Generic, 0);
          NewDeviceData ndd = df.PrepareForHs();
          HsDevice dv = hs.GetDeviceByRef(hs.CreateDevice(ndd));
          dv.Address = "Monitor-" + MonId;
          hs.UpdateDeviceByRef(dv.Ref, dv.Changes);
          //var myDevice = hs.GetDeviceByAddress("Monitor-" + MonId);
          
          
          //Create the Enabled feature
          var ff = FeatureFactory.CreateFeature(Id);
          ff.WithName("Enabled");
          ff.WithDefaultValue(1);
          ff.AddButton(0, "Disable");
          ff.AddButton(1, "Enable");
          
          var nfd = ff.PrepareForHsDevice(dv.Ref);
          int feature = HomeSeerSystem.CreateFeatureForDevice(nfd);
          Dictionary<EProperty, object> adddata = new Dictionary<EProperty, object>();
          adddata.Add(EProperty.Address, "ZM_Enabled" + MonId);
          hs.UpdateFeatureByRef(feature, adddata);
          
          
          df.WithFeature(ff);
          
          //Create the Function Feature
          var func = FeatureFactory.CreateFeature(Id);
          func.WithName("Function");
          func.AddTextDropDown(funcDD);
          double ActiveFunc;
          if (funcDD.TryGetValue(MonFunction, out ActiveFunc))
          {
          if (ActiveFunc != null)
          {
          func.WithDefaultValue(ActiveFunc);
          }
          }
          
          
          df.WithFeature(func);
          NewDeviceData dd;
          dd = df.PrepareForHs();
          int device = HomeSeerSystem.CreateDevice(dd);
          Dictionary<EProperty, object> addnewdata = new Dictionary<EProperty, object>
          {
          { EProperty.Address, "Monitor-"+MonId },
          { EProperty.VoiceCommand, MonName }
          
          };
          HomeSeerSystem.UpdateDeviceByRef(device, addnewdata);
          
          
          
          
          
          
          }
          I need some way to differentiate between the monitors when the buttons or drop down are interacted with and details are sent to "SetIOMulti". I thought the best way to handle that would be to set a unique address for each feature. However the Address isn't being set. I have a feeling that it has something to with the line "NewFeatureData nfd = ff.PrepareForHsDevice(dv.Ref);" is throwing System.Collections.Generic.KeyNotFoundException when it is run. Could that be it or am I doing something else wrong?

          Comment


            #35
            Hi lorenjz ,

            Try adjusting you're code slighty to see if it helps as follows:

            Code:
            {
            Dictionary<EProperty, object> adddata = new Dictionary<EProperty, object>();
            adddata.Add(EProperty.Address, "Monitor-"+MonId);
            adddata.Add(EProperty.VoiceCommand, MonName);
            HomeSeerSystem.UpdateFeatureByRef(feature, adddata);
            }
            I had a similar issue to you and found this method worked for me.

            Also, I do something similar - working out the type of device it is.
            I add it into PluginExtraData so a user cannot change it and then my first step in SetMultiIO is ot check the value to work out if I continue and do something or just ignore it.. This method also allows me to distingish between different type of actions then.
            If you want to go the PluginExtraData route, the code would be something like as follows:;

            Code:
            {
            PlugExtraData PIED = new PlugExtraData();
            PIED.AddNamed(Name.ToLower() + "_DeviceType", "Anything");
            func.WithExtraData(PIED);
            }
            This code would need to be added probabley jusut after your code line

            Code:
            func.AddTextDropDown(funcDD);
            Hope that helps

            Comment


              #36
              Until now I have been focused on information flowing from my plugin to zoneminder. Is there a way to have zoneminder send information to my plugin? For example PHLocation has this web address listed in it's manual: "https://connected2.homeseer.com/phl2api?dtype=TF" If this is possible how could I implement this for my plugin?

              Comment

              Working...
              X