Skip to content

Commit

Permalink
[hdpowerview] Update positions after triggering scene/scene group (op…
Browse files Browse the repository at this point in the history
…enhab#11768)

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

Fixes openhab#11697

Signed-off-by: Jacob Laursen <[email protected]>
Signed-off-by: Michael Schmidt <[email protected]>
  • Loading branch information
jlaur authored and mischmidt83 committed Jan 9, 2022
1 parent 5dee96c commit 86f893e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ public void enableScheduledEvent(int scheduledEventId, boolean enable)
* @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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,13 @@
*
* @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;
Expand Down Expand Up @@ -113,7 +115,7 @@ public HDPowerViewHubHandler(Bridge bridge, HttpClient httpClient,

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
if (RefreshType.REFRESH.equals(command)) {
if (RefreshType.REFRESH == command) {
requestRefreshShadePositions();
return;
}
Expand All @@ -129,12 +131,16 @@ public void handleCommand(ChannelUID channelUID, Command command) {
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
Expand Down Expand Up @@ -189,14 +195,22 @@ public void dispose() {
}

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);
}
Expand Down

0 comments on commit 86f893e

Please sign in to comment.