I want to use this lamp dimmable module into HG.
I've made a program like the following?
Program.AddVirtualModule("HomeAutomation.Marmitek", "A1", "Dimmer", "homegenie/generic/dimmer");
var myModules = Modules.InDomain("HomeAutomation.Marmitek");
// handle standard API calls
When.WebServiceCallReceived("HomeAutomation.Marmitek", ( args ) => {
string[] reqs = ((string)args).Split('/');
try
{
string lightnumber= reqs[1];
string command= reqs[2];
string parameter= ""; if (reqs.Length > 3) parameter = Uri.UnescapeDataString(reqs[3]);
var module= myModules.WithAddress(lightnumber).Get();
var dim_level= module.Parameter("Status.Level").DecimalValue;
switch(command) {
case "Control.On":
module.On();
break;
case "Control.Off":
module.Off();
break;
case "Control.Toggle":
if (dim_level == 0) {
module.On();
}
else {
module.Off();
}
break;
case "Control.Level":
module.Level= dim_level;
break;
}
//
return "{ 'ResponseValue' : 'OK' }";
} catch (Exception e) {
Program.Notify("My Light ERROR!", e.Message);
}
return "{ 'ResponseValue' : 'ERROR' }";
});
Is this correct?