Connection suspension and resuming
When looking at the initial connection process, the data syncronization is straight forward. But to develop an fully functional remote device, some other scenarios must be considered. When the connection state changes to connected state, this does not automatically mean that this is an initial connection process. When the user connects to the device and does not quit the conncetion by navigating back to the main page, instead exits the app (by going to the home screen or switching to another app), the connection is suspended. That means the properties remain loaded and the property states remain the same. Now, when the user turns back to the app the connection is resumed.
If a connection is resumed, there is the possibility that the properties or it's states have changed in the meantime while the connection was offline. When this is the case, the appropriate steps to update the changed elements must be taken.
How it works
When the connection state changes to disconnected state, a determination of the reason is not possible (quitted/suspended). But when the connection is resumed, the app sends a notification to the remote device. This notification is reported through the onDeviceConnectionRestored method of the ILaroomyAppCallback interface.
There are different approaches to update the dataset to achieve a correct device-app state alignment.
The most efficient way: While the device is in disconnected state, monitor all changes that occur in that time. When the callback reports a resumed connection, send single updates for all changes. When the callback reports a property-loading-complete operation, the collected data can be deleted, since this was an initial loading process.
The overkill: When the resumed connection is reported, trigger a complete property-reload process by calling the sendPropertyReloadCommand method of the LaRoomy Api. This shouldn't be done, because it is a bad experience for the user, but sometimes it is the last resort.
The middle way: Trigger a property-state-update by calling the sendRefreshAllStatesCommand method of the LaRoomy Api. This will be executed in the background, so the user is rarely bothered.
The middle way is executed automatically when the app reports a resumed connection. This is an internal feature of the LaRoomy Api and must be explicitly disabled by calling the enableAutoRefreshStates method of the LaRoomy Api and set the parameter to false.
// disable automatic state refresh function
LaRoomyApi .enableAutoRefreshStates(false);