Skip to content

Commit

Permalink
Correct typecast error plus JLAUR comments
Browse files Browse the repository at this point in the history
Signed-off-by: clinique <gael@lhopital.org>
  • Loading branch information
clinique committed Mar 16, 2024
1 parent d25d24a commit 3a92b91
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -350,15 +350,20 @@ public synchronized <T> T executeUri(URI uri, HttpMethod method, Class<T> clazz,
try {
exception = new NetatmoException(deserializer.deserialize(ApiError.class, responseBody));
} catch (NetatmoException e) {
exception = new NetatmoException("Error deserializing error: %s".formatted(statusCode.getMessage()));
if (statusCode == Code.TOO_MANY_REQUESTS) {
exception = new NetatmoException(Code.TOO_MANY_REQUESTS.getMessage());
} else {
exception = new NetatmoException(
"Error deserializing error: %s".formatted(statusCode.getMessage()));
}
}
throw exception;
} catch (NetatmoException e) {
if (e.getStatusCode() == ServiceError.MAXIMUM_USAGE_REACHED) {
if (statusCode == Code.TOO_MANY_REQUESTS
|| exception.getStatusCode() == ServiceError.MAXIMUM_USAGE_REACHED) {
prepareReconnection(API_LIMIT_INTERVAL_S,
"@text/maximum-usage-reached [ \"%d\" ]".formatted(API_LIMIT_INTERVAL_S), null, null);
}
throw e;
throw exception;

} catch (InterruptedException | TimeoutException | ExecutionException e) {
if (retryCount > 0) {
logger.debug("Request error, retry counter: {}", retryCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.ScheduledExecutorService;
import java.util.stream.Stream;
Expand Down Expand Up @@ -107,7 +106,7 @@ void setThingStatus(ThingStatus thingStatus, ThingStatusDetail thingStatusDetail
}

default void expireData() {
getCapabilities().values().forEach(cap -> cap.expireData());
getCapabilities().values().forEach(Capability::expireData);
}

default String getId() {
Expand Down Expand Up @@ -152,13 +151,12 @@ default List<CommonInterface> getAllActiveChildren(Bridge bridge) {
}

default List<CommonInterface> getActiveChildren() {
Thing thing = getThing();
if (thing instanceof Bridge bridge) {
return bridge.getThings().stream().filter(Thing::isEnabled)
.filter(th -> th.getStatusInfo().getStatusDetail() != ThingStatusDetail.BRIDGE_OFFLINE)
.map(Thing::getHandler).filter(Objects::nonNull).map(CommonInterface.class::cast).toList();
}
return List.of();
return getThing() instanceof Bridge bridge
? bridge.getThings().stream().filter(Thing::isEnabled)
.filter(th -> th.getStatusInfo().getStatusDetail() != ThingStatusDetail.BRIDGE_OFFLINE)
.map(Thing::getHandler).filter(CommonInterface.class::isInstance)
.map(CommonInterface.class::cast).toList()
: List.of();
}

default Stream<CommonInterface> getActiveChildren(FeatureArea area) {
Expand Down Expand Up @@ -207,7 +205,7 @@ default void commonHandleCommand(ChannelUID channelUID, Command command) {
}

default void proceedWithUpdate() {
updateReadings().forEach(dataSet -> setNewData(dataSet));
updateReadings().forEach(this::setNewData);
}

default List<NAObject> updateReadings() {
Expand Down Expand Up @@ -244,7 +242,6 @@ default void commonDispose() {
}

default void removeChannels(List<Channel> channels) {
ThingBuilder builder = editThing().withoutChannels(channels);
updateThing(builder.build());
updateThing(editThing().withoutChannels(channels).build());
}
}

0 comments on commit 3a92b91

Please sign in to comment.