diff --git a/bundles/org.openhab.binding.smartthings/src/main/java/org/openhab/binding/smartthings/internal/SmartthingsBaseServlet.java b/bundles/org.openhab.binding.smartthings/src/main/java/org/openhab/binding/smartthings/internal/SmartthingsBaseServlet.java
index 66b0b280a0293..d0e438b7c239e 100644
--- a/bundles/org.openhab.binding.smartthings/src/main/java/org/openhab/binding/smartthings/internal/SmartthingsBaseServlet.java
+++ b/bundles/org.openhab.binding.smartthings/src/main/java/org/openhab/binding/smartthings/internal/SmartthingsBaseServlet.java
@@ -40,7 +40,7 @@
public class SmartthingsBaseServlet extends HttpServlet {
private static final long serialVersionUID = -4719613645562518231L;
- private final Logger logger = LoggerFactory.getLogger(SmartthingsAuthServlet.class);
+ private final Logger logger = LoggerFactory.getLogger(SmartthingsBaseServlet.class);
protected final SmartthingsBridgeHandler bridgeHandler;
protected final HttpService httpService;
diff --git a/bundles/org.openhab.binding.smartthings/src/main/java/org/openhab/binding/smartthings/internal/SmartthingsServlet.java b/bundles/org.openhab.binding.smartthings/src/main/java/org/openhab/binding/smartthings/internal/SmartthingsServlet.java
index e3b31b494b95e..933ea8db5da83 100644
--- a/bundles/org.openhab.binding.smartthings/src/main/java/org/openhab/binding/smartthings/internal/SmartthingsServlet.java
+++ b/bundles/org.openhab.binding.smartthings/src/main/java/org/openhab/binding/smartthings/internal/SmartthingsServlet.java
@@ -41,6 +41,7 @@
import org.openhab.binding.smartthings.internal.dto.SMEvent.device;
import org.openhab.binding.smartthings.internal.dto.SmartthingsLocation;
import org.openhab.binding.smartthings.internal.handler.SmartthingsBridgeHandler;
+import org.openhab.binding.smartthings.internal.type.SmartthingsException;
import org.osgi.framework.BundleContext;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.annotations.Activate;
@@ -160,21 +161,25 @@ protected void service(@Nullable HttpServletRequest req, @Nullable HttpServletRe
template = indexTemplate;
}
- if (template == selectLocationTemplate) {
+ if (selectLocationTemplate.equals(template)) {
SetupApp();
- SmartthingsLocation[] locationList = api.GetAllLocations();
- for (SmartthingsLocation loc : locationList) {
- optionBuffer.append("");
+ try {
+ SmartthingsLocation[] locationList = api.GetAllLocations();
+ for (SmartthingsLocation loc : locationList) {
+ optionBuffer.append("");
+ }
+ } catch (SmartthingsException ex) {
+ optionBuffer.append("Unable to retrieve locations !!");
}
setupInProgress = true;
- } else if (template == poolTemplate) {
+ } else if (poolTemplate.equals(template)) {
if (setupInProgress) {
replaceMap.put(KEY_POOL_STATUS, "false");
} else {
replaceMap.put(KEY_POOL_STATUS, "true");
}
- } else if (template == confirmationTemplate) {
+ } else if (confirmationTemplate.equals(template)) {
replaceMap.put(KEY_LOCATION, installedLocation);
replaceMap.put(KEY_APP_ID, installedAppId);
}
@@ -222,8 +227,12 @@ protected void service(@Nullable HttpServletRequest req, @Nullable HttpServletRe
String token = resultObj.installData.authToken;
installedAppId = resultObj.installData.installedApp.installedAppId;
- SmartthingsLocation loc = api.GetLocation(resultObj.installData.installedApp.locationId);
- installedLocation = loc.name;
+ try {
+ SmartthingsLocation loc = api.GetLocation(resultObj.installData.installedApp.locationId);
+ installedLocation = loc.name;
+ } catch (SmartthingsException ex) {
+ installedLocation = "Unable to retrieve location!!";
+ }
setupInProgress = false;
logger.info("");
@@ -309,7 +318,11 @@ protected void service(@Nullable HttpServletRequest req, @Nullable HttpServletRe
logger.error("error during confirmation {}", confirmUrl);
}
- api.CreateAppOAuth(appId);
+ try {
+ api.CreateAppOAuth(appId);
+ } catch (SmartthingsException ex) {
+ logger.error("Unable to setup app oauth settings!!");
+ }
logger.trace("CONFIRMATION {}", confirmUrl);
}
@@ -321,9 +334,13 @@ protected void service(@Nullable HttpServletRequest req, @Nullable HttpServletRe
protected void SetupApp() {
SmartthingsApi api = bridgeHandler.getSmartthingsApi();
- AppResponse appResponse = api.SetupApp();
- if (appResponse.oauthClientId != null && appResponse.oauthClientSecret != null) {
- bridgeHandler.updateConfig(appResponse.oauthClientId, appResponse.oauthClientSecret);
+ try {
+ AppResponse appResponse = api.SetupApp();
+ if (appResponse.oauthClientId != null && appResponse.oauthClientSecret != null) {
+ bridgeHandler.updateConfig(appResponse.oauthClientId, appResponse.oauthClientSecret);
+ }
+ } catch (SmartthingsException ex) {
+ logger.info("Unable to setup Smartthings app !!");
}
}
}
diff --git a/bundles/org.openhab.binding.smartthings/src/main/java/org/openhab/binding/smartthings/internal/api/SmartthingsApi.java b/bundles/org.openhab.binding.smartthings/src/main/java/org/openhab/binding/smartthings/internal/api/SmartthingsApi.java
index 6aeb1a0700915..e2f4b7411028a 100644
--- a/bundles/org.openhab.binding.smartthings/src/main/java/org/openhab/binding/smartthings/internal/api/SmartthingsApi.java
+++ b/bundles/org.openhab.binding.smartthings/src/main/java/org/openhab/binding/smartthings/internal/api/SmartthingsApi.java
@@ -26,6 +26,7 @@
import org.openhab.binding.smartthings.internal.dto.SmartthingsDevice;
import org.openhab.binding.smartthings.internal.dto.SmartthingsLocation;
import org.openhab.binding.smartthings.internal.dto.SmartthingsRoom;
+import org.openhab.binding.smartthings.internal.type.SmartthingsException;
import org.openhab.core.auth.client.oauth2.OAuthClientService;
import org.openhab.core.io.net.http.HttpClientFactory;
import org.slf4j.Logger;
@@ -73,12 +74,12 @@ public SmartthingsApi(HttpClientFactory httpClientFactory, SmartthingsNetworkCon
this.networkConnector = networkConnector;
}
- public SmartthingsDevice[] GetAllDevices() {
+ public SmartthingsDevice[] GetAllDevices() throws SmartthingsException {
SmartthingsDevice[] devices = DoRequest(SmartthingsDevice[].class, baseUrl + deviceEndPoint);
return devices;
}
- public AppResponse SetupApp() {
+ public AppResponse SetupApp() throws SmartthingsException {
SmartthingsApp[] appList = GetAllApps();
Optional appOptional = Arrays.stream(appList).filter(x -> APP_NAME.equals(x.appName))
@@ -100,40 +101,40 @@ public AppResponse SetupApp() {
}
}
- public SmartthingsCapabilitie[] GetAllCapabilities() {
+ public SmartthingsCapabilitie[] GetAllCapabilities() throws SmartthingsException {
try {
String uri = baseUrl + capabilitiesEndPoint;
SmartthingsCapabilitie[] listCapabilities = DoRequest(SmartthingsCapabilitie[].class, uri);
return listCapabilities;
} catch (final Exception e) {
- throw new RuntimeException(e.getMessage(), e);
+ throw new SmartthingsException("SmartthingsApi : Unable to retrieve capabilities", e);
}
}
- public SmartthingsCapabilitie GetCapabilitie(String capabilityId, String version) {
+ public SmartthingsCapabilitie GetCapabilitie(String capabilityId, String version) throws SmartthingsException {
try {
String uri = baseUrl + capabilitiesEndPoint + "/" + capabilityId + "/" + version;
SmartthingsCapabilitie capabilitie = DoRequest(SmartthingsCapabilitie.class, uri);
return capabilitie;
} catch (final Exception e) {
- throw new RuntimeException(e.getMessage(), e);
+ throw new SmartthingsException("SmartthingsApi : Unable to retrieve capability", e);
}
}
- public SmartthingsLocation[] GetAllLocations() {
+ public SmartthingsLocation[] GetAllLocations() throws SmartthingsException {
try {
String uri = baseUrl + locationEndPoint;
SmartthingsLocation[] listLocations = DoRequest(SmartthingsLocation[].class, uri);
return listLocations;
} catch (final Exception e) {
- throw new RuntimeException(e.getMessage(), e);
+ throw new SmartthingsException("SmartthingsApi : Unable to retrieve locations", e);
}
}
- public SmartthingsLocation GetLocation(String locationId) {
+ public SmartthingsLocation GetLocation(String locationId) throws SmartthingsException {
try {
String uri = baseUrl + locationEndPoint + "/" + locationId;
@@ -141,22 +142,22 @@ public SmartthingsLocation GetLocation(String locationId) {
return loc;
} catch (final Exception e) {
- throw new RuntimeException(e.getMessage(), e);
+ throw new SmartthingsException("SmartthingsApi : Unable to retrieve location", e);
}
}
- public SmartthingsRoom[] GetRooms(String locationId) {
+ public SmartthingsRoom[] GetRooms(String locationId) throws SmartthingsException {
try {
String uri = baseUrl + locationEndPoint + "/" + locationId + roomsEndPoint;
SmartthingsRoom[] listRooms = DoRequest(SmartthingsRoom[].class, uri);
return listRooms;
} catch (final Exception e) {
- throw new RuntimeException(e.getMessage(), e);
+ throw new SmartthingsException("SmartthingsApi : Unable to retrieve rooms", e);
}
}
- public SmartthingsRoom GetRoom(String locationId, String roomId) {
+ public SmartthingsRoom GetRoom(String locationId, String roomId) throws SmartthingsException {
try {
String uri = baseUrl + locationEndPoint + "/" + locationId + roomsEndPoint + "/" + roomId;
@@ -164,11 +165,11 @@ public SmartthingsRoom GetRoom(String locationId, String roomId) {
return loc;
} catch (final Exception e) {
- throw new RuntimeException(e.getMessage(), e);
+ throw new SmartthingsException("SmartthingsApi : Unable to retrieve room", e);
}
}
- public SmartthingsApp[] GetAllApps() {
+ public SmartthingsApp[] GetAllApps() throws SmartthingsException {
try {
String uri = baseUrl + appEndPoint;
@@ -178,11 +179,11 @@ public SmartthingsApp[] GetAllApps() {
return listApps;
} catch (final Exception e) {
- throw new RuntimeException(e.getMessage(), e);
+ throw new SmartthingsException("SmartthingsApi : Unable to retrieve apps", e);
}
}
- public SmartthingsApp GetApp(String appId) {
+ public SmartthingsApp GetApp(String appId) throws SmartthingsException {
try {
String uri = baseUrl + appEndPoint + "/" + appId;
@@ -190,11 +191,11 @@ public SmartthingsApp GetApp(String appId) {
return app;
} catch (final Exception e) {
- throw new RuntimeException(e.getMessage(), e);
+ throw new SmartthingsException("SmartthingsApi : Unable to retrieve app", e);
}
}
- public AppResponse CreateApp() {
+ public AppResponse CreateApp() throws SmartthingsException {
try {
String uri = baseUrl + appEndPoint + "?signatureType=ST_PADLOCK&requireConfirmation=true";
@@ -215,11 +216,11 @@ public AppResponse CreateApp() {
} catch (
final Exception e) {
- throw new RuntimeException(e.getMessage(), e);
+ throw new SmartthingsException("SmartthingsApi : Unable to create app", e);
}
}
- public void CreateAppOAuth(String appId) {
+ public void CreateAppOAuth(String appId) throws SmartthingsException {
try {
String uri = baseUrl + appEndPoint + "/" + appId + "/oauth";
@@ -238,7 +239,7 @@ public void CreateAppOAuth(String appId) {
// return appResponse;
} catch (final Exception e) {
- throw new RuntimeException(e.getMessage(), e);
+ throw new SmartthingsException("SmartthingsApi : Unable to create oauth settings", e);
}
}
@@ -260,26 +261,27 @@ public void SendCommand(String deviceId, String jsonMsg) {
String uri = baseUrl + deviceEndPoint + "/" + deviceId + "/commands";
DoRequest(JsonObject.class, uri, jsonMsg, false);
} catch (final Exception e) {
- throw new RuntimeException(e.getMessage(), e);
+ throw new RuntimeException("SmartthingsApi : Unable to send command", e);
}
}
- public @Nullable JsonObject SendStatus(String deviceId, String jsonMsg) {
+ public @Nullable JsonObject SendStatus(String deviceId, String jsonMsg) throws SmartthingsException {
try {
String uri = baseUrl + deviceEndPoint + "/" + deviceId + "/status";
JsonObject res = DoRequest(JsonObject.class, uri, jsonMsg, false);
return res;
} catch (final Exception e) {
- throw new RuntimeException(e.getMessage(), e);
+ throw new SmartthingsException("SmartthingsApi : Unable to send status", e);
}
}
- public T DoRequest(Class resultClass, String uri) {
+ public T DoRequest(Class resultClass, String uri) throws SmartthingsException {
return DoRequest(resultClass, uri, null, false);
}
- public T DoRequest(Class resultClass, String uri, @Nullable String body, Boolean update) {
+ public T DoRequest(Class resultClass, String uri, @Nullable String body, Boolean update)
+ throws SmartthingsException {
try {
HttpMethod httpMethod = HttpMethod.GET;
if (body != null) {
@@ -292,7 +294,7 @@ public T DoRequest(Class resultClass, String uri, @Nullable String body,
T res = networkConnector.DoRequest(resultClass, uri, null, getToken(), body, httpMethod);
return res;
} catch (final Exception e) {
- throw new RuntimeException(e.getMessage(), e);
+ throw new SmartthingsException("SmartthingsApi : Unable to do request", e);
}
}
}
diff --git a/bundles/org.openhab.binding.smartthings/src/main/java/org/openhab/binding/smartthings/internal/discovery/SmartthingsDiscoveryService.java b/bundles/org.openhab.binding.smartthings/src/main/java/org/openhab/binding/smartthings/internal/discovery/SmartthingsDiscoveryService.java
index 3a8ec29f00787..82b79177bb8c1 100644
--- a/bundles/org.openhab.binding.smartthings/src/main/java/org/openhab/binding/smartthings/internal/discovery/SmartthingsDiscoveryService.java
+++ b/bundles/org.openhab.binding.smartthings/src/main/java/org/openhab/binding/smartthings/internal/discovery/SmartthingsDiscoveryService.java
@@ -35,6 +35,7 @@
import org.openhab.binding.smartthings.internal.type.SmartthingsChannelGroupTypeProvider;
import org.openhab.binding.smartthings.internal.type.SmartthingsChannelTypeProvider;
import org.openhab.binding.smartthings.internal.type.SmartthingsConfigDescriptionProvider;
+import org.openhab.binding.smartthings.internal.type.SmartthingsException;
import org.openhab.binding.smartthings.internal.type.SmartthingsThingTypeProvider;
import org.openhab.binding.smartthings.internal.type.SmartthingsTypeRegistry;
import org.openhab.core.config.discovery.AbstractDiscoveryService;
@@ -173,80 +174,85 @@ public void doScan(Boolean addDevice) {
SmartthingsBridgeHandler bridge = smartthingsHubCommand.getBridgeHandler();
SmartthingsApi api = bridge.getSmartthingsApi();
- SmartthingsDevice[] devices = api.GetAllDevices();
+ try {
+ SmartthingsDevice[] devices = api.GetAllDevices();
- for (SmartthingsDevice device : devices) {
+ for (SmartthingsDevice device : devices) {
- String name = device.name;
- String id = device.deviceId;
- String label = device.label;
- String manufacturerName = device.manufacturerName;
- String locationId = device.locationId;
- String roomId = device.roomId;
+ String name = device.name;
+ String id = device.deviceId;
+ String label = device.label;
+ String manufacturerName = device.manufacturerName;
+ String locationId = device.locationId;
+ String roomId = device.roomId;
- logger.debug("Device");
+ logger.debug("Device");
- if (device.components == null || device.components.length == 0) {
- return;
- }
+ if (device.components == null || device.components.length == 0) {
+ return;
+ }
- Boolean enabled = false;
- if (label.equals("Four")) {
- // enabled = true;
- }
- if (label.equals("Petrole")) {
- enabled = true;
- }
+ Boolean enabled = false;
+ if (label.equals("Four")) {
+ // enabled = true;
+ }
+ if (label.equals("Petrole")) {
+ enabled = true;
+ }
- // enabled = true;
+ // enabled = true;
- if (!enabled) {
- continue;
- }
+ if (!enabled) {
+ continue;
+ }
- String deviceType = null;
- for (SmartthingsComponent component : device.components) {
- String compId = component.id;
- String compLabel = component.label;
+ String deviceType = null;
+ for (SmartthingsComponent component : device.components) {
+ String compId = component.id;
+ String compLabel = component.label;
- if (component.capabilities != null && component.capabilities.length > 0) {
- for (SmartthingsCapabilitie cap : component.capabilities) {
- String capId = cap.id;
- String capVersion = cap.version;
+ if (component.capabilities != null && component.capabilities.length > 0) {
+ for (SmartthingsCapabilitie cap : component.capabilities) {
+ String capId = cap.id;
+ String capVersion = cap.version;
- logger.info("");
+ logger.info("");
+ }
}
- }
- if (component.categories != null && component.categories.length > 0) {
- for (SmartthingsCategory cat : component.categories) {
- String catId = cat.name;
- String catType = cat.categoryType;
+ if (component.categories != null && component.categories.length > 0) {
+ for (SmartthingsCategory cat : component.categories) {
+ String catId = cat.name;
+ String catType = cat.categoryType;
- if (compId.equals("main")) {
- deviceType = catId;
- }
+ if (compId.equals("main")) {
+ deviceType = catId;
+ }
- logger.info("");
+ logger.info("");
+ }
}
}
- }
- if (deviceType == null) {
- logger.info("unknow device, bypass");
- continue;
- }
+ if (deviceType == null) {
+ logger.info("unknow device, bypass");
+ continue;
+ }
- if (name.equals("white-and-color-ambiance")) {
- continue;
- }
+ if (name.equals("white-and-color-ambiance")) {
+ continue;
+ }
- deviceType = deviceType.toLowerCase();
- this.typeRegistry.Register(deviceType, device);
- if (addDevice) {
- createDevice(deviceType, Objects.requireNonNull(device));
- }
+ deviceType = deviceType.toLowerCase();
+ this.typeRegistry.Register(deviceType, device);
+ if (addDevice) {
+ createDevice(deviceType, Objects.requireNonNull(device));
+ }
+ }
+ } catch (SmartthingsException ex) {
+ logger.error("Unable to get devices !!");
+ return;
}
logger.debug("End Discovery");
diff --git a/bundles/org.openhab.binding.smartthings/src/main/java/org/openhab/binding/smartthings/internal/handler/SmartthingsCloudBridgeHandler.java b/bundles/org.openhab.binding.smartthings/src/main/java/org/openhab/binding/smartthings/internal/handler/SmartthingsCloudBridgeHandler.java
index 497ca379a399c..c7b1cb9566499 100644
--- a/bundles/org.openhab.binding.smartthings/src/main/java/org/openhab/binding/smartthings/internal/handler/SmartthingsCloudBridgeHandler.java
+++ b/bundles/org.openhab.binding.smartthings/src/main/java/org/openhab/binding/smartthings/internal/handler/SmartthingsCloudBridgeHandler.java
@@ -21,6 +21,7 @@
import org.openhab.binding.smartthings.internal.api.SmartthingsApi;
import org.openhab.binding.smartthings.internal.discovery.SmartthingsDiscoveryService;
import org.openhab.binding.smartthings.internal.dto.SmartthingsCapabilitie;
+import org.openhab.binding.smartthings.internal.type.SmartthingsException;
import org.openhab.binding.smartthings.internal.type.SmartthingsTypeRegistry;
import org.openhab.core.auth.client.oauth2.OAuthFactory;
import org.openhab.core.config.core.status.ConfigStatusMessage;
@@ -73,13 +74,18 @@ public void initialize() {
public void initCapabilites() {
logger.info("Start init capa");
SmartthingsApi api = this.getSmartthingsApi();
- SmartthingsCapabilitie[] capabilitiesList = api.GetAllCapabilities();
- for (SmartthingsCapabilitie cap : capabilitiesList) {
- String capId = cap.id;
- String capVersion = cap.version;
- SmartthingsCapabilitie capa = api.GetCapabilitie(capId, capVersion);
- typeRegistry.RegisterCapabilities(capa);
+ try {
+ SmartthingsCapabilitie[] capabilitiesList = api.GetAllCapabilities();
+
+ for (SmartthingsCapabilitie cap : capabilitiesList) {
+ String capId = cap.id;
+ String capVersion = cap.version;
+ SmartthingsCapabilitie capa = api.GetCapabilitie(capId, capVersion);
+ typeRegistry.RegisterCapabilities(capa);
+ }
+ } catch (SmartthingsException ex) {
+ logger.error("Error during initCapabilities!!");
}
logger.info("End init capa");
}
diff --git a/bundles/org.openhab.binding.smartthings/src/main/java/org/openhab/binding/smartthings/internal/handler/SmartthingsThingHandler.java b/bundles/org.openhab.binding.smartthings/src/main/java/org/openhab/binding/smartthings/internal/handler/SmartthingsThingHandler.java
index c3c3982e8d993..ab7f2bdbf816d 100644
--- a/bundles/org.openhab.binding.smartthings/src/main/java/org/openhab/binding/smartthings/internal/handler/SmartthingsThingHandler.java
+++ b/bundles/org.openhab.binding.smartthings/src/main/java/org/openhab/binding/smartthings/internal/handler/SmartthingsThingHandler.java
@@ -28,6 +28,7 @@
import org.openhab.binding.smartthings.internal.api.SmartthingsApi;
import org.openhab.binding.smartthings.internal.converter.SmartthingsConverter;
import org.openhab.binding.smartthings.internal.dto.SmartthingsStateData;
+import org.openhab.binding.smartthings.internal.type.SmartthingsException;
import org.openhab.core.config.core.status.ConfigStatusMessage;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.library.types.PercentType;
@@ -106,20 +107,24 @@ public void handleCommand(ChannelUID channelUID, Command command) {
String deviceId = properties.get("deviceId");
if (deviceId != null) {
- JsonObject res = api.SendStatus(deviceId, jsonMsg);
- if (res != null) {
- JsonObject cp = res.get("components").getAsJsonObject();
- JsonObject main = cp.get("main").getAsJsonObject();
- JsonObject sw = main.get("switch").getAsJsonObject();
- JsonObject sw2 = sw.get("switch").getAsJsonObject();
- String value = sw2.get("value").getAsString();
- if (value.equals("on")) {
- updateState(channelUID, OnOffType.ON);
- } else {
- updateState(channelUID, OnOffType.OFF);
+ try {
+ JsonObject res = api.SendStatus(deviceId, jsonMsg);
+ if (res != null) {
+ JsonObject cp = res.get("components").getAsJsonObject();
+ JsonObject main = cp.get("main").getAsJsonObject();
+ JsonObject sw = main.get("switch").getAsJsonObject();
+ JsonObject sw2 = sw.get("switch").getAsJsonObject();
+ String value = sw2.get("value").getAsString();
+ if (value.equals("on")) {
+ updateState(channelUID, OnOffType.ON);
+ } else {
+ updateState(channelUID, OnOffType.OFF);
+ }
+
+ logger.trace("");
}
-
- logger.trace("");
+ } catch (SmartthingsException ex) {
+ logger.error("Unable to update device : {}", deviceId);
}
}
diff --git a/bundles/org.openhab.binding.smartthings/src/main/java/org/openhab/binding/smartthings/internal/type/SmartthingsTypeRegistryImpl.java b/bundles/org.openhab.binding.smartthings/src/main/java/org/openhab/binding/smartthings/internal/type/SmartthingsTypeRegistryImpl.java
index 2ae7d47d92f8d..94e832afc31d1 100644
--- a/bundles/org.openhab.binding.smartthings/src/main/java/org/openhab/binding/smartthings/internal/type/SmartthingsTypeRegistryImpl.java
+++ b/bundles/org.openhab.binding.smartthings/src/main/java/org/openhab/binding/smartthings/internal/type/SmartthingsTypeRegistryImpl.java
@@ -82,7 +82,6 @@ public class SmartthingsTypeRegistryImpl implements SmartthingsTypeRegistry {
public SmartthingsTypeRegistryImpl() {
this.bundleContext = FrameworkUtil.getBundle(SmartthingsTypeRegistryImpl.class).getBundleContext();
- logger.info("SmartthingsTypeRegistryImpl()");
}
@Override
@@ -109,7 +108,7 @@ public void CreateChannelDefinition(SmartthingsCapabilitie capa) {
continue;
}
- logger.info("capa:" + capa.id + " <> " + key);
+ logger.info("capa: {} <> {}", capa.id, key);
if (attr.schema == null) {
logger.info("no schema");
@@ -134,23 +133,23 @@ public void CreateChannelDefinition(SmartthingsCapabilitie capa) {
if (channelDef != null) {
channelTp = channelDef.tp;
} else {
- if (tpSmart.equals("integer")) {
+ if ("integer".equals(tpSmart)) {
channelTp = "Number";
- } else if (tpSmart.equals("string")) {
+ } else if ("string".equals(tpSmart)) {
channelTp = "String";
- } else if (tpSmart.equals("object")) {
- if (prop.title != null && prop.title.equals("JsonObject")) {
+ } else if ("object".equals(tpSmart)) {
+ if (prop.title != null && "JsonObject".equals(prop.title)) {
channelTp = "String";
} else {
channelTp = "";
}
- } else if (tpSmart.equals("array")) {
+ } else if ("array".equals(tpSmart)) {
channelTp = "";
- } else if (tpSmart.equals("string")) {
+ } else if ("string".equals(tpSmart)) {
channelTp = "String";
- } else if (tpSmart.equals("number")) {
+ } else if ("number".equals(tpSmart)) {
channelTp = "Number";
- } else if (tpSmart.equals("boolean")) {
+ } else if ("boolean".equals(tpSmart)) {
channelTp = "String";
} else {
logger.info("need review");
@@ -165,10 +164,10 @@ public void CreateChannelDefinition(SmartthingsCapabilitie capa) {
Boolean display = false;
if (display) {
- logger.info("");
- logger.info(" " + channelTp + "");
- logger.info(" ");
- logger.info(" " + category + "");
+ logger.info("", channelName);
+ logger.info(" {}", channelTp);
+ logger.info(" ", label);
+ logger.info(" {}", category);
if (prop.enumeration != null && channelDef == null) {
logger.info(" ");
@@ -177,7 +176,7 @@ public void CreateChannelDefinition(SmartthingsCapabilitie capa) {
String optValue = opt;
String optName = StringUtils.capitalize(
StringUtils.join(StringUtils.splitByCharacterTypeCamelCase(opt), StringUtils.SPACE));
- logger.info(" ");
+ logger.info(" ", optValue, optName);
}
logger.info(" ");
logger.info(" ");
@@ -186,7 +185,7 @@ public void CreateChannelDefinition(SmartthingsCapabilitie capa) {
logger.info("");
}
- if (channelTp == null || channelTp.equals("")) {
+ if (channelTp == null || "".equals(channelTp)) {
continue;
}
@@ -284,7 +283,7 @@ public void Register(String deviceType, SmartthingsDevice device) {
try {
generateThingsType(device.deviceId, device.label, deviceType, device);
} catch (Exception ex) {
- logger.info("wrong:" + ex.toString());
+ logger.info("wrong: {}", ex.toString());
}
}
@@ -329,7 +328,7 @@ private void generateThingsType(String deviceId, String deviceLabel, String devi
SmartthingsCapabilitie capa = capabilitiesDict.get(capId);
if (capa != null) {
- logger.info("capa:" + cap.id);
+ logger.info("capa: {}", cap.id);
for (String key : capa.attributes.keySet()) {
if (key.indexOf("range") >= 0) {
continue;