One of the main characteristics of the Device and Device Item functional properties is the way these properties can be accessed. On this page we will describe some specifics concerning functional properties with readable access. The Device Access module stores the last known values of all readable properties in its internal cache.
Initially when the Device with its Device Items is created, then the Device Access read initially from the protocol adapter the values of the properties and cached them (by invoking the getter method of the properties). The getter method return after the property is read from the physical device. When an application make an attempt to retrieve the value of a specific property, the Device Access will return the property value from the internal cache. This internal cache is needed to make invocation of the getters method faster then sending network requests to the physical device every time.
The Device Access sends event through OSGi Event Admin service:
Property Cached Value
The cached property value is updated in the following situations:
When the physical device sends network notification to the gateway that the device property value is changed, the protocol adapter notifies the Device Access for the new property value and the Device Access will send OSGi event that the property is changed. For example the physical device send this notification when the user press any button on device and this action change the device property - turn on or turn off a switch. The other example is when the device itself change property - temperature sensor. Additionally the protocol adapter is possible to force sending events. In this situation the Device Access will send event no matter if the property value is equal or not to the cached value. For example a motion detector detects many motions in a short time and every motion has to be send as event to applications.
The protocol adapter is able to force device refresh or refresh specific property. In this situation the internal cache should be updated.
It is possible the physical device to not support property change notification, i.e. the device does not send notification over the network when some of its properties are changed. Then the device should be asked periodically to give its property value. For this reason the protocol adapter uses the polling mechanism provided by Device Access. Each protocol adapter has a minimal polling interval which can be retrieved from the ProtocolAdapterInfo object, using ProtocolAdapterInfo.getMinimalPollingInterval() method. This method should return the minimal polling interval in milliseconds or "0" if the protocol adapter does not support the polling mechanism. The minimal polling interval is used as a prevention to avoid overloading the network.
The protocol adapter also supports a default polling interval specific for concrete device property –HomeDeviceSpi.getDefaultPollingInterval(byte), or concrete device item property – DeviceClassObjectSpi.getDefaultPollingInterval(String). The default polling interval is used to initialize the polling mechanism for device/device item property. To indicate that the polling mechanism should not be started for a property, the protocol adapter should return a default polling interval 0. For example the protocol adapter is specified with minimal polling interval of 2 seconds and 0 as a default polling interval for specific device item property. This is useful when the property has access "R", i.e. the property is not eventable and it has one and the same value every time.