[hdpowerview] Update positions after triggering scene/scene group (#11768)

* Update positions after triggering scene/scene group.
* Compare enum values directly with ==
* Fix re-entrant calls.

Fixes #11697

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
jlaur 2021-12-20 20:32:48 +01:00 committed by GitHub
parent b2dd13efbb
commit 817de38683
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 9 deletions

View File

@ -237,7 +237,6 @@ public class HDPowerViewWebTargets {
* @param query the http query parameter
* @param jsonCommand the request command content (as a json string)
* @return the response content (as a json string)
* @throws HubProcessingException
* @throws HubMaintenanceException
* @throws HubProcessingException
*/

View File

@ -72,11 +72,13 @@ import com.google.gson.JsonParseException;
*
* @author Andy Lintner - Initial contribution
* @author Andrew Fiddian-Green - Added support for secondary rail positions
* @author Jacob Laursen - Add support for scene groups and automations
* @author Jacob Laursen - Added support for scene groups and automations
*/
@NonNullByDefault
public class HDPowerViewHubHandler extends BaseBridgeHandler {
private static final long INITIAL_SOFT_POLL_DELAY_MS = 5_000;
private final Logger logger = LoggerFactory.getLogger(HDPowerViewHubHandler.class);
private final HttpClient httpClient;
private final HDPowerViewTranslationProvider translationProvider;
@ -113,7 +115,7 @@ public class HDPowerViewHubHandler extends BaseBridgeHandler {
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
if (RefreshType.REFRESH.equals(command)) {
if (RefreshType.REFRESH == command) {
requestRefreshShadePositions();
return;
}
@ -129,12 +131,16 @@ public class HDPowerViewHubHandler extends BaseBridgeHandler {
throw new ProcessingException("Web targets not initialized");
}
int id = Integer.parseInt(channelUID.getIdWithoutGroup());
if (sceneChannelTypeUID.equals(channel.getChannelTypeUID()) && OnOffType.ON.equals(command)) {
if (sceneChannelTypeUID.equals(channel.getChannelTypeUID()) && OnOffType.ON == command) {
webTargets.activateScene(id);
} else if (sceneGroupChannelTypeUID.equals(channel.getChannelTypeUID()) && OnOffType.ON.equals(command)) {
// Reschedule soft poll for immediate shade position update.
scheduleSoftPoll(0);
} else if (sceneGroupChannelTypeUID.equals(channel.getChannelTypeUID()) && OnOffType.ON == command) {
webTargets.activateSceneCollection(id);
// Reschedule soft poll for immediate shade position update.
scheduleSoftPoll(0);
} else if (automationChannelTypeUID.equals(channel.getChannelTypeUID())) {
webTargets.enableScheduledEvent(id, OnOffType.ON.equals(command));
webTargets.enableScheduledEvent(id, OnOffType.ON == command);
}
} catch (HubMaintenanceException e) {
// exceptions are logged in HDPowerViewWebTargets
@ -189,14 +195,22 @@ public class HDPowerViewHubHandler extends BaseBridgeHandler {
}
private void schedulePoll() {
scheduleSoftPoll(INITIAL_SOFT_POLL_DELAY_MS);
scheduleHardPoll();
}
private void scheduleSoftPoll(long initialDelay) {
ScheduledFuture<?> future = this.pollFuture;
if (future != null) {
future.cancel(false);
}
logger.debug("Scheduling poll for 5000ms out, then every {}ms", refreshInterval);
this.pollFuture = scheduler.scheduleWithFixedDelay(this::poll, 5000, refreshInterval, TimeUnit.MILLISECONDS);
logger.debug("Scheduling poll for {} ms out, then every {} ms", initialDelay, refreshInterval);
this.pollFuture = scheduler.scheduleWithFixedDelay(this::poll, initialDelay, refreshInterval,
TimeUnit.MILLISECONDS);
}
future = this.hardRefreshPositionFuture;
private void scheduleHardPoll() {
ScheduledFuture<?> future = this.hardRefreshPositionFuture;
if (future != null) {
future.cancel(false);
}