Skip to content

Commit

Permalink
[orbitbhyve] improvements based on code review
Browse files Browse the repository at this point in the history
Signed-off-by: Ondrej Pecta <opecta@gmail.com>
  • Loading branch information
octa22 committed Jul 18, 2021
1 parent a853bf8 commit 31b2dc1
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 63 deletions.
5 changes: 5 additions & 0 deletions bom/openhab-addons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,11 @@
<artifactId>org.openhab.binding.oppo</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.binding.orbitbhyve</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.binding.orvibo</artifactId>
Expand Down
24 changes: 9 additions & 15 deletions bundles/org.openhab.binding.orbitbhyve/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ So far only the [Orbit B-hyve 8-zone Indoor Timer](https://bhyve.orbitonline.com
This binding supports the auto discovery of the sprinklers bound to your Orbit B-hyve account.
To start the discovery you need to create a bridge thing and enter valid credentials to your Orbit B-hyve cloud account.

## Binding Configuration

This binding does not require any configuration on the binding level.

## Thing Configuration

The bridge thing requires a manual configuration. You have to enter valid credentials to your Orbit B-hyve account, and you can also set the refresh time in seconds for polling data from the Orbit cloud.
Expand All @@ -33,16 +29,14 @@ This binding automatically detects all zones and programs for each sprinkler and

Beside the dynamic channels each sprinkler thing provides these standard channels:

| channel | type | description |
|----------------|----------|--------------------------------------------------------------------|
| 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 |
| watering_time | Number | 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) |
| control | String | This channel manages the manual zone watering time in minutes |

| channel | type | description |
|----------------|-------------|--------------------------------------------------------------------|
| 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 |
| 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) |

## Full Example

Expand Down Expand Up @@ -87,4 +81,4 @@ Text item=IrrigationMode
Text item=IrrigationRainDelay
Switch item=IrrigationRainDelay mappings=[0="OFF", 24="24", 48="48", 72="72"]
Text item=IrrigationNextStart visibility=[IrrigationP1Enable==ON]
```
```
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class OrbitBhyveHandlerFactory extends BaseThingHandlerFactory {
/**
* the shared http client
*/
private @NonNullByDefault({}) HttpClient httpClient;
private HttpClient httpClient;

/**
* the shared web socket client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,14 @@ private boolean login() {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR);
return false;
}
} catch (InterruptedException | TimeoutException | ExecutionException e) {
} catch (TimeoutException | ExecutionException e) {
logger.debug("Exception during login", e);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR);
if (e instanceof InterruptedException) {
Thread.currentThread().interrupt();
}
return false;
} catch (InterruptedException e) {
logger.debug("Error during updating device", e);
updateStatus(ThingStatus.OFFLINE);
Thread.currentThread().interrupt();
return false;
}
updateStatus(ThingStatus.ONLINE);
Expand Down Expand Up @@ -203,12 +205,13 @@ public List<OrbitBhyveDevice> getDevices() {
logger.debug("Returned status: {}", response.getStatus());
updateStatus(ThingStatus.OFFLINE);
}
} catch (InterruptedException | TimeoutException | ExecutionException e) {
} catch (TimeoutException | ExecutionException e) {
logger.debug("Error during getting devices", e);
updateStatus(ThingStatus.OFFLINE);
if (e instanceof InterruptedException) {
Thread.currentThread().interrupt();
}
} catch (InterruptedException e) {
logger.debug("Error during updating device", e);
updateStatus(ThingStatus.OFFLINE);
Thread.currentThread().interrupt();
}
return new ArrayList<>();
}
Expand All @@ -232,13 +235,15 @@ Request sendRequestBuilder(String uri, HttpMethod method) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"Returned status: " + response.getStatus());
}
} catch (InterruptedException | TimeoutException | ExecutionException e) {
} catch (TimeoutException | ExecutionException e) {
logger.debug("Error during getting device: {}", deviceId, e);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"Error during getting device info");
if (e instanceof InterruptedException) {
Thread.currentThread().interrupt();
}
} catch (InterruptedException e) {
logger.debug("Error during getting device: {}", deviceId, e);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"Error during getting device info");
Thread.currentThread().interrupt();
}
return null;
}
Expand Down Expand Up @@ -475,12 +480,13 @@ public void enableProgram(OrbitBhyveProgram program, boolean enable) {
logger.debug("Returned status: {}", response.getStatus());
updateStatus(ThingStatus.OFFLINE);
}
} catch (InterruptedException | TimeoutException | ExecutionException e) {
} catch (TimeoutException | ExecutionException e) {
logger.debug("Error during updating program", e);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Error during getting programs");
if (e instanceof InterruptedException) {
Thread.currentThread().interrupt();
}
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Error during updating programs");
} catch (InterruptedException e) {
logger.debug("Error during updating program", e);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Error during updating programs");
Thread.currentThread().interrupt();
}
}

Expand Down Expand Up @@ -527,12 +533,13 @@ public List<OrbitBhyveProgram> getPrograms() {
logger.debug("Returned status: {}", response.getStatus());
updateStatus(ThingStatus.OFFLINE);
}
} catch (InterruptedException | TimeoutException | ExecutionException e) {
} catch (TimeoutException | ExecutionException e) {
logger.debug("Error during getting programs", e);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Error during getting programs");
if (e instanceof InterruptedException) {
Thread.currentThread().interrupt();
}
} catch (InterruptedException e) {
logger.debug("Error during getting program", e);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Error during getting programs");
Thread.currentThread().interrupt();
}
return new ArrayList<>();
}
Expand Down Expand Up @@ -577,12 +584,13 @@ private void updateDevice(String deviceId, String deviceString) {
}
updateStatus(ThingStatus.OFFLINE);
}
} catch (InterruptedException | TimeoutException | ExecutionException e) {
} catch (TimeoutException | ExecutionException e) {
logger.debug("Error during updating device", e);
updateStatus(ThingStatus.OFFLINE);
if (e instanceof InterruptedException) {
Thread.currentThread().interrupt();
}
} catch (InterruptedException e) {
logger.debug("Error during updating device", e);
updateStatus(ThingStatus.OFFLINE);
Thread.currentThread().interrupt();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,6 @@ public void updateProgram(OrbitBhyveProgram program) {
}

public void updateSmartWatering(String senseMode) {
updateState(CHANNEL_SMART_WATERING, (senseMode.equals("auto")) ? OnOffType.ON : OnOffType.OFF);
updateState(CHANNEL_SMART_WATERING, ("auto".equals(senseMode)) ? OnOffType.ON : OnOffType.OFF);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/
@NonNullByDefault
public class OrbitBhyveSocket extends WebSocketAdapter {
private final Logger logger = LoggerFactory.getLogger(OrbitBhyveBridgeHandler.class);
private final Logger logger = LoggerFactory.getLogger(OrbitBhyveSocket.class);
private OrbitBhyveBridgeHandler handler;

public OrbitBhyveSocket(OrbitBhyveBridgeHandler handler) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns:binding="https://openhab.org/schemas/binding/v1.0.0"
xsi:schemaLocation="https://openhab.org/schemas/binding/v1.0.0 https://openhab.org/schemas/binding-1.0.0.xsd">

<name>Orbit B-Hyve Binding</name>
<description>This is the binding for Orbit B-Hyve.</description>
<name>Orbit B-hyve Binding</name>
<description>This is the binding for Orbit B-hyve.</description>

</binding:binding>
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@

<config-description uri="bridge-type:orbitbhyve:bridge">
<parameter name="email" type="text" required="true">
<label>Email parameter</label>
<description>This is a login to your B-Hyve account.</description>
<label>Email Parameter</label>
<context>email</context>
<description>This is a login to your B-hyve account.</description>
</parameter>
<parameter name="password" type="text" required="true">
<label>Password</label>
<context>password</context>
<description>This is a password to your B-Hyve account.</description>
<description>This is a password to your B-hyve account.</description>
</parameter>
<parameter name="refresh" type="integer" required="false" min="10">
<label>Refresh</label>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<thing:thing-descriptions bindingId="orbitbhyve"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:thing="http://openhab.org/schemas/thing-description/v1.0.0"
xsi:schemaLocation="http://openhab.org/smarthome/schemas/thing-description/v1.0.0 http://openhab.org/schemas/thing-description-1.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:thing="https://openhab.org/schemas/thing-description/v1.0.0"
xsi:schemaLocation="https://openhab.org/schemas/thing-description/v1.0.0 https://openhab.org/schemas/thing-description-1.0.0.xsd">

<!-- Bridge Type -->
<bridge-type id="bridge">
<label>Orbit B-Hyve Binding Bridge</label>
<description>Bridge for Orbit B-Hyve Binding</description>
<label>Bridge</label>
<description>Bridge for Orbit B-hyve Binding</description>
<config-description-ref uri="bridge-type:orbitbhyve:bridge"/>
</bridge-type>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,29 @@
<channel-type id="mode">
<item-type>String</item-type>
<label>Irrigation Mode</label>
<description>Channel representing mode of Orbit B-Hyve Device (auto/manual)</description>
<state readOnly="true"></state>
<description>Channel representing mode of Orbit B-hyve Device (auto/manual)</description>
<state readOnly="true">
<options>
<option value="auto">Auto</option>
<option value="manual">Manual</option>
</options>
</state>
</channel-type>
<channel-type id="next_start">
<item-type>DateTime</item-type>
<label>Next Watering Start Time</label>
<label>Next Watering Time</label>
<description>Channel representing start time of the next watering</description>
<state readOnly="true"></state>
</channel-type>
<channel-type id="rain_delay">
<item-type>Integer</item-type>
<label>Rain delay</label>
<item-type>Number</item-type>
<label>Rain Delay</label>
<description>Channel representing rain delay in hours</description>
<state pattern="%d h"></state>
</channel-type>
<channel-type id="watering_time">
<item-type>Integer</item-type>
<label>Zone watering time</label>
<item-type>Number:Time</item-type>
<label>Zone Watering Time</label>
<description>Channel representing the manual zone watering time in minutes</description>
<state max="240" min="0" pattern="%d min"></state>
</channel-type>
Expand All @@ -36,17 +41,17 @@
</channel-type>
<channel-type id="smart_watering">
<item-type>Switch</item-type>
<label>Sprinkler Smart Watering Control</label>
<label>Smart Watering Control</label>
<description>Channel for enabling/disabling the smart watering mode</description>
</channel-type>
<channel-type id="program">
<item-type>Switch</item-type>
<label>Program channel</label>
<label>Program Channel</label>
<description>Dynamic channel representing a program</description>
</channel-type>
<channel-type id="zone">
<item-type>Switch</item-type>
<label>Zone channel</label>
<label>Zone Channel</label>
<description>Dynamic channel representing a zone</description>
</channel-type>
</thing:thing-descriptions>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
<supported-bridge-type-refs>
<bridge-type-ref id="bridge"/>
</supported-bridge-type-refs>
<label>Orbit B-Hyve Sprinkler</label>
<label>Sprinkler</label>
<description>Orbit B-hyve Sprinkler</description>
<channels>
<channel id="control" typeId="control"/>
<channel id="mode" typeId="mode"/>
Expand Down

0 comments on commit 31b2dc1

Please sign in to comment.