Skip to content

feat: standardizing on SLF4J annotation #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/main/java/com/bigboxer23/switch_bot/SwitchBotApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import okhttp3.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/** */
@Slf4j
@Getter
public class SwitchBotApi {
private static final Logger logger = LoggerFactory.getLogger(SwitchBotApi.class);
protected static final String baseUrl = "https://api.switch-bot.com/";

private static SwitchBotApi instance;
Expand All @@ -38,7 +37,7 @@ private SwitchBotApi(String token, String secret) {

public static SwitchBotApi getInstance(String token, String secret) {
if (token == null || secret == null) {
logger.error("need to define token and secret values.");
log.error("need to define token and secret values.");
throw new RuntimeException("need to define token and secret values.");
}
return Optional.ofNullable(instance).orElseGet(() -> {
Expand Down Expand Up @@ -67,7 +66,7 @@ protected RequestBuilderCallback addAuth() {
.addHeader("nonce", nonce)
.addHeader("t", time);
} catch (NoSuchAlgorithmException | InvalidKeyException e) {
logger.warn("exception with auth: ", e);
log.warn("exception with auth: ", e);
}
return builder;
};
Expand All @@ -83,13 +82,13 @@ protected boolean checkForError(Response response, Optional<IApiResponse> apiRes
return apiResponse
.map(api -> {
if (api.getStatusCode() != 100) {
logger.error("error code: " + api.getStatusCode() + " : " + api.getMessage());
log.error("error code: " + api.getStatusCode() + " : " + api.getMessage());
return false;
}
return true;
})
.orElseGet(() -> {
logger.error("Error calling switchbot api: " + response.code() + " " + response.message());
log.error("Error calling switchbot api: " + response.code() + " " + response.message());
return false;
});
}
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/com/bigboxer23/switch_bot/SwitchBotDeviceApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import okhttp3.RequestBody;
import okhttp3.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/** */
@Slf4j
public class SwitchBotDeviceApi {
private static final Logger logger = LoggerFactory.getLogger(SwitchBotDeviceApi.class);
private final SwitchBotApi provider;

private Map<String, String> deviceIdToNames;
Expand All @@ -42,12 +41,12 @@ private synchronized void refreshDeviceNameMap() {
return;
}
try {
logger.info("Refreshing device id/name map...");
log.info("Refreshing device id/name map...");
deviceIdToNames = Collections.unmodifiableMap(
getDevices().stream().collect(Collectors.toMap(Device::getDeviceId, Device::getDeviceName)));
deviceIdToNamesCacheTime = System.currentTimeMillis();
} catch (IOException e) {
logger.error("Failed to refresh device names.", e);
log.error("Failed to refresh device names.", e);
deviceIdToNames = null;
deviceIdToNamesCacheTime = -1;
}
Expand All @@ -72,7 +71,7 @@ public List<Device> getDevices() throws IOException {
*/
public Device getDeviceStatus(String deviceId) throws IOException {
if (deviceId == null) {
logger.error("Need valid device id");
log.error("Need valid device id");
return null;
}
try (Response response = OkHttpUtil.getSynchronous(
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/bigboxer23/switch_bot/data/Device.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public class Device {

private float electricCurrent; // amps / 10


private int waterDetectorStatus;

@Json(name = "CO2")
Expand Down