Skip to content

Commit

Permalink
Rebase to latest 2.5.x (2.5.8) + Fixed new build warnings (usage of s…
Browse files Browse the repository at this point in the history
…ome apache http constant file + conversion from epoch millis to DateTimeType)

Signed-off-by: Markus Pfleger <pfleger_markus@gmx.at>
  • Loading branch information
Markus Pfleger committed Aug 4, 2020
1 parent dc97adf commit a551e34
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion bundles/org.openhab.binding.automower/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.addons.reactor.bundles</artifactId>
<version>2.5.7-SNAPSHOT</version>
<version>2.5.8-SNAPSHOT</version>
</parent>

<artifactId>org.openhab.binding.automower</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;

import org.apache.commons.httpclient.HttpStatus;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.client.util.FormContentProvider;
import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.util.Fields;
import org.openhab.binding.automower.internal.rest.api.HusqvarnaApi;
import org.openhab.binding.automower.internal.rest.api.authentication.dto.PostOAuth2Response;
Expand Down Expand Up @@ -96,21 +96,21 @@ public PostOAuth2Response loginWithRefreshToken(String appKey, String refreshTok
private PostOAuth2Response parseResponse(ContentResponse response) throws AutomowerCommunicationException {
int statusCode = response.getStatus();
switch (statusCode) {
case HttpStatus.SC_OK:
case HttpStatus.SC_CREATED:
case HttpStatus.OK_200:
case HttpStatus.CREATED_201:
try {
return gson.fromJson(response.getContentAsString(), PostOAuth2Response.class);
} catch (JsonSyntaxException e) {
throw new AutomowerCommunicationException(e);
}

case HttpStatus.SC_BAD_REQUEST:
case HttpStatus.BAD_REQUEST_400:
throw new AutomowerCommunicationException(statusCode,
"Unable to authenticate. Maybe the given credentials are wrong or the Authentication Api is not connected to the given application key: "
+ response.getContentAsString());

case HttpStatus.SC_FORBIDDEN:
case HttpStatus.SC_UNAUTHORIZED:
case HttpStatus.FORBIDDEN_403:
case HttpStatus.UNAUTHORIZED_401:
throw new UnauthorizedException(statusCode, response.getContentAsString());

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;

import org.apache.commons.httpclient.HttpStatus;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.client.util.StringContentProvider;
import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.HttpStatus;
import org.openhab.binding.automower.internal.rest.api.HusqvarnaApi;
import org.openhab.binding.automower.internal.rest.api.automowerconnect.dto.MowerCommandRequest;
import org.openhab.binding.automower.internal.rest.api.automowerconnect.dto.MowerListResult;
Expand Down Expand Up @@ -126,12 +126,12 @@ private void checkForError(ContentResponse response, int statusCode) throws Auto
}

switch (statusCode) {
case HttpStatus.SC_NOT_FOUND:
case HttpStatus.NOT_FOUND_404:
throw new AutomowerCommunicationException(statusCode, "Target '" + response.getRequest().getURI()
+ "' seems to be not available: " + response.getContentAsString());

case HttpStatus.SC_FORBIDDEN:
case HttpStatus.SC_UNAUTHORIZED:
case HttpStatus.FORBIDDEN_403:
case HttpStatus.UNAUTHORIZED_401:
throw new UnauthorizedException(statusCode, response.getContentAsString());

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

import static org.openhab.binding.automower.internal.AutomowerBindingConstants.*;

import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
Expand All @@ -38,7 +41,6 @@
import org.eclipse.smarthome.core.thing.binding.ThingHandlerService;
import org.eclipse.smarthome.core.types.Command;
import org.eclipse.smarthome.core.types.RefreshType;
import org.joda.time.DateTime;
import org.openhab.binding.automower.internal.AutomowerBindingConstants;
import org.openhab.binding.automower.internal.actions.AutomowerActions;
import org.openhab.binding.automower.internal.bridge.AutomowerBridge;
Expand Down Expand Up @@ -251,14 +253,17 @@ private void updateChannelState(Mower mower) {
updateState(CHANNEL_STATUS_ACTIVITY, new StringType(mower.getAttributes().getMower().getActivity().name()));
updateState(CHANNEL_STATUS_STATE, new StringType(mower.getAttributes().getMower().getState().name()));

updateState(CHANNEL_STATUS_LAST_UPDATE, new DateTimeType(
new DateTime(mower.getAttributes().getMetadata().getStatusTimestamp()).toString()));
Instant statusTimestamp = Instant.ofEpochMilli(mower.getAttributes().getMetadata().getStatusTimestamp());
updateState(CHANNEL_STATUS_LAST_UPDATE,
new DateTimeType(ZonedDateTime.ofInstant(statusTimestamp, ZoneId.systemDefault())));
updateState(CHANNEL_STATUS_BATTERY,
new DecimalType(mower.getAttributes().getBattery().getBatteryPercent()));

updateState(CHANNEL_STATUS_ERROR_CODE, new DecimalType(mower.getAttributes().getMower().getErrorCode()));
updateState(CHANNEL_STATUS_ERROR_TIMESTAMP, new DateTimeType(
new DateTime(mower.getAttributes().getMower().getErrorCodeTimestamp()).toString()));

Instant errorCodeTimestamp = Instant.ofEpochMilli(mower.getAttributes().getMower().getErrorCodeTimestamp());
updateState(CHANNEL_STATUS_ERROR_TIMESTAMP,
new DateTimeType(ZonedDateTime.ofInstant(errorCodeTimestamp, ZoneId.systemDefault())));

}
}
Expand Down

0 comments on commit a551e34

Please sign in to comment.