The adding operation is introduced to meet cases when the underlying protocol does not support automatic detection of newly-joined devices. In such a case, an administration application can force the contact with the new devices via the Home Device Manager API to the adapter and then to the driver.
Adding a Device
To add a new home device in the system:
Construct a Map with all the properties that are required by the protocol adapter.
Retrieve the Home Device Admin service ().
Retrieve the ProtocolAdapterInfo object of the protocol of the device by invoking the getProtocolAdapterInfo method of the Home Device Admin. The method accepts one argument which is the name of the protocol (usually stored in the PROTOCOL_NAME constant of its adapter)
Finally, add the device by calling the addHomeDevice method of the Home Device Admin and passing:
The ProtocolAdapterInfo object of the protocol of the device.
The contents of the map depend on whether your protocol adapter supports the Add operation. If it supports the Add operation, the map must contain both the properties of the home device that you want to add and the properties of the associated device class objects.
Removing Devices
To remove a home device that has been previously added:
Retrieve the Home Device Admin service ().
Call the removeHomeDevice(String deviceUID) method of the Home Device Admin and pass the UID of the home device as an argument. It will return true in case the operation is successful. You can also use the removeHomeDevice(String deviceUID, int operationArguments) method, passing as arguments the device UID and an argument for the remove operation execution. The argument is a bitmask and can be one of the following:
OperationInfo.ARGUMENT_REMOVE_RESET - Indicates that the device is removed from the device registry and all its data is deleted. This argument should always be used in combination with other arguments so that supported remove operation arguments returned from ProtocolAdapterInfo implementations for a given protocol always match too.
OperationInfo.ARGUMENT_REMOVE_FORCE - Indicates the forceful removal of the home device.
OperationInfo.ARGUMENT_REMOVE_POSTPONE - Indicates that the device remove operation is postponed until the device is again available in the network.
OperationInfo.NO_ARGUMENTS - Defines that the remove operation will be executed without any arguments.
Other custom arguments supported by the Protocol Adapter.
Optionally, you can cancel the execution of a home device remove operation by using the cancelRemoveHomeDevice(String deviceUID) method of the HomeDeviceAdmin interface. If the Protocol Adapter supports this operation, the Home Device Admin will stop the remove operation of the home device with the specified UID.
If HomeDeviceSpi is not registered to the HDM, a home device can be removed by using the HomeProtocolAdapterRemover interface. The interface is called by the HomeDeviceAdmin and provides a callback to the adapter, that includes the UID. HomeProtocolAdapterRemover calls the removeHomeDevice(String deviceSpiUID)method which forces the adapter to remove the specific home device by using its UID. That way the adapters are notified when a home device is removed and may interfere e.g. it may stop the removal.