Skip to content

Commit

Permalink
Fixes openhab#7261
Browse files Browse the repository at this point in the history
Fixes a NPE due to a change in the Hydrawise API, adds additional controller statuses as a channles.

Signed-off-by: digitaldan <[email protected]>
  • Loading branch information
digitaldan committed Mar 31, 2020
1 parent 8a5b3d0 commit 43c413b
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 12 deletions.
42 changes: 35 additions & 7 deletions bundles/org.openhab.binding.hydrawise/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ Changes made through this Thing type will be reflected in the Hydrawise mobile a

#### Cloud Thing Supported Channel Groups

| channel group ID |
|---------------------------------------|
| [Zones](#Zone-Channel-Group) |
| [All Zones](#All-Zones-Channel-Group) |
| [Sensor](#Sensor-Channel-Group) |
| [Forecast](#Sensor-Channel-Group) |
| channel group ID |
|-----------------------------------------------|
| [Controller](#Cloud-Controller-Channel-Group) |
| [Zones](#Zone-Channel-Group) |
| [All Zones](#All-Zones-Channel-Group) |
| [Sensor](#Sensor-Channel-Group) |
| [Forecast](#Sensor-Channel-Group) |
### Local Thing

Expand Down Expand Up @@ -70,6 +71,13 @@ Then copy the API key shown here:

### Channel Groups

#### Cloud Controller Channel Group

| channel group ID | Description |
|------------------|----------------------------------|
| status | Status of controller |
| lastContact | Last contact time of controller |

#### Zone Channel Group

Up to 36 total zones are supported per Local or Cloud thing
Expand Down Expand Up @@ -114,6 +122,8 @@ A single all zone group are supported per Cloud or Local Thing

### Channels

Channels uses across zones, sensors and forecasts

| channel ID | type | Groups | description | Read Write |
|-----------------|--------------------|----------------|---------------------------------------------|------------|
| name | String | zone, sensor | Descriptive name | R |
Expand All @@ -140,7 +150,25 @@ A single all zone group are supported per Cloud or Local Thing
## Full Example

```
Group SprinklerZones
Group Sprinkler "Sprinkler"
Group SprinklerController "Controller" (Sprinkler)
Group SprinklerZones "Zones" (Sprinkler)
Group SprinklerSensors "Sensors" (Sprinkler)
Group SprinkerForecast "Forecast" (Sprinkler)
String SprinkerControllerStatus "Status [%s]" (SprinklerController) {channel="hydrawise:cloud:home:controller#status"}
Number SprinkerControllerLastContact "Last Contact [%d]" (SprinklerController) {channel="hydrawise:cloud:home:controller#lastContact"}
Switch SprinklerSensor1 "Sprinler Sensor" (SprinklerSensors) {channel="hydrawise:cloud:home:sensor1#active"}
Group SprinkerForecastDay1 "Todays Forecast" (SprinkerForecast)
Number:Temperature SprinkerForecastDay1HiTemp "High Temp [%d]" (SprinkerForecastDay1) {channel="hydrawise:cloud:home:forecast1#temperaturehigh"}
Number:Temperature SprinkerForecastDay1LowTemp "Low Temp [%d]" (SprinkerForecastDay1) {channel="hydrawise:cloud:home:forecast1#temperaturelow"}
String SprinkerForecastDay1Conditions "Conditions [%s]" (SprinkerForecastDay1) {channel="hydrawise:cloud:home:forecast1#conditions"}
String SprinkerForecastDay1Day "Day [%s]" (SprinkerForecastDay1) {channel="hydrawise:cloud:home:forecast1#day"}
Number SprinkerForecastDay1Humidity "Humidity [%d%%]" (SprinkerForecastDay1) {channel="hydrawise:cloud:home:forecast1#humidity"}
Number:Speed SprinkerForecastDay1Wind "Wind [%s]" (SprinkerForecastDay1) {channel="hydrawise:cloud:home:forecast1#wind"}
Group SprinklerZone1 "1 Front Office Yard" (SprinklerZones)
String SprinklerZone1Name "1 Front Office Yard name" (SprinklerZone1) {channel="hydrawise:cloud:home:zone1#name"}
Switch SprinklerZone1Run "1 Front Office Yard Run" (SprinklerZone1) {channel="hydrawise:cloud:home:zone1#run"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public class HydrawiseBindingConstants {

public static final String BASE_IMAGE_URL = "https://app.hydrawise.com/config/images/";

public static final String CHANNEL_GROUP_CONTROLLER = "controller";
public static final String CHANNEL_CONTROLLER_LAST_CONTACT = "lastContact";
public static final String CHANNEL_CONTROLLER_STATUS = "status";
public static final String CHANNEL_GROUP_ALLZONES = "allzones";
public static final String CHANNEL_ZONE_RUN_CUSTOM = "runcustom";
public static final String CHANNEL_ZONE_RUN = "run";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,10 @@ protected void configure()
protected void pollController() throws HydrawiseConnectionException, HydrawiseAuthenticationException {
List<Controller> controllers = client.getCustomerDetails().controllers;
Controller controller = getController(controllerId, controllers);
if (controller != null && !controller.online) {
throw new HydrawiseConnectionException("Controller is offline");
if (controller == null) {
throw new HydrawiseConnectionException("Controller is offline or missing");
}
updateController(controller);
StatusScheduleResponse status = client.getStatusSchedule(controllerId);
updateSensors(status);
updateForecast(status);
Expand Down Expand Up @@ -179,6 +180,12 @@ protected void sendStopAllCommand()
client.stopAllRelays(controllerId);
}

private void updateController(Controller controller) {
updateGroupState(CHANNEL_GROUP_CONTROLLER, CHANNEL_CONTROLLER_LAST_CONTACT,
new DecimalType(controller.lastContact));
updateGroupState(CHANNEL_GROUP_CONTROLLER, CHANNEL_CONTROLLER_STATUS, new StringType(controller.status));
}

private void updateSensors(StatusScheduleResponse status) {
status.sensors.forEach(sensor -> {
String group = "sensor" + sensor.input;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
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">
<channel-group-type id="cloudController">
<label>Controller</label>
<description>Hydrawise cloud controller</description>
<channels>
<channel id="lastContact" typeId="lastContactTime" />
<channel id="status" typeId="status" />
</channels>
</channel-group-type>

<channel-group-type id="zone">
<label>Zone</label>
Expand All @@ -27,7 +35,7 @@
<channel id="run" typeId="run" />
</channels>
</channel-group-type>

<channel-group-type id="sensor">
<label>Sensor</label>
<description>Hydrawise sensor</description>
Expand Down Expand Up @@ -56,6 +64,23 @@
</channel-group-type>

<!-- Controller -->

<channel-type id="lastContactTime" advanced="true">
<item-type>Number</item-type>
<label>Last Contact Time</label>
<description>Last contact time of a controller in seconds</description>
<state readOnly="true"></state>
</channel-type>

<channel-type id="status">
<item-type>String</item-type>
<label>Status</label>
<description>Status of the controller</description>
<state readOnly="true"></state>
</channel-type>

<!-- Zones -->

<channel-type id="name">
<item-type>String</item-type>
<label>Name</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@
<!-- Until we have https://github.com/eclipse/smarthome/issues/1118 fixed, we need to list all possible channel groups.
Once this is fixed we can dynamically add them to the thing and not list them here. -->
<channel-groups>

<!-- Controller -->

<channel-group id="controller" typeId="cloudController">
<label>Controller</label>
<description>Controller</description>
</channel-group>

<!-- Sensors -->

<channel-group id="sensor1" typeId="sensor">
<label>Sensor 1</label>
<description>Sensor 1</description>
Expand All @@ -29,6 +39,8 @@
<description>Sensor 4</description>
</channel-group>

<!-- Forecasts -->

<channel-group id="forecast1" typeId="forecast">
<label>Today's Weather</label>
<description>Today's weather forecast</description>
Expand All @@ -46,8 +58,12 @@
<description>Day 4 weather forecast</description>
</channel-group>

<!-- All Zones -->

<channel-group id="allzones" typeId="allzones" />

<!-- Zones -->

<channel-group id="zone1" typeId="zone">
<label>Zone 1</label>
<description>Sprinkler Zone 1</description>
Expand Down Expand Up @@ -383,6 +399,4 @@
</parameter>
</config-description>
</thing-type>


</thing:thing-descriptions>

0 comments on commit 43c413b

Please sign in to comment.