more G-Labs products

Author Topic: C# documentation  (Read 4540 times)

May 15, 2014, 05:36:19 AM
Read 4540 times

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
There was a page that showed all the methods and whatnot in a list broken up by module (or something like that).  I can't find the link now and it doesn't appear to be linked to the homegenie.it/docs page.  I think it was on http://generoso.info somewhere.  Any idea where that went?

I'm trying to figure out where UpdateTime can be used, currently.  I'll need that page in the future surely, but that'sthe main thing right now.
« Last Edit: May 15, 2014, 05:46:00 AM by bkenobi »

May 15, 2014, 05:45:19 AM
Reply #1

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I think the page was off of

http://generoso.info/homegenie/learn.html

It looks like this now redirects to the main homegenie.it site, though.

May 16, 2014, 06:53:44 PM
Reply #2

dutchie

  • **
  • Information
  • Jr. Member
  • Posts: 47
I think it's gone for now. Maybe in future (I hope in near future  ;)) it will be here:
http://www.homegenie.it/docs_api/index.html

May 16, 2014, 07:42:19 PM
Reply #3

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
That's where I was reviewing.  Looks like the page that used to contain all the methods and whatnot is lost for now.  Hope Gene can bring it back soon as I could really use it!

May 16, 2014, 08:46:45 PM
Reply #4

dutchie

  • **
  • Information
  • Jr. Member
  • Posts: 47
I hope so too.
Gene stated somewhere else he's not a fan of writing docs  :'(

Right now struggling through Visual Studio and Google (wish I knew how to prgram)
« Last Edit: May 17, 2014, 02:11:56 PM by dutchie »

May 27, 2014, 05:31:32 PM
Reply #5

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
Is there a property that holds the last activity of a module?  I have a motion sensor that works great, but the X10 signal can occasionally not reach the controller.  The module transmits via PLC and for whatever reason it doesn't get the signal to the controller every time.  I've done everything I can and it's up to 95-99%, but that's the best it will be.

So, what I need to do is check for the motion sensor being stuck in the ON position in the code.  The Advanced Smart Lights code I am working on tracks the last 2 instances of ON/OFF.  If I use the same motion sensor for multiple instances of this code, it gets confused.  The solution would really be to just check when the last time the MODULE was triggered rather than the last time the code saw it trigger.

If there is no property for this, I suppose I could write a code to track this and turn it off if it's been on for too long.  Just thinking it might be nice if I could access the last activity time like:

Modules.WithAddress("A1").UpdateTime

May 28, 2014, 07:28:56 AM
Reply #6

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I think this is a little clunky without the UpdateTime field on each module, but it does seem to work.  I suppose it could be added to the user contributions thread, but I don't know it's that useful.

May 28, 2014, 09:28:33 AM
Reply #7

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Hi Ben,

you can try:

Code: [Select]
var mySensor = Modules.WithName("My Sensor");
var currentUpdate = mySensor.Parameter("Sensor.MotionDetect").UpdateTime;
var previousUpdate = mySensor.Parameter("Sensor.MotionDetect").LastUpdateTime;

these are returning a DateTime object (UTC format) you could use for the purpose.

g.

May 28, 2014, 04:44:07 PM
Reply #8

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
Yeah, that will definitely help!  Is there a way to know what the previous value was?

Code: [Select]
var mysensor = Modules.WithName("My Sensor");
var currentevent= mysensor.Parameter("Sensor.MotionDetect").Value;
var currenteventUpdate= mysensor.Parameter("Sensor.MotionDetect").UpdateTime;
var lastevent= mysensor.Parameter("Sensor.MotionDetect").LastValue;
var lasteventUpdate= mysensor.Parameter("Sensor.MotionDetect").LastUpdateTime;

If so, my Advanced Smart Lights code could be simplified, too.  I'll try tonight when I get back to my Raspi, but knowing the correct syntax would help reduce development time.

May 28, 2014, 06:34:54 PM
Reply #9

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I just searched the readme and found the entry for 0.96 alpha:

Code: [Select]
22/03/2013 0.96 alpha
...
- added UpdateTime, LastValue, LastUpdateTime and ValueIncrement to Module data class

So I've got my answer.

May 28, 2014, 06:48:59 PM
Reply #10

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Right,

you can find more insight by looking at the source code:

https://github.com/genielabs/HomeGenie/blob/master/HomeGenie/Data/ModuleParameter.cs

Cheers,
g.

May 28, 2014, 06:51:31 PM
Reply #11

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
That's exactly what I'm doing now.  Thanks!

May 29, 2014, 03:55:19 AM
Reply #12

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
Where in the code are the parameter types/values defined?  In other words, what parameters does the device type switch have?  I know the sensors have "sensor.MotionDetect" and "sensor.Level", but I'm not sure what Switches, Lights, Dimmers, etc. have.

May 30, 2014, 04:30:48 AM
Reply #13

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
In lieu of a response, I searched the code and found a file that contained a set of parameters that I think indicates that switch, light, dimmer, etc all use "status.level".  This worked for switch as expected.

I did run into an issue using LastValue with a C# defined parameter.  I can use the LastValue for HG coded parameters but it appears that they don't work for user code parameters.  Is that correct, or am I somehow using it wrong (it should work)?

May 30, 2014, 04:54:46 AM
Reply #14

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I think I need help understanding some code in ModuleParameter.cs.

Code: [Select]
        public string Value
        {
            get
            {
                return parameterValue;
            }
            set
            {
                //TODO: find a better solution for "Meter.Watts" case
                //if (_value != value || Name == Properties.METER_WATTS || Name.StartsWith("ZWaveNode."))
                {
                    if ((!string.IsNullOrEmpty(parameterValue) && parameterValue != value)) // || Name == Properties.METER_WATTS || Name.StartsWith("ZWaveNode."))
                    {
                        LastValue = parameterValue;
                        LastUpdateTime = UpdateTime.ToUniversalTime();
                    }
                    UpdateTime = DateTime.UtcNow;
                    parameterValue = value;
                    //
                    // can we add this value for statistics?
                    double v;
                    if (value != "" && StatisticsLogger.IsValidField(this.Name) && double.TryParse(value.Replace(",", "."), System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.CultureInfo.InvariantCulture, out v))
                    {
                        Statistics.AddValue(v, this.UpdateTime);
                    }
                }
            }
        }

Line 74 looks like it will only allow Value to be updated if the new value is different than the last value.  However, this is a problem for me.  I need to watch for a single or double tap of a switch.  In order to do this, I need to know what the current and last values of the switch are.  I have code that looks for a double tap (ON + ON or Off + OFF) in order to act.  The way it's currently coded, it looks like I cannot detect a double tap of the switch.

I could change the code to eliminate this, but I'm not sure if that would break something else.  Could you help understand why HG won't let a double sending of the current value?  The only thing I can think of is that this is in an effort to keep RF commands from being stored as a LastValue since they are most likely repeated when sent.