HomeGenie Forum

Automation Program Plugins and Wizard Scripting => Help => Topic started by: [email protected] on November 01, 2016, 04:18:44 PM

Title: HG interface --> widget
Post by: [email protected] on November 01, 2016, 04:18:44 PM
I currently have an enum in my code which maps states to the value I expect..

For example

0 = Off
1 = On
2 = Turning On
3 = Turning Off.

Should I store these values in status .level, and then how do I map the enum structure back to text in a widget..

IE do i just do:

if x == 0 then "Label text Off"
if x == 1 then "Label text On"
if x == 2 then "Label text turning on"

More to the point, any examples?
Title: Re: HG interface --> widget
Post by: mvdarend on November 02, 2016, 10:59:56 AM
But enums would be nice in HG, not sure why they're not supported.

I prefer using a switch if there is more than two or three options, ie:

Code: [Select]
switch(x){
  case  0:
    "Label text Off"
    break;
  case  1:
    "Label text On"
    break;
  case  2:
    "Label text turning on"
    break;
  default:
    "Label text unknown value"
    break;
}

The syntax is the same for C# and Javascript.
Title: Re: HG interface --> widget
Post by: [email protected] on November 02, 2016, 11:14:48 AM
thanks, yeah I know about switch, it was just a pseudo example :) enums aren't officially supported but I do wonder if they could be by moving some of the code from the appfactory.cs code into the code editor window so you can see the anonymous methods.. keep meaning to do a fork and play, that would potentially let you do includes too..

The enum I don't need in this instance, just wonder where I should be storing these values and if there are any example widgets?

IE if is for an alarm area, I have two areas's for example, 0 and 1 named house and garage.

I add these currently then the status could be:

armed
arming
part armed
unarmed

and I want to represent these states via a widget, just really need one I can look at to understand :)
Title: Re: HG interface --> widget
Post by: mvdarend on November 02, 2016, 11:30:49 AM
Ah OK, I think I've got it now.

If you use the Status Widget to test with you can send the values as StatusWidget.House = 0 and StatusWidget.Garage = 1 for example.

The values should show up directly in the widget.

If you then modify the widget slightly in the widget editor (here is the GitHub source code as an example (https://github.com/genielabs/HomeGenie/blob/master/BaseFiles/Common/html/pages/control/widgets/homegenie/generic/status.js)) at line 27 to something like this.

replace
Code: [Select]
var displayvalue = value;
with your version of this:
Code: [Select]
switch(value){
case 0:
  displayvalue = "Armed"
  break;
case 1:
  displayvalue = "Unarmed"
  break;
etc.
}

Untested code, but you should get the idea.

Edit: In the MySensor code you can also see how I've used the parameter list to store some custom stuff.

Title: Re: HG interface --> widget
Post by: [email protected] on November 02, 2016, 08:56:40 PM
Thanks.. that's helped me a lot!

erm how do I change the widget.. Adding the modules in the interface like this:

Code: [Select]
            for (var i = 1; i < alarm.Areas.Count; i++)
            {
                var moduleToAdd = new InterfaceModule
                {
                    Domain = this.GetDomain(),
                    Address = $"A{alarm.Areas[i].AreaNumber}",
                    Description = $"Texecom Area {alarm.Areas[i].AreaNumber}",
                    ModuleType = ModuleTypes.Sensor,
                    //CustomData = new { ZoneText = alarm.Zones[i].ZoneName }
                    CustomData = alarm.Areas[i]
                };
                interfaceModules.Add(moduleToAdd);
            }
            OnInterfaceModulesChanged(this.GetDomain());

But I don't seem to be able to change the widget when adding...
Title: Re: HG interface --> widget
Post by: [email protected] on November 02, 2016, 09:12:52 PM
Also tried as ModuleType.Generic
Title: Re: HG interface --> widget
Post by: mvdarend on November 03, 2016, 07:08:52 AM
I'm not familiar with interfaceModule as I've never created a MIG interface before, I've always added virtual modules as follows:

Code: [Select]
Program.AddVirtualModule(hgDomain, myNodeId, hgType, hgWidget);for example
Quote
Program.AddVirtualModule("HomeAutomation.MySensors", 1, "Generic", "homegenie/generic/status");

Not exactly what you're looking for, but hopefully it will point you in the right direction.

You can also change the widget by changing the Widget.DisplayModule parameter.

Title: Re: HG interface --> widget
Post by: [email protected] on November 03, 2016, 02:28:32 PM
I found some code last night in the UPNP.cs file which has this in prior to you posting this, I haven't fully tested it yet..

Really wish MIG and Homegenie were one project.. doesn't make it easy to search for things.

David
Title: Re: HG interface --> widget
Post by: [email protected] on November 03, 2016, 02:28:48 PM
Ps thanks too :)
Title: Re: HG interface --> widget
Post by: [email protected] on November 03, 2016, 06:42:22 PM
for reference:

Code: [Select]
OnInterfacePropertyChanged(this.GetDomain(), "Source Module Here", "Description Here", "Widget.DisplayModule", "homegenie/something/mywidget");