You can receive events related to the changes in the structure of the handled devices and in the state of the devices themselves.
There are currently two basic event notification types - related to changes in the available home devices and related to changes in the device class objects, i.e. in the state of a device. To receive the events through the OSGi Event Admin, you have to implement an service with the HDM event topics of interest as an registration property and with an additional event filter if necessary.
You can specify the set of properties that are added to the events generated by devices. There are three possible options for configuring the event properties set:
Minimal - Pass "true" as a value to the hdm.events.configuration.minimal system property and only the event name and value along with the device UID, status, error code and message will be added to the received device events.
Full - Use "false" as a value to the hdm.events.configuration.minimal system property and all predefined device and protocol adapter properties along with the additional ones will be added to the received events (see the description of the HDM Device Events Properties Configuration with PID mbs.hdm.core.device.events in "Configuration Properties" section in "Setup Guide").
Custom - Use the HDM Device Events Properties Configuration with PID mbs.hdm.core.device.events (see the "Configuration Properties" section in "Setup Guide") to specify which properties you want to be included in the device events you have subscribed to.
The supported topics and related event properties are conveniently available as constants in the com.prosyst.mbs.services.hdm.HomeDeviceEventConstants interface.
Getting Notified about Changes in Home Devices
Every HDM event contains all or some of the following device properties depending on your configuration (see description above) - predefined ones in the HomeDevice interface (UID, NAME, VENDOR, VERSION, TYPE, PARENT_UID, DEVICE_CLASSES, STATUS, and ADAPTER), adapter ones and custom additional ones. Some of the predefined device properties may not be present if their values are null. For example, if the source device does not have a parent, the device property PARENT_UID will not be available in the event.
Register an Event Handler service for the following topics depending on your needs (available as constants in HomeDeviceEventConstants):
TOPIC_HOME_DEVICE_ADDED - a new Home Device is added.
TOPIC_HOME_DEVICE_READDED - a Home Device that has been previously added to the system is now added again.
TOPIC_HOME_DEVICE_REMOVED - a Home Device is removed from the system.
TOPIC_HOME_DEVICE_PROPERTY_CHANGED - a Home Device property is changed.
In the handleEvent method of your Event Handler implementation, process the properties of the passed Event as follows (available as constants in HomeDeviceEventConstants):
In case you have subscribed your application to the TOPIC_HOME_DEVICE_PROPERTY_CHANGED topic, then use PROPERTY_HOME_DEVICE_PROPERTY_NAME and PROPERTY_HOME_DEVICE_PROPERTY_VALUE to detect which property has changed and to retrieve the new value.
Getting Notified about Changes in Device Class Objects
Register an Event Handler service for the following topics depending on your needs (available as constants in HomeDeviceEventConstants):
TOPIC_DEVICE_CLASS_OBJECT_ADDED - a new Device Class Object is added to the system.
TOPIC_DEVICE_CLASS_OBJECT_REMOVED - a Device Class Object is removed from the system.
TOPIC_DEVICE_CLASS_OBJECT_PROPERTY_CHANGED - a Device Class Object property is changed.
In the handleEvent method of your Event Handler implementation, process the properties of the passed Event as follows (available as constants in HomeDeviceEventConstants):
PROPERTY_DEVICE_CLASS to access the com.prosyst.mbs.hdm.DeviceClassObject that forced the event.
In case you have subscribed your application to the TOPIC_DEVICE_CLASS_OBJECT_PROPERTY_CHANGED topic, then use PROPERTY_DEVICE_CLASS_OBJECT_PROPERTY_NAME and PROPERTY_DEVICE_CLASS_OBJECT_PROPERTY_VALUE to detect which property has changed and to retrieve the new value. You can use the PROPERTY_DEVICE_CLASS_OBJECT_PROPERTY_IS_DEFAULT constant to detect whether the changed property value has been the default one. The PROPERTY_DEVICE_CLASS_OBJECT_PROPERTY_IS_PENDING event property can be used to determine whether the new value has already been applied to the Device Class Object property or the operation is still pending.
All events contain the UID of the device, under the com.prosyst.mbs.hdm.HomeDevice.UID property.