Skip to content

Commit 9921551

Browse files
authored
feat: standardizing on SLF4J annotation (#94)
1 parent 5e0e667 commit 9921551

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

src/main/java/com/bigboxer23/switch_bot/SwitchBotApi.java

+6-7
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@
1111
import javax.crypto.Mac;
1212
import javax.crypto.spec.SecretKeySpec;
1313
import lombok.Getter;
14+
import lombok.extern.slf4j.Slf4j;
1415
import okhttp3.Response;
15-
import org.slf4j.Logger;
16-
import org.slf4j.LoggerFactory;
1716

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

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

3938
public static SwitchBotApi getInstance(String token, String secret) {
4039
if (token == null || secret == null) {
41-
logger.error("need to define token and secret values.");
40+
log.error("need to define token and secret values.");
4241
throw new RuntimeException("need to define token and secret values.");
4342
}
4443
return Optional.ofNullable(instance).orElseGet(() -> {
@@ -67,7 +66,7 @@ protected RequestBuilderCallback addAuth() {
6766
.addHeader("nonce", nonce)
6867
.addHeader("t", time);
6968
} catch (NoSuchAlgorithmException | InvalidKeyException e) {
70-
logger.warn("exception with auth: ", e);
69+
log.warn("exception with auth: ", e);
7170
}
7271
return builder;
7372
};
@@ -83,13 +82,13 @@ protected boolean checkForError(Response response, Optional<IApiResponse> apiRes
8382
return apiResponse
8483
.map(api -> {
8584
if (api.getStatusCode() != 100) {
86-
logger.error("error code: " + api.getStatusCode() + " : " + api.getMessage());
85+
log.error("error code: " + api.getStatusCode() + " : " + api.getMessage());
8786
return false;
8887
}
8988
return true;
9089
})
9190
.orElseGet(() -> {
92-
logger.error("Error calling switchbot api: " + response.code() + " " + response.message());
91+
log.error("Error calling switchbot api: " + response.code() + " " + response.message());
9392
return false;
9493
});
9594
}

src/main/java/com/bigboxer23/switch_bot/SwitchBotDeviceApi.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@
1111
import java.util.Map;
1212
import java.util.Optional;
1313
import java.util.stream.Collectors;
14+
import lombok.extern.slf4j.Slf4j;
1415
import okhttp3.RequestBody;
1516
import okhttp3.Response;
16-
import org.slf4j.Logger;
17-
import org.slf4j.LoggerFactory;
1817

1918
/** */
19+
@Slf4j
2020
public class SwitchBotDeviceApi {
21-
private static final Logger logger = LoggerFactory.getLogger(SwitchBotDeviceApi.class);
2221
private final SwitchBotApi provider;
2322

2423
private Map<String, String> deviceIdToNames;
@@ -42,12 +41,12 @@ private synchronized void refreshDeviceNameMap() {
4241
return;
4342
}
4443
try {
45-
logger.info("Refreshing device id/name map...");
44+
log.info("Refreshing device id/name map...");
4645
deviceIdToNames = Collections.unmodifiableMap(
4746
getDevices().stream().collect(Collectors.toMap(Device::getDeviceId, Device::getDeviceName)));
4847
deviceIdToNamesCacheTime = System.currentTimeMillis();
4948
} catch (IOException e) {
50-
logger.error("Failed to refresh device names.", e);
49+
log.error("Failed to refresh device names.", e);
5150
deviceIdToNames = null;
5251
deviceIdToNamesCacheTime = -1;
5352
}
@@ -72,7 +71,7 @@ public List<Device> getDevices() throws IOException {
7271
*/
7372
public Device getDeviceStatus(String deviceId) throws IOException {
7473
if (deviceId == null) {
75-
logger.error("Need valid device id");
74+
log.error("Need valid device id");
7675
return null;
7776
}
7877
try (Response response = OkHttpUtil.getSynchronous(

src/main/java/com/bigboxer23/switch_bot/data/Device.java

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ public class Device {
4141

4242
private float electricCurrent; // amps / 10
4343

44-
4544
private int waterDetectorStatus;
4645

4746
@Json(name = "CO2")

0 commit comments

Comments
 (0)