Previous Topic

Next Topic

Book Contents

Book Index

Managing Zones (deprecated)

Create a zone by specifying the devices that should be added to it and then retrieve it in order to use it.

Creating a Zone

To create a new zone:

  1. Retrieve the Home Zone Admin service (com.prosyst.mbs.services.hdm.zones.HomeZoneAdmin). If you are accessing the Home Device Manager via the JSON Remote API use the functions from the HZAdmin group.
  2. Put the following configuration properties of a zone in a Map (or in a Plain Object if you are using the  JSON Remote API ):
  3. Call the addHomeZone method of the HomeZoneAdmin interface (or HZAdmin/addHomeZone if you are using the JSON Remote API ) and pass the configuration properties of the zone along with a zone UID (optional).

The method returns a new com.prosyst.mbs.services.hdm.zones.HomeZone object. If you pass as an argument the UID of an existing home zone the method will result in setting the configuration properties as attributes of the zone.

The following Java code snippet creates a zone and adds two Home Device objects stored in the mydevice and myotherdevice variables to it.

    //Retrieve the Zone Admin service

  ServiceReference zoneref = bc.getServiceReference(HomeZoneAdmin.class.getName());

  HomeZoneAdmin zoneadmin = (HomeZoneAdmin)bc.getService(zoneref);

    //Construct an array of the devices' UID-s.  

  String[] uids = new String[] { mydevice.getUID(), myotherdevice.getUID() };

    //Construct the zone properties map.    

  HashMap zonemap = new HashMap();

  zonemap.put(HomeZone.TYPE,"test");

  zonemap.put(HomeZone.DEVICES, uids);

    //Create the zone  

  zoneadmin.addHomeZone("myzone", zonemap);

The following JavaScript code snippet creates remotely a zone and adds two Home Device objects to it.

   //Construct an array of the devices' UID-s

  uids = [mydevice.UID, myotherdevice.UID]

    //Construct the zone properties object.    

  zonemap = new Object();

  zonemap.type ="test"

  zonemap.devices = uids;

    //Create the zone.    

  var xhr = new XMLHttpRequest();

  xhr.open("POST", "/remote/json-rpc", false);

  xhr.send('{"jsonrpc": "2.0", "method": "HZAdmin/addHomeZone", "params": ["myzone", '+JSON.stringify(zonemap)+'], "id": 1}')

Retrieving a Zone

To retrieve a zone:

  1. Retrieve the Home Zone Admin service and do one of the following:

The following Java code snippet retrieves all zones of type "test".

HomeZone[] myzones = zoneadmin.getHomeZones("("+HomeZone.TYPE+"=test)");

The following JavaScript code snippet retrieves remotely all zones of type "test".

  xhr.open("POST", "/remote/json-rpc", false);

  xhr.setRequestHeader("Content-Type","application/json")

  xhr.send('{"jsonrpc": "2.0", "method": "HZAccess/getHomeZones", "params": "(type=test)", "id": 1}')0

  myzones = JSON.parse(xhr.responseText).result

Grouping Zones

Zones can be grouped hierarchically and thus a parent-child relationship between them can be formed.

You can group several zones into one and thus provide some specific logic and functionality. For example, "small" home zones like "Light on the First Floor", "Lights in the Garage" and "Lights on the Second Floor" can be child zones of the "bigger" home zone - "Lights in the House".

System Zone

You always have one system zone (HomeZoneAdmin.SYSTEM_HOME_ZONE) which cannot be removed. It contains all devices that don't belong to any other zone. When a device is added to a zone, it is removed from the system zone.

Manipulating Devices in a Zone

The zone model allows you to easily launch common device actions directly from a zone. Depending on the requirements you have passed, the Home Device Manager will launch the execution on all devices or devices with certain functionality and capabilities.

Executing an Operation on a Device Class Object

Operations provide direct approach to initiating an action on the DCO of a device in accordance with the implemented device class interface. For convenience, you can start such actions over a whole zone.

To execute an operation on all Device Class Objects of a certain type, that belong to a certain zone:

  1. Retrieve the zone.
  2. Invoke the invokeDCOOperation method (or HZAccess/invokeDCOOperation ) by passing the following input arguments:

The operation will be executed on all devices that are in the zone, either one by one or natively if their protocol supports it.

Changing a Property of a Device Class Object

To change the properties of all Device Class Objects of a certain type, that belong to a certain zone:

  1. Retrieve the zone.
  2. Invoke the setDCOProperty method (or HZAccess/setDCOProperty) by passing:

The property value of all devices that are in the zone will be changed either one by one or natively if their protocol supports it.

Subscribing to Zone Events

You can be notified when zones are added and removed or when new devices are added to or removed from them.

To receive events related to zones, implement an event handler and subscribe to the topics you are interested in.

You can configure the set of properties that are included in the events generated by zones. There are three possible options for configuring the event properties set:

The events related to home zones are provided as constants of the com.prosyst.mbs.services.hdm.HomeZoneEventConstants interface.

You can receive events by subscribing to specific event topics via OSGi Event Handler or via JSON-RPC or Web Socket.