|
@@ -222,17 +222,67 @@ public class KakaoMsgHandler {
|
|
|
*/
|
|
|
public Map<String, Object> getDeviceStatus(int dong, int ho, String endpointId){
|
|
|
Map<String, Object> retMap = new HashMap<String, Object>();
|
|
|
+ String modelId = "";
|
|
|
+ int devNum = 1;
|
|
|
+
|
|
|
+ Document doc = null;
|
|
|
+
|
|
|
+ // endpoint Id로 존재하는 THINGS 인지 확인
|
|
|
+ // 발생 ERROR FAIL_NONEXIST
|
|
|
+ try {
|
|
|
+ String[] tmpSplit = endpointId.split("_");
|
|
|
+
|
|
|
+ modelId = tmpSplit[0];
|
|
|
+ devNum = Integer.parseInt(tmpSplit[1]); // 회로 번호
|
|
|
+
|
|
|
+ if(!THINGS_INFO.isExistThings(modelId)) {
|
|
|
+ retMap.put(KEY_INFO.HTTP_KEY_ERROR, KAKAO_RESULT.getErrorInfo(KAKAO_RESULT.FAIL_NONEXIST));
|
|
|
+ logger.error("[ERROR]-[(" + endpointId + ") - Non Exist]");
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+ }catch(Exception e) {
|
|
|
+ retMap.put(KEY_INFO.HTTP_KEY_ERROR, KAKAO_RESULT.getErrorInfo(KAKAO_RESULT.FAIL_NONEXIST));
|
|
|
+ logger.error("[ERROR]-[(" + endpointId + ") - Non Exist]");
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
|
|
|
- String[] tmpSplit = endpointId.split("_");
|
|
|
-
|
|
|
- String modelId = tmpSplit[0]; // 기기 ID
|
|
|
- int devNum = Integer.parseInt(tmpSplit[1]); // 회로 번호
|
|
|
-
|
|
|
- Document doc = new WallpadMsgSender().remoteDeviceStatus(dong, ho, modelId, devNum);
|
|
|
+ try {
|
|
|
+ doc = new WallpadMsgSender().remoteDeviceStatus(dong, ho, modelId, devNum);
|
|
|
+
|
|
|
+ if(doc == null) {
|
|
|
+ retMap.put(KEY_INFO.HTTP_KEY_ERROR, KAKAO_RESULT.getErrorInfo(KAKAO_RESULT.FAIL_UNREACHABLE));
|
|
|
+ logger.error("[ERROR]-[Document is Null] - [" + dong + "-" + ho + "] ["+ modelId +"]");
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+ }catch(Exception e) {
|
|
|
+ retMap.put(KEY_INFO.HTTP_KEY_ERROR, KAKAO_RESULT.getErrorInfo(KAKAO_RESULT.FAIL_NONEXIST));
|
|
|
+ logger.error("[ERROR]-[(" + endpointId + ") - Non Exist]");
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
|
|
|
- if(doc == null) {
|
|
|
- retMap.put(KEY_INFO.HTTP_KEY_ERROR, KAKAO_RESULT.getErrorInfo(KAKAO_RESULT.FAIL_UNREACHABLE));
|
|
|
- logger.error("[ERROR]-[Document is Null] - [" + dong + "-" + ho + "] ["+ modelId +"]");
|
|
|
+ return getStatusMap(endpointId, doc);
|
|
|
+ }
|
|
|
+
|
|
|
+ public Map<String, Object> getDeviceStatus_bak(int dong, int ho, String endpointId){
|
|
|
+ Map<String, Object> retMap = new HashMap<String, Object>();
|
|
|
+ Document doc = null;
|
|
|
+
|
|
|
+ try {
|
|
|
+ String[] tmpSplit = endpointId.split("_");
|
|
|
+
|
|
|
+ String modelId = tmpSplit[0]; // 기기 ID
|
|
|
+ int devNum = Integer.parseInt(tmpSplit[1]); // 회로 번호
|
|
|
+
|
|
|
+ doc = new WallpadMsgSender().remoteDeviceStatus(dong, ho, modelId, devNum);
|
|
|
+
|
|
|
+ if(doc == null) {
|
|
|
+ retMap.put(KEY_INFO.HTTP_KEY_ERROR, KAKAO_RESULT.getErrorInfo(KAKAO_RESULT.FAIL_UNREACHABLE));
|
|
|
+ logger.error("[ERROR]-[Document is Null] - [" + dong + "-" + ho + "] ["+ modelId +"]");
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+ }catch(Exception e) {
|
|
|
+ retMap.put(KEY_INFO.HTTP_KEY_ERROR, KAKAO_RESULT.getErrorInfo(KAKAO_RESULT.FAIL_NONEXIST));
|
|
|
+ logger.error("[ERROR]-[(" + endpointId + ") - Non Exist]");
|
|
|
return retMap;
|
|
|
}
|
|
|
|
|
@@ -267,12 +317,13 @@ public class KakaoMsgHandler {
|
|
|
retMap.put(KEY_INFO.HTTP_KEY_ERROR, KAKAO_RESULT.getErrorInfo(KAKAO_RESULT.FAIL_INVALID_REQ));
|
|
|
return retMap;
|
|
|
}
|
|
|
- String action = KakaoMsgHandler.setDeviceActionStr(modelId, desired);
|
|
|
+ String action = KakaoMsgHandler.setDeviceActionStr(modelId, actionName, desired);
|
|
|
|
|
|
if(action.length() == 0) {
|
|
|
retMap.put(KEY_INFO.HTTP_KEY_ERROR, KAKAO_RESULT.getErrorInfo(KAKAO_RESULT.FAIL_INVALID_REQ));
|
|
|
return retMap;
|
|
|
}
|
|
|
+
|
|
|
Document doc = new WallpadMsgSender().remoteDeviceControl(
|
|
|
dong,
|
|
|
ho,
|
|
@@ -427,7 +478,76 @@ public class KakaoMsgHandler {
|
|
|
* @param desired
|
|
|
* @return
|
|
|
*/
|
|
|
- public static String setDeviceActionStr(String modelId, Map<String, Object> desired) {
|
|
|
+
|
|
|
+ public static String setDeviceActionStr(String modelId, String actionName, Map<String, Object> desired) {
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
+
|
|
|
+ THINGS_INFO.THINGS things = THINGS_INFO.getThingsType(modelId);
|
|
|
+ try {
|
|
|
+ switch(things.getEndPoint()) {
|
|
|
+ case THINGS_INFO.THINGS_LIGHT:
|
|
|
+ if(actionName.equals("Power") && desired.containsKey("power")) {
|
|
|
+ String tmpState = (String)desired.get("power");
|
|
|
+ if(tmpState.equals("on") || tmpState.equals("off")) sb.append(tmpState);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ case THINGS_INFO.THINGS_TEMPER:
|
|
|
+ if(actionName.equals("Power") && desired.containsKey("power")) {
|
|
|
+ String tmpState = (String)desired.get("power");
|
|
|
+ if(tmpState.equals("on") || tmpState.equals("off")) sb.append(tmpState);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(actionName.equals("TemperatureSetpoint") && desired.containsKey("targetSetpoint")) {
|
|
|
+ double tempPoint = (double)desired.get("targetSetpoint");
|
|
|
+ sb.append("on/").append(Double.toString(tempPoint));
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+ case THINGS_INFO.THINGS_GAS:
|
|
|
+ if(actionName.equals("Lock") && desired.containsKey("locked")){
|
|
|
+ if((boolean)desired.get("locked"))
|
|
|
+ sb.append("close");
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ case THINGS_INFO.THINGS_VENTIL:
|
|
|
+ if(actionName.equals("Power") && desired.containsKey("power")) {
|
|
|
+ String tmpState = (String)desired.get("power");
|
|
|
+ if(tmpState.equals("on") || tmpState.equals("off")) sb.append(tmpState);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(actionName.equals("AirFlow") && desired.containsKey("fanSpeed")) {
|
|
|
+ String tmpFanSpeed = (String)desired.get("fanSpeed");
|
|
|
+
|
|
|
+ if(tmpFanSpeed.equals("low") || tmpFanSpeed.equals("middle") || tmpFanSpeed.equals("high"))
|
|
|
+ sb.append("on/").append(desired.get("fanSpeed"));
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ case THINGS_INFO.THINGS_ELECPLUG:
|
|
|
+ if(desired.containsKey("power")) sb.append(desired.get("power"));
|
|
|
+ else if(desired.containsKey("mode")) sb.append(desired.get("mode"));
|
|
|
+ break;
|
|
|
+
|
|
|
+ case THINGS_INFO.THINGS_ELEVATOR:
|
|
|
+ if(actionName.equals("ElevatorCall") && desired.containsKey("callDirection")) {
|
|
|
+ if("down".equalsIgnoreCase((String)desired.get("callDirection"))) {
|
|
|
+ sb.append(desired.get("callDirection"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }catch(Exception e) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ logger.info("[---->>]" + sb.toString());
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String setDeviceActionStr_bak(String modelId, Map<String, Object> desired) {
|
|
|
StringBuffer sb = new StringBuffer();
|
|
|
|
|
|
THINGS_INFO.THINGS things = THINGS_INFO.getThingsType(modelId);
|
|
@@ -454,10 +574,12 @@ public class KakaoMsgHandler {
|
|
|
if(desired.containsKey("power")) sb.append(desired.get("power"));
|
|
|
else if(desired.containsKey("fanSpeed")) sb.append("on/").append(desired.get("fanSpeed"));
|
|
|
break;
|
|
|
+
|
|
|
case THINGS_INFO.THINGS_ELECPLUG:
|
|
|
if(desired.containsKey("power")) sb.append(desired.get("power"));
|
|
|
else if(desired.containsKey("mode")) sb.append(desired.get("mode"));
|
|
|
break;
|
|
|
+
|
|
|
case THINGS_INFO.THINGS_ELEVATOR:
|
|
|
if(desired.containsKey("callDirection")) {
|
|
|
if("down".equalsIgnoreCase((String)desired.get("callDirection"))) {
|
|
@@ -503,7 +625,10 @@ public class KakaoMsgHandler {
|
|
|
|
|
|
case THINGS_INFO.THINGS_VENTIL:
|
|
|
state.put("power", splitStr[0]);
|
|
|
- if(splitStr[0].equalsIgnoreCase("on")) state.put("fanSpeed", splitStr[1]);
|
|
|
+ if(splitStr[0].equalsIgnoreCase("on")) {
|
|
|
+ if(splitStr[1].equals("mid")) state.put("fanSpeed", "middle");
|
|
|
+ else state.put("fanSpeed", splitStr[1]);
|
|
|
+ }
|
|
|
break;
|
|
|
case THINGS_INFO.THINGS_ELEVATOR:
|
|
|
state.put("callDirection", "down");
|