diff --git a/bundles/org.openhab.binding.orbitbhyve/README.md b/bundles/org.openhab.binding.orbitbhyve/README.md index 337c8b1494cab..9d0d8874070ac 100644 --- a/bundles/org.openhab.binding.orbitbhyve/README.md +++ b/bundles/org.openhab.binding.orbitbhyve/README.md @@ -33,7 +33,7 @@ Beside the dynamic channels each sprinkler thing provides these standard channel |----------------|-------------|--------------------------------------------------------------------| | mode | String | This channel represents the mode of sprinkler device (auto/manual) | | next_start | DateTime | This channel represents the start time of the next watering | -| rain_delay | Number | This channel manages the current rain delay in hours | +| rain_delay | Number:Time | This channel manages the current rain delay in hours | | watering_time | Number:Time | This channel manages the manual zone watering time in minutes | | control | Switch | This channel controls the sprinkler (ON/OFF) | | smart_watering | Switch | This channel controls the smart watering (ON/OFF) | diff --git a/bundles/org.openhab.binding.orbitbhyve/src/main/java/org/openhab/binding/orbitbhyve/internal/OrbitBhyveHandlerFactory.java b/bundles/org.openhab.binding.orbitbhyve/src/main/java/org/openhab/binding/orbitbhyve/internal/OrbitBhyveHandlerFactory.java index b655a26d81009..95b7e5ec4ed1b 100644 --- a/bundles/org.openhab.binding.orbitbhyve/src/main/java/org/openhab/binding/orbitbhyve/internal/OrbitBhyveHandlerFactory.java +++ b/bundles/org.openhab.binding.orbitbhyve/src/main/java/org/openhab/binding/orbitbhyve/internal/OrbitBhyveHandlerFactory.java @@ -15,7 +15,6 @@ import static org.openhab.binding.orbitbhyve.internal.OrbitBhyveBindingConstants.THING_TYPE_BRIDGE; import static org.openhab.binding.orbitbhyve.internal.OrbitBhyveBindingConstants.THING_TYPE_SPRINKLER; -import java.util.Arrays; import java.util.HashSet; import java.util.Set; @@ -48,7 +47,7 @@ public class OrbitBhyveHandlerFactory extends BaseThingHandlerFactory { private static final Set SUPPORTED_THING_TYPES_UIDS = new HashSet<>( - Arrays.asList(THING_TYPE_BRIDGE, THING_TYPE_SPRINKLER)); + Set.of(THING_TYPE_BRIDGE, THING_TYPE_SPRINKLER)); /** * the shared http client @@ -58,7 +57,7 @@ public class OrbitBhyveHandlerFactory extends BaseThingHandlerFactory { /** * the shared web socket client */ - private @NonNullByDefault({}) WebSocketClient webSocketClient; + private WebSocketClient webSocketClient; @Activate public OrbitBhyveHandlerFactory(@Reference HttpClientFactory httpClientFactory, diff --git a/bundles/org.openhab.binding.orbitbhyve/src/main/java/org/openhab/binding/orbitbhyve/internal/handler/OrbitBhyveBridgeHandler.java b/bundles/org.openhab.binding.orbitbhyve/src/main/java/org/openhab/binding/orbitbhyve/internal/handler/OrbitBhyveBridgeHandler.java index 4697de8f8f78d..73e66851364e8 100644 --- a/bundles/org.openhab.binding.orbitbhyve/src/main/java/org/openhab/binding/orbitbhyve/internal/handler/OrbitBhyveBridgeHandler.java +++ b/bundles/org.openhab.binding.orbitbhyve/src/main/java/org/openhab/binding/orbitbhyve/internal/handler/OrbitBhyveBridgeHandler.java @@ -79,8 +79,6 @@ public class OrbitBhyveBridgeHandler extends ConfigStatusBridgeHandler { private @Nullable ScheduledFuture future = null; - private @Nullable ScheduledFuture statusFuture = null; - private @Nullable Session session; private @Nullable String sessionToken = null; @@ -130,10 +128,6 @@ public void dispose() { if (localFuture != null) { localFuture.cancel(true); } - localFuture = statusFuture; - if (localFuture != null) { - localFuture.cancel(true); - } closeSession(); super.dispose(); } @@ -186,6 +180,7 @@ private synchronized void ping() { try { logger.debug("Sending ping"); localSession.getRemote().sendString("{\"event\":\"ping\"}"); + updateAllStatuses(); } catch (IOException e) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Error sending ping to a web socket"); @@ -290,10 +285,10 @@ private void processEvent(OrbitBhyveSocketEvent event) { if (ch != null) { updateState(ch.getUID(), "off".equals(event.getMode()) ? OnOffType.OFF : OnOffType.ON); } - deferredStatusUpdate(event.getDeviceId()); + updateDeviceStatus(event.getDeviceId()); break; case "rain_delay": - deferredStatusUpdate(event.getDeviceId()); + updateDeviceStatus(event.getDeviceId()); break; case "skip_active_station": disableZones(event.getDeviceId()); @@ -302,7 +297,7 @@ private void processEvent(OrbitBhyveSocketEvent event) { OrbitBhyveProgram program = gson.fromJson(event.getProgram(), OrbitBhyveProgram.class); if (program != null) { updateDeviceProgramStatus(program); - deferredStatusUpdate(program.getDeviceId()); + updateDeviceStatus(program.getDeviceId()); } break; default: @@ -310,12 +305,26 @@ private void processEvent(OrbitBhyveSocketEvent event) { } } - private void deferredStatusUpdate(String deviceId) { - ScheduledFuture localFuture = statusFuture; - if (localFuture != null) { - localFuture.cancel(true); + private void updateAllStatuses() { + List devices = getDevices(); + for (Thing th : getThing().getThings()) { + String deviceId = th.getUID().getId(); + OrbitBhyveSprinklerHandler handler = (OrbitBhyveSprinklerHandler) th.getHandler(); + for (OrbitBhyveDevice device : devices) { + if (deviceId.equals(th.getUID().getId())) { + updateDeviceStatus(device, handler); + } + } + } + } + + private void updateDeviceStatus(@Nullable OrbitBhyveDevice device, @Nullable OrbitBhyveSprinklerHandler handler) { + if (device != null && handler != null) { + handler.setDeviceOnline(device.isConnected()); + handler.updateDeviceStatus(device.getStatus()); + handler.updateSmartWatering(device.getWaterSenseMode()); + return; } - statusFuture = scheduler.schedule(() -> updateDeviceStatus(deviceId), 3, TimeUnit.SECONDS); } private void updateDeviceStatus(String deviceId) { @@ -323,12 +332,7 @@ private void updateDeviceStatus(String deviceId) { if (deviceId.equals(th.getUID().getId())) { OrbitBhyveSprinklerHandler handler = (OrbitBhyveSprinklerHandler) th.getHandler(); OrbitBhyveDevice device = getDevice(deviceId); - if (device != null && handler != null) { - handler.setDeviceOnline(device.isConnected()); - handler.updateDeviceStatus(device.getStatus()); - handler.updateSmartWatering(device.getWaterSenseMode()); - return; - } + updateDeviceStatus(device, handler); } } } diff --git a/bundles/org.openhab.binding.orbitbhyve/src/main/java/org/openhab/binding/orbitbhyve/internal/handler/OrbitBhyveSprinklerHandler.java b/bundles/org.openhab.binding.orbitbhyve/src/main/java/org/openhab/binding/orbitbhyve/internal/handler/OrbitBhyveSprinklerHandler.java index fb7afcde5b4ea..b3c0c5b96feae 100644 --- a/bundles/org.openhab.binding.orbitbhyve/src/main/java/org/openhab/binding/orbitbhyve/internal/handler/OrbitBhyveSprinklerHandler.java +++ b/bundles/org.openhab.binding.orbitbhyve/src/main/java/org/openhab/binding/orbitbhyve/internal/handler/OrbitBhyveSprinklerHandler.java @@ -23,10 +23,8 @@ import org.openhab.binding.orbitbhyve.internal.model.OrbitBhyveDeviceStatus; import org.openhab.binding.orbitbhyve.internal.model.OrbitBhyveProgram; import org.openhab.binding.orbitbhyve.internal.model.OrbitBhyveZone; -import org.openhab.core.library.types.DateTimeType; -import org.openhab.core.library.types.DecimalType; -import org.openhab.core.library.types.OnOffType; -import org.openhab.core.library.types.StringType; +import org.openhab.core.library.types.*; +import org.openhab.core.library.unit.Units; import org.openhab.core.thing.Bridge; import org.openhab.core.thing.Channel; import org.openhab.core.thing.ChannelUID; @@ -79,9 +77,12 @@ public void handleCommand(ChannelUID channelUID, Command command) { handler.stopWatering(deviceId); return; } - if (CHANNEL_WATERING_TIME.equals(channelUID.getId()) && command instanceof DecimalType) { - wateringTime = ((DecimalType) command).intValue(); - updateState(CHANNEL_WATERING_TIME, (DecimalType) command); + if (CHANNEL_WATERING_TIME.equals(channelUID.getId()) && command instanceof QuantityType) { + final QuantityType value = ((QuantityType) command).toUnit(Units.MINUTE); + if (value != null) { + wateringTime = value.intValue(); + updateState(CHANNEL_WATERING_TIME, new DecimalType(wateringTime)); + } return; } if (channelUID.getId().startsWith("zone")) { @@ -107,7 +108,11 @@ public void handleCommand(ChannelUID channelUID, Command command) { return; } if (CHANNEL_RAIN_DELAY.equals(channelUID.getId()) && command instanceof DecimalType) { - handler.setRainDelay(deviceId, ((DecimalType) command).intValue()); + final QuantityType value = ((QuantityType) command).toUnit(Units.HOUR); + if (value != null) { + handler.setRainDelay(deviceId, value.intValue()); + } + } } } diff --git a/bundles/org.openhab.binding.orbitbhyve/src/main/resources/OH-INF/config/config.xml b/bundles/org.openhab.binding.orbitbhyve/src/main/resources/OH-INF/config/config.xml index d20d31a2efeec..568af236e6bea 100644 --- a/bundles/org.openhab.binding.orbitbhyve/src/main/resources/OH-INF/config/config.xml +++ b/bundles/org.openhab.binding.orbitbhyve/src/main/resources/OH-INF/config/config.xml @@ -17,7 +17,7 @@ - Specifies the refresh time in seconds for polling events from Orbit cloud + Specifies the refresh time in seconds for polling data from Orbit cloud 30 diff --git a/bundles/org.openhab.binding.orbitbhyve/src/main/resources/OH-INF/thing/channels.xml b/bundles/org.openhab.binding.orbitbhyve/src/main/resources/OH-INF/thing/channels.xml index 04f06957dde98..f4efac85493ff 100644 --- a/bundles/org.openhab.binding.orbitbhyve/src/main/resources/OH-INF/thing/channels.xml +++ b/bundles/org.openhab.binding.orbitbhyve/src/main/resources/OH-INF/thing/channels.xml @@ -23,7 +23,7 @@ - Number + Number:Time Channel representing rain delay in hours