freedomotic

Data structures

If you plan to develop a plugin for Freedomotic you need to access the framework data structures.

These types of data are concerned with building automation and Freedomotic architecture:

  1. Environment topology
  2. Environment objects
  3. People
  4. Loaded plugins and extensions

Environment topology

Environment data are accessible by the static reference. It returns the Environment thing instance which gives you access to all the environment properties

Freedomotic.environment.getPojo();

Returns all the zones in the environment

Freedomotic.environment.getZones()

Zones are logical (virtual) portions of the environment. To retrieve the list of physical environment rooms use (rooms are zones too)

Freedomotic.environment.getRooms()

Environment things

The things (lights, doors, couches, ...) in the environment can be retrived in different ways.

Get a thing by its name

EnvObjectPersistence.getObject(String name)

Get the things filtering by protocol and address property

EnvObjectPersistence.getObject(String protocol, String address)

Get the list of the things linked to a specific protocol

EnvObjectPersistence.getObjectByProtocol(String protocol)

Get the list of all things in the current environment

EnvObjectPersistence.getObjects()

This is the correct import to access this method

import com.freedomotic.objects.EnvObjectPersistence;

Plugins

Get the list of loaded plugins

AddonManager.getLoadedPlugins()

it returns an ArrayList of Plugin type.

Get a plugin by name

AddonManager.getPluginByName(String name)

Remember to import com.freedomotic.plugins.AddonManager;

Get plugin configuration from manifest

You can access configuration file of a plugin in this way:

int myVar = configuration.getIntProperty("PROPERTY-NAME", 1);

The second parameter in getIntProperty is the default value to use if the PROPERTY-NAME cannot be found or cannot be converted to the proper type (int, double, string, ...)

other methods are:

boolean myVar = configuration.getBooleanProperty("PROPERTY-NAME", true);
double myVar = configuration.getDoubleProperty("PROPERTY-NAME", 1.5f);
String myVar = configuration.getStringProperty("PROPERTY-NAME", "some text");

read tuples properties from config file:

boolean myVar = tuple.getBooleanProperty(tupleIndex, "PROPERTY-NAME", true);
double myVar = tuple.getDoubleProperty(tupleIndex, "PROPERTY-NAME", 1.5f);
String myVar = tuple.getStringProperty(tupleIndex, "PROPERTY-NAME", "some text");

Get received command parameters

The onMessage method has a Command c parameter. Is possible to access the received parameters this way:

String saveItInAVariable = c.getProperty("COMMAND-PARAM-NAME");

Accessing Data Structures from Crosslanguage Plugins

This is done through a REST connection which serves this data. More info at https://github.com/freedomotic/freedomotic/wiki/Freedomotic-APIs.