Helper Class Reference  1.4
HomeGenie - Automation Programs API
Public Member Functions | Properties | List of all members
ProgramHelper Class Reference

Program Helper class.
Class instance accessor: Program More...

Inheritance diagram for ProgramHelper:
ProgramHelperBase

Public Member Functions

void Setup (Action functionBlock)
 Execute a setup function when the program is enabled. It is meant to be used in the "Setup Code" to execute only once the instructions contained in the passed function. It is mainly used for setting program configuration fields, parameters and features. More...
 
void Run (bool willRun)
 Run the program as soon as the "Setup Code" exits. This command is meant to be used in the "Setup Code". More...
 
ProgramHelper UseWidget (string widget)
 Set the widget that will be used for displaying this program data in the UI Control page. More...
 
ProgramHelper Implements (string interfaceId, string apiUrl, object options=null)
 Register this program as implementation of the specified interface. More...
 
ProgramHelper AddOption (string field, string defaultValue, string description, string type)
 Adds a configuration option for the program. The option field will be displayed in the program options dialog using the UI widget specified by the "type" field. More...
 
ModuleParameter Option (string field)
 Gets the value of a program option field. More...
 
ProgramHelper AddFeature (string forDomains, string forModuleTypes, string parameterName, string description, string type)
 Adds a "feature" field to modules matching the specified domain/type. Feature fields are used by automation programs to create own handled module parameters. This command should only appear inside a Program.Setup delegate. More...
 
ProgramFeature Feature (string parameterName)
 Return the feature field associated to the specified module parameter. More...
 
ProgramHelper AddModule (string domain, string address, string type, string widget="", string[] implementedFeatures=null)
 Adds a new module to the system. More...
 
ProgramHelper AddModules (string domain, int startAddress, int endAddress, string type, string widget="", string[] implementedFeatures=null)
 Adds a new set of modules to the system. More...
 
ProgramHelper RemoveModule (string domain, string address)
 Remove a module from the system. More...
 
ProgramHelper Notify (string message)
 Display UI notification message using the name of the program as default title for the notification. More...
 
ProgramHelper Notify (string message, params object[] paramList)
 Display UI notification message using the name of the program as default title for the notification. More...
 
ProgramHelper Notify (string title, string message)
 Display UI notification message from current program. More...
 
ProgramHelper Notify (string title, string message, params object[] paramList)
 Display UI notification message from current program. More...
 
ProgramHelper Emit (string parameter, object value, string description="")
 Emits a new parameter value. More...
 
void GoBackground ()
 This command is usually put at the end of the "Program Code". It is the equivalent of an infinite noop loop. More...
 
ModuleParameter Parameter (string parameterName)
 Gets or sets a program parameter. More...
 
StoreHelper Store (string storeName)
 Gets or creates a persistent data Store for this program. More...
 
bool UpdateModuleDatabase ()
 Force update module database with current data. More...
 
- Public Member Functions inherited from ProgramHelperBase
ProgramHelperBase Say (string sentence, string locale=null, bool goAsync=false)
 Playbacks a synthesized voice message from speaker. More...
 
ProgramHelperBase Play (string waveUrl)
 Playbacks a wave file. More...
 
Thread RunAsyncTask (Utility.AsyncFunction functionBlock)
 Executes a function asynchronously. More...
 
void Run (string programId, string options=null)
 Executes the specified Automation Program. More...
 
ProgramHelperBase WaitFor (string programId)
 Waits for the given program to complete execution. More...
 
ProgramHelper WithAddress (int programAddress)
 Returns a reference to the ProgramHelper of a program. More...
 
ProgramHelper WithName (string programName)
 Returns a reference to the ProgramHelper of a program. More...
 

Properties

bool IsRunning [get]
 Gets a value indicating whether the program is running. More...
 
bool IsEnabled [get]
 Gets a value indicating whether the program is enabled. More...
 
Module Module [get]
 Get a reference to the Module associated to the program. More...
 
- Properties inherited from ProgramHelperBase
NLog.Logger Log [get]
 Gets the logger object. More...
 

Detailed Description

Program Helper class.
Class instance accessor: Program

Member Function Documentation

◆ Setup()

void Setup ( Action  functionBlock)

Execute a setup function when the program is enabled. It is meant to be used in the "Setup Code" to execute only once the instructions contained in the passed function. It is mainly used for setting program configuration fields, parameters and features.

Parameters
functionBlockFunction name or inline delegate.

Example:

Program.Setup(()=>
{
Program.AddOption(
"MaxLevel",
"40",
"Keep level below the following value",
"slider:10:80");
Program.AddFeature(
"Dimmer",
"EnergyManagement.EnergySavingMode",
"Energy Saving Mode enabled light",
"checkbox");
}, 0);

◆ Run()

void Run ( bool  willRun)

Run the program as soon as the "Setup Code" exits. This command is meant to be used in the "Setup Code".

Parameters
willRunIf set to true will run.

◆ UseWidget()

ProgramHelper UseWidget ( string  widget)

Set the widget that will be used for displaying this program data in the UI Control page.

Returns
ProgramHelper.
Parameters
widgetThe widget path.

◆ Implements()

ProgramHelper Implements ( string  interfaceId,
string  apiUrl,
object  options = null 
)

Register this program as implementation of the specified interface.

Returns
ProgramHelper
Parameters
interfaceIdThe string identifier of the implemented interface. (e.g. "@Statistics:Provider")
apiUrlMandatory URL of API to call to get implementation details/config
optionsOptional custom object

◆ AddOption()

ProgramHelper AddOption ( string  field,
string  defaultValue,
string  description,
string  type 
)

Adds a configuration option for the program. The option field will be displayed in the program options dialog using the UI widget specified by the "type" field.

Returns
ProgramHelper
Parameters
fieldName of this input field
defaultValueDefault value for this input field
descriptionDescription for this input field
typeThe type of this option (eg. "text", "password", "cron.text", ...). Each type can have different initialization options that are specified as ":" separated items. See html/ui/widgets folder for a list of possible types/options.

◆ Option()

ModuleParameter Option ( string  field)

Gets the value of a program option field.

Returns
The option field.
Parameters
fieldName of the option field to get.

Example:

// ....
var delay = Program.Option("OffDelay").DecimalValue;
Pause( delay );
Modules.WithFeature("Timer.TurnOffDelay").Off();

◆ AddFeature()

ProgramHelper AddFeature ( string  forDomains,
string  forModuleTypes,
string  parameterName,
string  description,
string  type 
)

Adds a "feature" field to modules matching the specified domain/type. Feature fields are used by automation programs to create own handled module parameters. This command should only appear inside a Program.Setup delegate.

Returns
ProgramHelper.
Parameters
forDomainsExpression based on module domain names, used to select what modules will be showing this feature field. This can be either a valid Regular Expression enclosed by '/' and '/' delimiters or a simple comma (or '|') separated list of domain names (prepend '!' to a name to exclude it).
forModuleTypesExpression based on module types and parameters names, used to select what modules will be showing this feature field. This must be in the format <types_expr>[:<parameters_expr>]. <types_expr> and <parameters_expr> can be either a valid Regular Expression enclosed by '/' and '/' delimiters or a simple comma (or '|') separated list of names (prepend '!' to a name to exclude it).
parameterNameName of the module parameter bound to this feature field.
descriptionDescription for this input field.
typeThe type of this feature field (eg. "text", "password", "cron.text", ...). Each type can have different initialization options that are specified as ":" separated items. See html/ui/widgets folder for a list of possible types/options.

◆ Feature()

ProgramFeature Feature ( string  parameterName)

Return the feature field associated to the specified module parameter.

Parameters
parameterNameParameter name.

◆ AddModule()

ProgramHelper AddModule ( string  domain,
string  address,
string  type,
string  widget = "",
string[]  implementedFeatures = null 
)

Adds a new module to the system.

Returns
ProgramHelper.
Parameters
domainDomain.
addressAddress.
typeType (Generic, Program, Switch, Light, Dimmer, Sensor, Temperature, Siren, Fan, Thermostat, Shutter, DoorWindow, MediaTransmitter, MediaReceiver).
widgetWidget to display this modules with.
implementedFeaturesAllow only features explicitly declared in this list

◆ AddModules()

ProgramHelper AddModules ( string  domain,
int  startAddress,
int  endAddress,
string  type,
string  widget = "",
string[]  implementedFeatures = null 
)

Adds a new set of modules to the system.

Returns
ProgramHelper.
Parameters
domainDomain.
startAddressStart address (numeric).
endAddressEnd address (numeric).
typeType (Generic, Program, Switch, Light, Dimmer, Sensor, Temperature, Siren, Fan, Thermostat, Shutter, DoorWindow, MediaTransmitter, MediaReceiver).
widgetWidget to display these modules with.
implementedFeaturesAllow only features explicitly declared in this list

◆ RemoveModule()

ProgramHelper RemoveModule ( string  domain,
string  address 
)

Remove a module from the system.

Returns
ProgramHelper.
Parameters
domainDomain.
addressAddress.

◆ Notify() [1/4]

ProgramHelper Notify ( string  message)

Display UI notification message using the name of the program as default title for the notification.

Parameters
messageMessage.

Example:

Program.Notify("Hello world!");

◆ Notify() [2/4]

ProgramHelper Notify ( string  message,
params object[]  paramList 
)

Display UI notification message using the name of the program as default title for the notification.

Parameters
messageFormatted message.
paramListFormat parameter list.

Example:

Program.Notify("Hello world!");

◆ Notify() [3/4]

ProgramHelper Notify ( string  title,
string  message 
)

Display UI notification message from current program.

Parameters
titleTitle.
messageMessage.

Example:

Program.Notify("Test Program", "Hello world!");

◆ Notify() [4/4]

ProgramHelper Notify ( string  title,
string  message,
params object[]  paramList 
)

Display UI notification message from current program.

Parameters
titleTitle.
messageFormatted message.
paramListFormat parameter list.

◆ Emit()

ProgramHelper Emit ( string  parameter,
object  value,
string  description = "" 
)

Emits a new parameter value.

Returns
ProgramHelper.
Parameters
parameterParameter name.
valueThe new parameter value to set.
descriptionEvent description. (optional)

◆ GoBackground()

void GoBackground ( )

This command is usually put at the end of the "Program Code". It is the equivalent of an infinite noop loop.

◆ Parameter()

ModuleParameter Parameter ( string  parameterName)

Gets or sets a program parameter.

Parameters
parameterNameParameter name.

Example:

// sets an example program parameter
Program.Parameter("MyProgram.ExampleParameter").Value = "Just testing...";
// read "Sensor.Temperature" parameter of the program named "DHT-11"
if (Program.WithName("DHT-11").Parameter("Sensor.Temperature").DecimalValue < 20
&& Modules.WithName("Heater").IsOff)
{
Modules.WithName("Heater").On();
}

◆ Store()

StoreHelper Store ( string  storeName)

Gets or creates a persistent data Store for this program.

Parameters
storeNameStore name.

◆ UpdateModuleDatabase()

bool UpdateModuleDatabase ( )

Force update module database with current data.

Property Documentation

◆ IsRunning

bool IsRunning
get

Gets a value indicating whether the program is running.

true if this program is running; otherwise, false.

◆ IsEnabled

bool IsEnabled
get

Gets a value indicating whether the program is enabled.

true if this program is enabled; otherwise, false.

◆ Module

Get a reference to the Module associated to the program.

Module object associated to the program.


The documentation for this class was generated from the following file: