[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:
@@ -237,7 +237,6 @@ public class HDPowerViewWebTargets {
|
|||||||
* @param query the http query parameter
|
* @param query the http query parameter
|
||||||
* @param jsonCommand the request command content (as a json string)
|
* @param jsonCommand the request command content (as a json string)
|
||||||
* @return the response content (as a json string)
|
* @return the response content (as a json string)
|
||||||
* @throws HubProcessingException
|
|
||||||
* @throws HubMaintenanceException
|
* @throws HubMaintenanceException
|
||||||
* @throws HubProcessingException
|
* @throws HubProcessingException
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -72,11 +72,13 @@ import com.google.gson.JsonParseException;
|
|||||||
*
|
*
|
||||||
* @author Andy Lintner - Initial contribution
|
* @author Andy Lintner - Initial contribution
|
||||||
* @author Andrew Fiddian-Green - Added support for secondary rail positions
|
* @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
|
@NonNullByDefault
|
||||||
public class HDPowerViewHubHandler extends BaseBridgeHandler {
|
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 Logger logger = LoggerFactory.getLogger(HDPowerViewHubHandler.class);
|
||||||
private final HttpClient httpClient;
|
private final HttpClient httpClient;
|
||||||
private final HDPowerViewTranslationProvider translationProvider;
|
private final HDPowerViewTranslationProvider translationProvider;
|
||||||
@@ -113,7 +115,7 @@ public class HDPowerViewHubHandler extends BaseBridgeHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleCommand(ChannelUID channelUID, Command command) {
|
public void handleCommand(ChannelUID channelUID, Command command) {
|
||||||
if (RefreshType.REFRESH.equals(command)) {
|
if (RefreshType.REFRESH == command) {
|
||||||
requestRefreshShadePositions();
|
requestRefreshShadePositions();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -129,12 +131,16 @@ public class HDPowerViewHubHandler extends BaseBridgeHandler {
|
|||||||
throw new ProcessingException("Web targets not initialized");
|
throw new ProcessingException("Web targets not initialized");
|
||||||
}
|
}
|
||||||
int id = Integer.parseInt(channelUID.getIdWithoutGroup());
|
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);
|
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);
|
webTargets.activateSceneCollection(id);
|
||||||
|
// Reschedule soft poll for immediate shade position update.
|
||||||
|
scheduleSoftPoll(0);
|
||||||
} else if (automationChannelTypeUID.equals(channel.getChannelTypeUID())) {
|
} else if (automationChannelTypeUID.equals(channel.getChannelTypeUID())) {
|
||||||
webTargets.enableScheduledEvent(id, OnOffType.ON.equals(command));
|
webTargets.enableScheduledEvent(id, OnOffType.ON == command);
|
||||||
}
|
}
|
||||||
} catch (HubMaintenanceException e) {
|
} catch (HubMaintenanceException e) {
|
||||||
// exceptions are logged in HDPowerViewWebTargets
|
// exceptions are logged in HDPowerViewWebTargets
|
||||||
@@ -189,14 +195,22 @@ public class HDPowerViewHubHandler extends BaseBridgeHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void schedulePoll() {
|
private void schedulePoll() {
|
||||||
|
scheduleSoftPoll(INITIAL_SOFT_POLL_DELAY_MS);
|
||||||
|
scheduleHardPoll();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void scheduleSoftPoll(long initialDelay) {
|
||||||
ScheduledFuture<?> future = this.pollFuture;
|
ScheduledFuture<?> future = this.pollFuture;
|
||||||
if (future != null) {
|
if (future != null) {
|
||||||
future.cancel(false);
|
future.cancel(false);
|
||||||
}
|
}
|
||||||
logger.debug("Scheduling poll for 5000ms out, then every {}ms", refreshInterval);
|
logger.debug("Scheduling poll for {} ms out, then every {} ms", initialDelay, refreshInterval);
|
||||||
this.pollFuture = scheduler.scheduleWithFixedDelay(this::poll, 5000, refreshInterval, TimeUnit.MILLISECONDS);
|
this.pollFuture = scheduler.scheduleWithFixedDelay(this::poll, initialDelay, refreshInterval,
|
||||||
|
TimeUnit.MILLISECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
future = this.hardRefreshPositionFuture;
|
private void scheduleHardPoll() {
|
||||||
|
ScheduledFuture<?> future = this.hardRefreshPositionFuture;
|
||||||
if (future != null) {
|
if (future != null) {
|
||||||
future.cancel(false);
|
future.cancel(false);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user