more G-Labs products

Author Topic: Stupid question.. getting all modules and status?  (Read 1519 times)

December 16, 2015, 10:43:22 PM
Read 1519 times

[email protected]

  • *****
  • Information
  • Hero Member
  • Posts: 271
I'm obviously doing something stupid..

I've extracted a snippet.. basically I want to get all modules, and then the status... I've tried:

Code: [Select]
{
  var modules = Modules.OfDeviceType("Light,Dimmer,Switch").SelectedModules;
  Program.Notify("",module.Address);
  Program.Notify("",module.Parameter("Status.Level").Statistics.History[0].Value);
}

and

Code: [Select]
for(int i = 0; i < modules.Count; i++)
{
 var module = modules[i];
  Program.Notify("",module.Address);
  Program.Notify("",module.Parameter("Status.Level").Statistics.History[0].Value);
}

Thanks

December 17, 2015, 04:26:51 PM
Reply #1

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I would try using the same format as what's used in a lot of WhenModuleChanging code to toggle through all modules.  As for your snippet, I don't see why you are using the history[0] element since that's the same as the current value.
Code: [Select]
module.Parameter("Status.Level").Statistics.History[0].Valueshould evaluate the same as
Code: [Select]
module.Parameter("Status.Level").Value

December 18, 2015, 04:14:25 PM
Reply #2

[email protected]

  • *****
  • Information
  • Hero Member
  • Posts: 271
Bit of a bad copy and paste error, I was trying all options and I was at the end of my....

doesn't the module changing pass the parameters as a seperate object?

I'm using the exact same code as a web method that does work, so dont know why I see the errors..

December 18, 2015, 05:06:33 PM
Reply #3

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
AFAIK, when you use the WhenModuleChanging function, it passes 2 objects (module, parameter).  And WhenModuleChanging can be triggered by more than one module at a time, so it's possible that you could need to parse more than one module (I suspect this would most likely occur when one triggers and another triggers before the first loop was finished.

The first object is a reference to the module which gives you access to everything connected to that module.  The second object is the parameter that changed IIRC.  I believe it would be something like
Code: [Select]
parameter.Name = "Status.Level"
parameter.Value = 1
for a module turning on but I could be remembering incorrectly.  Just look at one of the functions in any code (or the documentation) to see what the parameter value is being checked against.

December 18, 2015, 08:04:29 PM
Reply #4

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
You can use ModulesManager Each to iterate through all modules, eg.:

Code: [Select]
Modules.OfDeviceType("Light,Dimmer,Switch").Each( (module) => {
  Program.Notify(module.Instance.Name, module.Parameter("Status.Level").Value);
  Pause(1);
  return false;
});

December 20, 2015, 03:40:35 PM
Reply #5

[email protected]

  • *****
  • Information
  • Hero Member
  • Posts: 271