more G-Labs products

Author Topic: Is there an Example of using Program Store / Get / Remove / List / Reset  (Read 1612 times)

January 19, 2016, 02:02:26 AM
Read 1612 times

HGexperimenter

  • **
  • Information
  • Jr. Member
  • Posts: 42
Is there an example using Program.Store / Get / List / Reset?

I want to be able to save some data and have it preserved in case of re-boot and an example using these functions would go a long way to helping understand how it is used.

Also with the Program Store List, is there an example to List all the Stored data (such as a wildcard List).

Thanks
Link to Helper: http://genielabs.github.io/HomeGenie/api/ape/a00014.html

Hi - Been a few days  and a few have viewed this - any help would be great with an example of Program.Store() - thanks!
« Last Edit: January 22, 2016, 01:09:40 PM by HGexperimenter »

January 24, 2016, 04:36:51 PM
Reply #1

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I assume that you would use it like a normal parameter.

Code: [Select]
Program.Store("test1").Value = 1;
Program.Store("test1").Remove;

I haven't tried it, so you'd have to test to verify syntax.

January 25, 2016, 11:41:40 PM
Reply #2

HGexperimenter

  • **
  • Information
  • Jr. Member
  • Posts: 42
Thanks for the suggestion.  That's what I thought...

It doesn't work:
Program.Store("test1").Value = 1;

Error: "The left-hand side of an assignment must be a variable, a property or an indexer"

I tried lots of variations - no luck.



January 26, 2016, 12:42:05 AM
Reply #3

louis

  • **
  • Information
  • Jr. Member
  • Posts: 26
Hi,

I tried something on an existing Sensor I had.. this seems to work

Program.Store("HomeAutomation.MyPVMonitor").Get("PVLoad").Value = "12";
var a = Program.Store("HomeAutomation.MyPVMonitor").Get("PVLoad").Value;

Program.Notify("test", a.ToString());

This at least displays the 12 :)

The sensor and parameter used are defined in another program (C#):
Startup Code:
Program.AddVirtualModule("HomeAutomation.MyPVMonitor", "1", "Sensor", "homegenie/generic/mypvmonitor");
Program Code
var myPVMonitor = Modules.InDomain("HomeAutomation.MyPVMonitor").WithAddress("1").Get();
var pvLoad = myPVMonitor.Parameter("MyPVMonitor.PVLoad");

I hope this helps you in the right direction ...

January 26, 2016, 02:27:22 AM
Reply #4

HGexperimenter

  • **
  • Information
  • Jr. Member
  • Posts: 42
louis: Thank you!  This works!  (I see the "Get" is needed to create and save a store variable - would be nice to have a "Put"!)

It also only takes Strings (I think).

Here is a test program I created - it also lists the values in the particular Program Store and then resets it all at the end.  I don't know if there is a way to get all the Program Store names though...

Code: [Select]
string storeName = "testStore"; // This is the name of a Program Store
// Test: Create a store and save a string value
Program.Store(storeName).Get("saveStore").Value = "1234.5";
var getIt = Program.Store(storeName).Get("saveStore").Value;
Program.Notify("Program Store", "GetIt: "+getIt.ToString());
Program.Store(storeName).Get("saveStore2").Value = "4567.8";
// Dump Program Store list
var list = Program.Store(storeName).List;
var count = list.Count;
Program.Notify("Program Store", "List size: "+count.ToString());
foreach (var storeItem in list) {
  Program.Notify("Program Store", "Name:"+storeItem.Name.ToString()+" Value:"+storeItem.Value.ToString());
}

// Reset the store: removes all stored names and data
Program.Store(storeName).Reset();

Hope this helops others too :)

January 26, 2016, 07:52:39 PM
Reply #5

HGexperimenter

  • **
  • Information
  • Jr. Member
  • Posts: 42
Addendum question:  Where is the data stored?
I checked homegenie_stats.db - not there.

Some sort of C# list:
Trace to:
store.cs:
public TsList<ModuleParameter> Data;

and:
utility.cs 
public class TsList<T> : System.Collections.Generic.List<T>
... but not sure if it is written to disk...
« Last Edit: January 26, 2016, 07:54:54 PM by HGexperimenter »

January 26, 2016, 11:37:17 PM
Reply #6

louis

  • **
  • Information
  • Jr. Member
  • Posts: 26
I'm not sure, but you might check modules.xml, this is where, I believe, parameter values are stored.
As it looks like the store is using some kind of parameter stuff ...

Good luck :)

Louis

January 27, 2016, 02:25:01 AM
Reply #7

HGexperimenter

  • **
  • Information
  • Jr. Member
  • Posts: 42
Yes - gets saved there after some time..  Not right away.  Might be a scheduled update of some sort.

February 18, 2016, 02:39:57 PM
Reply #8

accident

  • *
  • Information
  • Newbie
  • Posts: 2
I'd love to know when/how often that data gets stored, or if there is a way to trigger it.  I have some thermostat scheduling stuff that needs to be stored in case of a power loss, and I can't seem to get the data store to be persistent.  Anybody have any idea on how that works?