From 14de918a79943e4961b09fa01ed320c6cad41f2e Mon Sep 17 00:00:00 2001 From: wjc <1243177876@qq.com> Date: 星期三, 28 六月 2023 17:14:51 +0800 Subject: [PATCH] Revert "Revert "Merge branch 'hxb' into wjc"" --- HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/HDLLinkLocalSdk.java | 2407 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 2,407 insertions(+), 0 deletions(-) diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/HDLLinkLocalSdk.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/HDLLinkLocalSdk.java new file mode 100644 index 0000000..f8d8c8c --- /dev/null +++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/HDLLinkLocalSdk.java @@ -0,0 +1,2407 @@ +package com.hdl.sdk.link; + +import android.content.Context; +import android.text.TextUtils; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.reflect.TypeToken; +import com.hdl.sdk.link.bean.GatewayLocationBean; +import com.hdl.sdk.link.bean.LinkIrDeviceBean; +import com.hdl.sdk.link.bean.LinkOtaBean; +import com.hdl.sdk.link.bean.LinkSidNameBean; +import com.hdl.sdk.link.common.config.TopicConstant; +import com.hdl.sdk.link.common.exception.HDLLinkCode; +import com.hdl.sdk.link.common.exception.HDLLinkException; +import com.hdl.sdk.link.common.utils.ErrorUtils; +import com.hdl.sdk.link.common.utils.IdUtils; +import com.hdl.sdk.link.common.utils.LogUtils; +import com.hdl.sdk.link.common.utils.gson.GsonConvert; +import com.hdl.sdk.link.bean.LinkCreateLogicBean; +import com.hdl.sdk.link.bean.LinkCreateSceneBean; +import com.hdl.sdk.link.bean.LinkEnableLogicBean; +import com.hdl.sdk.link.bean.LinkEnableSecurityBean; +import com.hdl.sdk.link.bean.LinkFunctionBean; +import com.hdl.sdk.link.bean.LinkLogicBean; +import com.hdl.sdk.link.bean.LinkOidBean; +import com.hdl.sdk.link.bean.LinkReNameGWBean; +import com.hdl.sdk.link.bean.LinkRoomBean; +import com.hdl.sdk.link.bean.LinkRoomBindBean; +import com.hdl.sdk.link.bean.LinkSceneBean; +import com.hdl.sdk.link.bean.LinkSidStrBean; +import com.hdl.sdk.link.bean.LinkSidUidBean; +import com.hdl.sdk.link.core.bean.FileRequest; +import com.hdl.sdk.link.core.bean.LinkRequest; +import com.hdl.sdk.link.core.bean.LinkResponse; +import com.hdl.sdk.link.core.bean.request.AuthenticateRequest; +import com.hdl.sdk.link.core.bean.request.DeviceControlRequest; +import com.hdl.sdk.link.core.bean.request.FunctionAttributeRequest; +import com.hdl.sdk.link.core.bean.request.PropertyReadRequest; +import com.hdl.sdk.link.core.bean.response.BaseLocalResponse; +import com.hdl.sdk.link.core.bean.scenebatch.SceneCanDeleteInfo; +import com.hdl.sdk.link.core.bean.scenebatch.SceneGroupInfo; +import com.hdl.sdk.link.core.callback.GatewayCallBack; +import com.hdl.sdk.link.core.callback.HDLLinkCallBack; +import com.hdl.sdk.link.core.callback.HDLLinkResponseCallBack; +import com.hdl.sdk.link.common.event.EventDispatcher; +import com.hdl.sdk.link.common.event.EventListener; +import com.hdl.sdk.link.core.callback.HDLLinkTCallBack; +import com.hdl.sdk.link.core.config.HDLLinkConfig; +import com.hdl.sdk.link.core.connect.HDLUdpConnect; +import com.hdl.sdk.link.core.bean.gateway.GatewayBean; +import com.hdl.sdk.link.core.connect.HDLConnectHelper; +import com.hdl.sdk.link.core.utils.LinkResponseUtils; +import com.hdl.sdk.link.gateway.HDLLinkLocalGateway; + +import java.lang.reflect.Type; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; + +/** + * Created by jlchen on 11/15/21. + * + * @Description : HDLLink + */ +public class HDLLinkLocalSdk { + /** + * instance + */ + private volatile static HDLLinkLocalSdk instance; + + /** + * getInstance + * + * @return HDLLink + */ + public static synchronized HDLLinkLocalSdk getInstance() { + if (instance == null) { + synchronized (HDLLinkLocalSdk.class) { + if (instance == null) { + instance = new HDLLinkLocalSdk(); + } + } + } + return instance; + } + + private Context context; + + + public void init(Context context) { + this.context = context.getApplicationContext(); + + String[] gatewayErrors = context.getResources().getStringArray(R.array.gateway); + Map<String, String> codeAndMsgMap = new HashMap<>(); + for (String gatewayError : gatewayErrors) { + String codeMsg[] = gatewayError.split("="); + codeAndMsgMap.put(codeMsg[0], codeMsg[1]); + } + //鍒濆鍖栫姸鎬佺爜澶氳瑷�淇℃伅 + ErrorUtils.errorsMap.putAll(codeAndMsgMap); + } + + public Context getContext() { + return context; + } + + public boolean isZh() { + Locale locale = getContext().getResources().getConfiguration().locale; + String language = locale.getLanguage(); + if (language.endsWith("zh")) + return true; + else + return false; + } + + /** + * 璁剧疆鎵撳嵃鏄惁寮�鍚� + * + * @param enable + */ + public void setLogEnabled(boolean enable) { + LogUtils.setEnabled(enable); + } + + /** + * 娉ㄥ唽鎵�鏈変富棰樻秷鎭殑鐩戝惉 + * + * @param listener + */ + public synchronized void registerAllTopicsListener(EventListener listener) { + EventDispatcher.getInstance().registerAllTopicsListener(listener); + } + + /** + * 鍙栨秷鎵�鏈変富棰樻秷鎭殑鐩戝惉 + * + * @param listener + */ + public synchronized void removeAllTopicsListener(EventListener listener) { + if (listener == null) return; + EventDispatcher.getInstance().removeAllTopicsListener(listener); + } + + /***********************涓夋柟璁惧鍜岀綉鍏抽�氫俊涔嬪墠鐨勮璇佹祦绋�****************************/ + /** + * 妫�娴嬫槸鍚﹀凡缁忚璇佽繃 + * 璁よ瘉閫氳繃鎵嶈兘杩涜璁惧鎺у埗 + * + * @return + */ + public boolean checkIfCertified() { + return HDLLinkConfig.getInstance().checkIfCertified(); + } + + /** + * 寮�濮嬬洃鍚拰鍙戣捣鍏ョ綉鍙婅璇佽姹� + * + * @param request 璁よ瘉璇锋眰淇℃伅 + * @param callBack 缁撴灉鍥炶皟 + */ + public void startAuthenticateRequest(AuthenticateRequest request, HDLLinkCallBack callBack) { + HDLUdpConnect.getInstance().startAuthenticateRequest(request, callBack); + } + + /** + * 鍙戦�佸叆缃戝強璁よ瘉璇锋眰 + * + * @param ip 缃戝叧IP + * @param request 璁よ瘉璇锋眰淇℃伅 + * @param callBack 缁撴灉鍥炶皟 + */ + public void sendAuthenticateRequest(String ip, AuthenticateRequest request, HDLLinkCallBack callBack) { + HDLUdpConnect.getInstance().sendAuthenticateRequest(ip, request, callBack); + } + + /***********************涓夋柟璁惧璇峰厛璁よ瘉鎴愬姛 鍐嶈皟鐢ㄤ笅闈㈢殑鎺ュ彛鍜岀綉鍏抽�氫俊****************************/ + /** + * 缁勬挱鎼滅储鎸囧畾缃戝叧鏄惁鍦ㄧ嚎锛屾悳绱㈠埌鍒欒繑鍥炴寚瀹氱殑缃戝叧瀵硅薄 + * + * @param callBack 鍥炶皟 + */ + public void searchGatewayMulticast(HDLUdpConnect.SearchGatewayCallBack callBack) { + HDLUdpConnect.getInstance().searchGatewayMulticast(callBack); + } + + /** + * 缁勬挱鎼滅储鎸囧畾缃戝叧鏄惁鍦ㄧ嚎锛屾悳绱㈠埌鍒欒繑鍥炴寚瀹氱殑缃戝叧瀵硅薄 + * + * @param callBack 鍥炶皟 + */ + public void searchGatewayBroadcast(HDLUdpConnect.SearchGatewayCallBack callBack) { + HDLUdpConnect.getInstance().searchGatewayBroadcast(callBack); + } + + /** + * 鑾峰彇璁惧鍒楄〃 + */ + public void getDeviceList(HDLLinkTCallBack<List<LinkOidBean>> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("id", IdUtils.getUUId()); + jsonObject.addProperty("time_stamp", time); + String topic = String.format(TopicConstant.GET_DEVICE_LIST, gatewayId); + LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("getDeviceList onSuccess"); + Type type = new TypeToken<BaseLocalResponse<List<LinkOidBean>>>() { + }.getType(); + List<LinkOidBean> list = LinkResponseUtils.convertLinkResponse(msg, type); + if (list == null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_PARSING_ERROR)); + } else { + callBack.onSuccess(list); + } + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 绾㈠瀹�/閬ユ帶鍣ㄥ畾浣� + */ + public void locationIr(String sid, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("id", IdUtils.getUUId()); + jsonObject.put("time_stamp", time); + List<JSONObject> stringList = new ArrayList<>(); + JSONObject jsonObject1 = new JSONObject(); + jsonObject1.put("sid", sid); + jsonObject1.put("duration_time", "5"); + stringList.add(jsonObject1); + jsonObject.put("objects", stringList); + String topic = String.format(TopicConstant.IR_FIND_REMOTE, gatewayId); + LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("locationIr onSuccess"); + callBack.onSuccess(""); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 绾㈠瀹濆垹闄わ紙閲囩敤link鍗忚閫氱煡鍒犻櫎骞堕��缃戝瓙璁惧鎷撴墤鍏崇郴锛� + */ + public void deleteLinkDevice(String oid, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("id", IdUtils.getUUId()); + jsonObject.put("time_stamp", time); + List<JSONObject> stringList = new ArrayList<>(); + JSONObject jsonObject1 = new JSONObject(); + jsonObject1.put("oid", oid); + stringList.add(jsonObject1); + jsonObject.put("objects", stringList); + String topic = String.format(TopicConstant.DELETING_GATEWAY_SLAVE, gatewayId); + LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("deleteLinkDevice onSuccess"); + callBack.onSuccess(""); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 閬ユ帶鍣ㄥ垹闄わ紙閲囩敤link鍗忚閫氱煡鍒犻櫎骞堕��缃戝瓙璁惧鎷撴墤鍏崇郴锛� + */ + public void deleteIrControlDevice(String sid, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("id", IdUtils.getUUId()); + jsonObject.put("time_stamp", time); + List<JSONObject> stringList = new ArrayList<>(); + JSONObject jsonObject1 = new JSONObject(); + jsonObject1.put("sid", sid); + stringList.add(jsonObject1); + jsonObject.put("objects", stringList); + String topic = String.format(TopicConstant.DELETING_GATEWAY_SLAVE, gatewayId); + LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("deleteIrControlDevice onSuccess"); + callBack.onSuccess(""); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 璁惧鎺у埗 + */ + public void controlDevice(Object object, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("id", IdUtils.getUUId()); + jsonObject.put("time_stamp", time); + List<Object> stringList = new ArrayList<>(); + stringList.add(object); + jsonObject.put("objects", stringList); + String topic = String.format(TopicConstant.PROPERTY_DOWN, gatewayId); + LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("controlDevice onSuccess"); + callBack.onSuccess(""); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鏇存敼涓荤綉鍏冲娉ㄥ悕 + */ + public void changeGWName(String gateWayName, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + final BaseLocalResponse<LinkReNameGWBean> data = new BaseLocalResponse<>(); + data.setId(IdUtils.getUUId()); + data.setTime_stamp(time); + LinkReNameGWBean linkReNameGWBean = new LinkReNameGWBean(); + linkReNameGWBean.setDevice_name(gateWayName); + data.setObjects(linkReNameGWBean); + String topic = String.format(TopicConstant.GATEWAY_RENAME, gatewayId); + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("changeGWName onSuccess"); + callBack.onSuccess(""); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鏇存敼浠庣綉鍏冲娉ㄥ悕 + */ + public void changeCongGWName(String gateWayName, String gatewayId, String ipAddress, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + final BaseLocalResponse<LinkReNameGWBean> data = new BaseLocalResponse<>(); + data.setId(IdUtils.getUUId()); + data.setTime_stamp(time); + LinkReNameGWBean linkReNameGWBean = new LinkReNameGWBean(); + linkReNameGWBean.setDevice_name(gateWayName); + data.setObjects(linkReNameGWBean); + String topic = String.format(TopicConstant.GATEWAY_RENAME, gatewayId); + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + request.setCloudTopic(String.format(TopicConstant.NATIVE_LINK_DOWN_SLAVE, HDLLinkConfig.getInstance().getGatewayId(), gatewayId)); + new HDLConnectHelper(ipAddress, request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("changeCongGWName onSuccess"); + callBack.onSuccess("Success"); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * sid鏇存敼鍚嶅瓧 + */ + public void sidNameChange(List<LinkSidNameBean> bean, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + final BaseLocalResponse<List<LinkSidNameBean>> data = new BaseLocalResponse<>(); + data.setId(IdUtils.getUUId()); + data.setTime_stamp(time); + data.setObjects(bean); + String topic = String.format(TopicConstant.EDIT_FUNCTION, gatewayId); + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("sidNameChange onSuccess"); + callBack.onSuccess(""); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * sid缁戝畾鎴块棿 + */ + public void sidBindUid(List<LinkSidUidBean> bean, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + final BaseLocalResponse<List<LinkSidUidBean>> data = new BaseLocalResponse<>(); + data.setId(IdUtils.getUUId()); + data.setTime_stamp(time); + data.setObjects(bean); + String topic = String.format(TopicConstant.SID_BIND_ROOM, gatewayId); + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("sidBindUid onSuccess"); + callBack.onSuccess("Success"); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * sid鍒犻櫎缁戝畾鎴块棿鍏崇郴 + */ + public void sidDeleteUid(List<LinkSidUidBean> bean, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + final BaseLocalResponse<List<LinkSidUidBean>> data = new BaseLocalResponse<>(); + data.setId(IdUtils.getUUId()); + data.setTime_stamp(time); + data.setObjects(bean); + String topic = String.format(TopicConstant.SID_DELETE_ROOM, gatewayId); + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("sidDeleteUid onSuccess"); + callBack.onSuccess("Success"); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鍒涘缓鍦烘櫙 + */ + public void createScene(List<LinkCreateSceneBean> bean, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + final BaseLocalResponse<List<LinkCreateSceneBean>> data = new BaseLocalResponse<>(); + data.setId(IdUtils.getUUId()); + data.setTime_stamp(time); + data.setObjects(bean); + String topic = String.format(TopicConstant.CREATE_SCENE, gatewayId); + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("createScene onSuccess"); + callBack.onSuccess("Success"); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 缂栬緫鍦烘櫙 鎵归噺澶勭悊缁� + */ + public void editSceneBatchGroup(List<SceneGroupInfo> bean, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + final BaseLocalResponse<List<SceneGroupInfo>> data = new BaseLocalResponse<>(); + data.setId(IdUtils.getUUId()); + data.setTime_stamp(time); + data.setObjects(bean); + String topic = String.format(TopicConstant.SCENE_EDIT, gatewayId); + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("editSceneBatchGroup onSuccess"); + callBack.onSuccess("Success"); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 缂栬緫鍦烘櫙 鎵归噺澶勭悊鍒犻櫎 + */ + public void editSceneBatchDelete(List<SceneCanDeleteInfo> bean, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + final BaseLocalResponse<List<SceneCanDeleteInfo>> data = new BaseLocalResponse<>(); + data.setId(IdUtils.getUUId()); + data.setTime_stamp(time); + data.setObjects(bean); + String topic = String.format(TopicConstant.SCENE_EDIT, gatewayId); + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("editSceneBatchDelete onSuccess"); + callBack.onSuccess("Success"); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 缂栬緫鍦烘櫙 + */ + public void editScene(List<LinkCreateSceneBean> bean, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + final BaseLocalResponse<List<LinkCreateSceneBean>> data = new BaseLocalResponse<>(); + data.setId(IdUtils.getUUId()); + data.setTime_stamp(time); + data.setObjects(bean); + String topic = String.format(TopicConstant.SCENE_EDIT, gatewayId); + for (int i = 0; i < data.getObjects().size(); i++) { + if (data.getObjects().get(i).getFunctions().size() == 0) { + data.getObjects().get(i).setFunctions(null); + } +// if (data.getObjects().get(i).getUids().size() == 0) { +// data.getObjects().get(i).setUids(null); +// } + } + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("editScene onSuccess"); + callBack.onSuccess("Success"); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鍒犻櫎鍦烘櫙 + */ + public void deleteScene(List<LinkSidStrBean> bean, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + final BaseLocalResponse<List<LinkSidStrBean>> data = new BaseLocalResponse<>(); + data.setId(IdUtils.getUUId()); + data.setTime_stamp(time); + data.setObjects(bean); + String topic = String.format(TopicConstant.SCENE_DELETE, gatewayId); + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("deleteScene onSuccess"); + callBack.onSuccess("Success"); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鑾峰彇鑷姩鍖栧垪琛� + */ + public void getLogicList(HDLLinkTCallBack<List<LinkLogicBean>> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("id", IdUtils.getUUId()); + jsonObject.addProperty("time_stamp", time); + String topic = String.format(TopicConstant.LOGIC_LIST_GET, gatewayId); + LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("getLogicList onSuccess"); + if (callBack != null) { + Type type = new TypeToken<BaseLocalResponse<List<LinkLogicBean>>>() { + }.getType(); + List<LinkLogicBean> list = LinkResponseUtils.convertLinkResponse(msg, type); + if (list == null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_PARSING_ERROR)); + } else { + callBack.onSuccess(list); + } + } + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鑾峰彇鑷姩鍖栬鎯� + */ + public void getLogicDetail(List<LinkSidStrBean> list, HDLLinkTCallBack<List<LinkCreateLogicBean>> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + final BaseLocalResponse<List<LinkSidStrBean>> data = new BaseLocalResponse<>(); + data.setId(IdUtils.getUUId()); + data.setTime_stamp(time); + data.setObjects(list); + String topic = String.format(TopicConstant.LOGIC_GET, gatewayId); + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("getLogicDetail onSuccess"); + if (callBack != null) { + Type type = new TypeToken<BaseLocalResponse<List<LinkCreateLogicBean>>>() { + }.getType(); + List<LinkCreateLogicBean> list = LinkResponseUtils.convertLinkResponse(msg, type); + if (list == null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_PARSING_ERROR)); + } else { + callBack.onSuccess(list); + } + + } + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鏂板缓鑷姩鍖� + */ + public void createLogic(List<LinkCreateLogicBean> bean, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + final BaseLocalResponse<List<LinkCreateLogicBean>> data = new BaseLocalResponse<>(); + data.setId(IdUtils.getUUId()); + data.setTime_stamp(time); + data.setObjects(bean); + String topic = String.format(TopicConstant.LOGIC_EDIT, gatewayId); + + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("createLogic onSuccess"); + callBack.onSuccess("Success"); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 寮�鍚叧闂嚜鍔ㄥ寲 + */ + public void enableLogic(List<LinkEnableLogicBean> bean, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + final BaseLocalResponse<List<LinkEnableLogicBean>> data = new BaseLocalResponse<>(); + data.setId(IdUtils.getUUId()); + data.setTime_stamp(time); + data.setObjects(bean); + String topic = String.format(TopicConstant.LOGIC_ENABLE_EDIT, gatewayId); + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("enableLogic onSuccess"); + callBack.onSuccess("Success"); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鍒犻櫎鑷姩鍖� + */ + public void deleteLogic(List<LinkSidStrBean> bean, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + final BaseLocalResponse<List<LinkSidStrBean>> data = new BaseLocalResponse<>(); + data.setId(IdUtils.getUUId()); + data.setTime_stamp(time); + data.setObjects(bean); + String topic = String.format(TopicConstant.LOGIC_DELETE, gatewayId); + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("deleteLogic onSuccess"); + callBack.onSuccess("Success"); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 绾㈠瀹濊瘯鐮� + */ + public void irCodeTest(JSONObject content, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + JSONObject jsonObject = new JSONObject(); + JSONArray jsonArray = new JSONArray(); + jsonArray.add(content); + jsonObject.put("id", IdUtils.getUUId()); + jsonObject.put("time_stamp", time); + jsonObject.put("objects", jsonArray); + String topic = String.format(TopicConstant.IR_CODE_TEST, gatewayId); + LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("irCodeTest onSuccess"); + callBack.onSuccess(""); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 绾㈠瀹濇坊鍔犻仴鎺у櫒 + */ + public void irDeviceAdd(JSONObject content, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + JSONObject jsonObject = new JSONObject(); + JSONArray jsonArray = new JSONArray(); + jsonArray.add(content); + jsonObject.put("id", IdUtils.getUUId()); + jsonObject.put("time_stamp", time); + jsonObject.put("objects", jsonArray); + String topic = String.format(TopicConstant.IR_DEVICE_ADD, gatewayId); + + LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("getSceneList onSuccess"); + callBack.onSuccess(""); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 绾㈠瀹濊嚜瀛︾爜 + */ + public void irCodeStudy(JSONObject content, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + JSONObject jsonObject = new JSONObject(); + JSONArray jsonArray = new JSONArray(); + jsonArray.add(content); + jsonObject.put("id", IdUtils.getUUId()); + jsonObject.put("time_stamp", time); + jsonObject.put("objects", jsonArray); + String topic = String.format(TopicConstant.IR_CODE_STUDY, gatewayId); + + LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("irCodeStudy onSuccess"); + callBack.onSuccess(""); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 绾㈠瀹濊嚜瀛︾爜鍒犻櫎 + */ + public void irCodeRemove(JSONObject content, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + JSONObject jsonObject = new JSONObject(); + JSONArray jsonArray = new JSONArray(); + jsonArray.add(content); + jsonObject.put("id", IdUtils.getUUId()); + jsonObject.put("time_stamp", time); + jsonObject.put("objects", jsonArray); + String topic = String.format(TopicConstant.IR_CODE_REMOVE, gatewayId); + + LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("irCodeRemove onSuccess"); + callBack.onSuccess(""); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + + /** + * 绾㈠瀹濋仴鎺у櫒鍒楄〃鑾峰彇 + */ + public void irDeviceList(JSONObject content, HDLLinkTCallBack<List<LinkIrDeviceBean>> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + JSONObject jsonObject = new JSONObject(); + JSONArray jsonArray = new JSONArray(); + jsonArray.add(content); + jsonObject.put("id", IdUtils.getUUId()); + jsonObject.put("time_stamp", time); + jsonObject.put("objects", jsonArray); + String topic = String.format(TopicConstant.IR_DEVICE_LIST, gatewayId); + + LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("irDeviceList onSuccess"); + if (callBack != null) { + Type type = new TypeToken<BaseLocalResponse<List<LinkIrDeviceBean>>>() { + }.getType(); + List<LinkIrDeviceBean> response = LinkResponseUtils.convertLinkResponse(msg, type); + if (response == null) { + callBack.onSuccess(new ArrayList<>()); + } else { + callBack.onSuccess(response); + } + } + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + + /** + * 鑾峰彇瀹夐槻鍒楄〃 + */ + public void getSecurityList(HDLLinkTCallBack<List<LinkLogicBean>> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("id", IdUtils.getUUId()); + jsonObject.addProperty("time_stamp", time); + + String topic = String.format(TopicConstant.SECURITY_LIST_GET, gatewayId); + + LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("getSecurityList onSuccess"); + if (callBack != null) { + Type type = new TypeToken<BaseLocalResponse<List<LinkLogicBean>>>() { + }.getType(); + List<LinkLogicBean> list = LinkResponseUtils.convertLinkResponse(msg, type); + if (list == null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_PARSING_ERROR)); + } else { + callBack.onSuccess(list); + } + + } + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鑾峰彇鑷姩鍖栬鎯� + */ + public void getSecurityDetail(List<LinkSidStrBean> list, HDLLinkTCallBack<List<LinkCreateLogicBean>> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + final BaseLocalResponse<List<LinkSidStrBean>> data = new BaseLocalResponse<>(); + data.setId(IdUtils.getUUId()); + data.setTime_stamp(time); + data.setObjects(list); + + String topic = String.format(TopicConstant.SECURITY_GET, gatewayId); + + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("getSecurityDetail onSuccess"); + if (callBack != null) { + Type type = new TypeToken<BaseLocalResponse<List<LinkCreateLogicBean>>>() { + }.getType(); + List<LinkCreateLogicBean> list = LinkResponseUtils.convertLinkResponse(msg, type); + if (list == null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_PARSING_ERROR)); + } else { + callBack.onSuccess(list); + } + + } + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鏂板缓瀹夐槻 + */ + public void createSecurity(List<LinkCreateLogicBean> bean, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + final BaseLocalResponse<List<LinkCreateLogicBean>> data = new BaseLocalResponse<>(); + data.setId(IdUtils.getUUId()); + data.setTime_stamp(time); + data.setObjects(bean); + String topic = String.format(TopicConstant.SECURITY_EDIT, gatewayId); + + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("createSecurity onSuccess"); + callBack.onSuccess("Success"); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鍒犻櫎瀹夐槻 + */ + public void deleteSecurity(List<LinkSidStrBean> bean, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + final BaseLocalResponse<List<LinkSidStrBean>> data = new BaseLocalResponse<>(); + data.setId(IdUtils.getUUId()); + data.setTime_stamp(time); + data.setObjects(bean); + String topic = String.format(TopicConstant.SECURITY_DELETE, gatewayId); + + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("deleteSecurity onSuccess"); + callBack.onSuccess("Success"); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 寮�鍚叧闂嚜鍔ㄥ寲 + */ + public void enableSecurity(List<LinkEnableSecurityBean> bean, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + final BaseLocalResponse<List<LinkEnableSecurityBean>> data = new BaseLocalResponse<>(); + data.setId(IdUtils.getUUId()); + data.setTime_stamp(time); + data.setObjects(bean); + String topic = String.format(TopicConstant.SECURITY_STATUS_SET, gatewayId); + + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("enableSecurity onSuccess"); + callBack.onSuccess("Success"); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + + /** + * 鑾峰彇鍔熻兘鍒楄〃 + */ + public void getFunctionList(HDLLinkTCallBack<List<LinkFunctionBean>> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("id", IdUtils.getUUId()); + jsonObject.addProperty("time_stamp", time); + + String topic = String.format(TopicConstant.GET_FUNCTION_LIST, gatewayId); + + LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("getFunctionList onSuccess"); + if (callBack != null) { + Type type = new TypeToken<BaseLocalResponse<List<LinkFunctionBean>>>() { + }.getType(); + List<LinkFunctionBean> list = LinkResponseUtils.convertLinkResponse(msg, type); + if (list == null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_PARSING_ERROR)); + } else { + callBack.onSuccess(list); + } + + } + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 妯℃嫙浜戠ota + */ + public void otaDeviceUpgradeDown(String oid, String module, HDLLinkTCallBack callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + final BaseLocalResponse<List<LinkOtaBean>> data = new BaseLocalResponse<>(); + data.setId(IdUtils.getUUId()); + data.setTime_stamp(time); + List<LinkOtaBean> bean = new ArrayList<>(); + LinkOtaBean linkOtaBean = new LinkOtaBean(); + linkOtaBean.setOid(oid); + linkOtaBean.setModule(module); + linkOtaBean.setSize(291710); + linkOtaBean.setSign_method("md5"); + linkOtaBean.setSign("05afc42e715b724e01b4ecd0ee2bde5d"); + linkOtaBean.setUrl("https://hdl-hz-prod.oss-cn-hangzhou.aliyuncs.com/20/2023/05/37886160-375a-4bf0-8a32-4093dac38679.ota"); + linkOtaBean.setVersion("V02.04.16"); + bean.add(linkOtaBean); + data.setObjects(bean); + String topic = String.format(TopicConstant.OTA_UPGRADE_DOWN, gatewayId); + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("getFunctionList onSuccess"); + if (callBack != null) { + callBack.onSuccess("Success"); + } + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + + /** + * 鏇存敼Sid澶囨敞鍚� + */ + public void editSidName(BaseLocalResponse<List<JsonObject>> data, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); +// LinkReNameGWBean linkReNameGWBean = new LinkReNameGWBean(); +// linkReNameGWBean.setDevice_name(sidName); +// data.setObjects(linkReNameGWBean); + String topic = String.format(TopicConstant.EDIT_FUNCTION_ATTRIBUTE, gatewayId); + + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("editSidName onSuccess"); + callBack.onSuccess("Success"); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鑾峰彇鍔熻兘灞炴�� + * 鏀寔鎵归噺 + * + * @param sids + * @param callBack + */ + public void getFunctionAttribute(List<String> sids, HDLLinkTCallBack<List<LinkFunctionBean>> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + + final BaseLocalResponse<List<FunctionAttributeRequest>> data = new BaseLocalResponse<>(); + data.setId(IdUtils.getUUId()); + data.setTime_stamp(time); + List<FunctionAttributeRequest> list = new ArrayList<>(); + for (String s : sids) { + list.add(new FunctionAttributeRequest(s)); + } + data.setObjects(list); + + String topic = String.format(TopicConstant.GET_FUNCTION_ATTRIBUTE, gatewayId); + + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("getFunctionAttribute onSuccess"); + if (callBack != null) { + Type type = new TypeToken<BaseLocalResponse<List<LinkFunctionBean>>>() { + }.getType(); + List<LinkFunctionBean> list = LinkResponseUtils.convertLinkResponse(msg, type); + if (list == null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_PARSING_ERROR)); + } else { + callBack.onSuccess(list); + } + } + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 璁惧鎺у埗 + * + * @param requestList 鎺у埗鐘舵�佸弬鏁� + * @param callBack 缁撴灉鍥炶皟 + */ + public void propertyDown(List<DeviceControlRequest> requestList, HDLLinkCallBack callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + + final BaseLocalResponse<List<DeviceControlRequest>> data = new BaseLocalResponse<>(); + data.setId(IdUtils.getUUId()); + data.setTime_stamp(time); + data.setObjects(requestList); + String topic = String.format(TopicConstant.PROPERTY_DOWN, gatewayId); + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("propertyDown onSuccess"); + callBack.onSuccess(msg.toString()); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + + } + + /** + * 璇诲彇鐘舵�� + * + * @param sids 璇锋眰鍙傛暟 鎸囧畾璇诲彇鐨勮澶噑id鍒楄〃 + * @param callBack 鍥炶皟 + */ + public void propertyRead(List<String> sids, HDLLinkCallBack callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + final BaseLocalResponse<List<PropertyReadRequest>> data = new BaseLocalResponse<>(); + data.setId(IdUtils.getUUId()); + data.setTime_stamp(time); + + List<PropertyReadRequest> list = new ArrayList<>(); + for (String s : sids) { + list.add(new PropertyReadRequest(s)); + } + data.setObjects(list); + + String topic = String.format(TopicConstant.PROPERTY_READ, gatewayId); + + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("propertyRead onSuccess"); + callBack.onSuccess(msg.toString()); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鑾峰彇鍦烘櫙鍒楄〃 + */ + public void getSceneList(HDLLinkTCallBack<List<LinkSceneBean>> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("id", IdUtils.getUUId()); + jsonObject.addProperty("time_stamp", time); + + String topic = String.format(TopicConstant.SCENE_LIST_GET, gatewayId); + + LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("getSceneList onSuccess"); + if (callBack != null) { + Type type = new TypeToken<BaseLocalResponse<List<LinkSceneBean>>>() { + }.getType(); + List<LinkSceneBean> list = LinkResponseUtils.convertLinkResponse(msg, type); + if (list == null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_PARSING_ERROR)); + } else { + callBack.onSuccess(list); + } + + } + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鑾峰彇鍦烘櫙璇︽儏 + */ + public void getSceneDetail(List<LinkSidStrBean> list, HDLLinkTCallBack<List<LinkCreateSceneBean>> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + final BaseLocalResponse<List<LinkSidStrBean>> data = new BaseLocalResponse<>(); + data.setId(IdUtils.getUUId()); + data.setTime_stamp(time); + data.setObjects(list); + String topic = String.format(TopicConstant.SCENE_GET, gatewayId); + + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("getSceneDetail onSuccess"); + if (callBack != null) { + Type type = new TypeToken<BaseLocalResponse<List<LinkCreateSceneBean>>>() { + }.getType(); + List<LinkCreateSceneBean> list = LinkResponseUtils.convertLinkResponse(msg, type); + if (list == null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_PARSING_ERROR)); + } else { + callBack.onSuccess(list); + } + } + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鍦烘櫙鎺у埗 + * + * @param sids 鍦烘櫙sid鍒楄〃 + * @param callBack 鍥炶皟 + */ + public void controlScene(List<String> sids, HDLLinkCallBack callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + final BaseLocalResponse<List<PropertyReadRequest>> data = new BaseLocalResponse<>(); + data.setId(IdUtils.getUUId()); + data.setTime_stamp(time); + + List<PropertyReadRequest> list = new ArrayList<>(); + for (String s : sids) { + list.add(new PropertyReadRequest(s)); + } + data.setObjects(list); + String topic = String.format(TopicConstant.SCENE_CONTROL, gatewayId); + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(data), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("controlScene onSuccess"); + callBack.onSuccess(msg.toString()); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 閫氱敤UDP鍙戦�佹寚浠� + * 1绉掓病鍝嶅簲灏辫浠栭噸鏂板彂閫�,閲嶈瘯3娆� + * + * @param topic 鍙戦�佹暟鎹� + * @param bodyStr body鍐呭 + * @param callBack 鍥炶皟 + */ + public void udpSendMsg(String topic, String bodyStr, HDLLinkResponseCallBack callBack) { + HDLUdpConnect.getInstance().udpSendMsg(topic, bodyStr, false, callBack); + } + + /** + * 閫氱敤骞挎挱UDP鍙戦�佹寚浠� + * 1绉掓病鍝嶅簲灏辫浠栭噸鏂板彂閫�,閲嶈瘯3娆� + * + * @param topic 鍙戦�佹暟鎹� + * @param bodyStr body鍐呭 + * @param callBack 鍥炶皟 + */ + public void udpBroadcastSendMsg(String topic, String bodyStr, HDLLinkResponseCallBack callBack) { + HDLUdpConnect.getInstance().udpSendMsg(topic, bodyStr, true, callBack); + } + + /** + * 閫氱敤TCP鍙戦�佹寚浠� + * 1绉掓病鍝嶅簲灏辫浠栭噸鏂板彂閫�,閲嶈瘯3娆� + * + * @param topic 鍙戦�佹暟鎹� + * @param body body鍐呭 + * @param callBack 鍥炶皟 + */ + public void tcpSendMsg(String topic, String body, HDLLinkCallBack callBack) { + + LinkRequest request = new LinkRequest(topic, body, HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("sendMsg onSuccess"); + if (callBack != null) { + callBack.onSuccess(msg.toString()); + } + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } + + /** + * 閫氱敤TCP鍙戦�佹寚浠� 鍙彂涓�娆★紝涓嶇洃鍚洖澶嶏紝涓嶉噸鍙� + * + * @param topic 鍙戦�佹暟鎹� + * @param body 鍥炲鐨勪富棰� + */ + public void tcpSendMsg(String topic, String body) { + LinkRequest request = new LinkRequest(topic, body, HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(1, HDLLinkConfig.getInstance().getIpAddress(), request, true); + } + + /** + * 鍒涙柊缃戝叧鍒楄〃锛岄噸鏂拌鍙� + * + * @param homeId 浣忓畢Id + * @param callBack 鍥炶皟鎵�鏈夎鍙栧埌鐨勭綉鍏冲垪琛� + */ + public void refreshGatewayByHome(String homeId, GatewayCallBack callBack) { + HDLLinkLocalGateway.getInstance().refreshGatewayByHome(homeId, callBack); + } + + /** + * 鍒涙柊缃戝叧鍒楄〃锛岄噸鏂拌鍙� + * + * @param callBack 鍥炶皟鎵�鏈夎鍙栧埌鐨勭綉鍏冲垪琛� + */ + public void refreshGateway(GatewayCallBack callBack) { + HDLLinkLocalGateway.getInstance().refreshGateway(callBack); + } + + /** + * 鑾峰彇褰撳墠浣忓畢缂撳瓨鐨勬墍鏈夌綉鍏筹紝涓�鑸槸璋冭瘯杞欢浣跨敤锛屼笁鏂逛笉鐢ㄨ皟璇曟鏂规硶 + * 濡傛灉涔嬪墠杩樻病鏈夎鍙栬繃缃戝叧锛屽厛璋冪敤鏂规硶refreshGatewayByHome璇诲彇涓�娆� + * + * @return + */ + public List<GatewayBean> getGatewayByHome() { + return HDLLinkLocalGateway.getInstance().getGatewayList(); + } + + + /** + * 鑾峰彇鎴块棿鍒楄〃 + * + * @param callBack + */ + public void getRoomList(HDLLinkTCallBack<List<LinkRoomBean>> callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("id", IdUtils.getUUId()); + jsonObject.addProperty("time_stamp", time); + + String topic = String.format(TopicConstant.ROOM_LIST_GET, gatewayId); + + LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("getRoomList onSuccess"); + Type type = new TypeToken<BaseLocalResponse<List<LinkRoomBean>>>() { + }.getType(); + List<LinkRoomBean> list = LinkResponseUtils.convertLinkResponse(msg, type); + if (list == null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_PARSING_ERROR)); + } else { + callBack.onSuccess(list); + } + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鍏ㄩ噺鏇存柊鎴块棿鍒楄〃 + * + * @param list + * @param callBack + */ + public void coverAddRoomList(List<LinkRoomBean> list, HDLLinkCallBack callBack) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + final BaseLocalResponse<List<LinkRoomBean>> senData = new BaseLocalResponse<>(); + senData.setId(IdUtils.getUUId()); + senData.setTime_stamp(time); + senData.setObjects(list); + + String topic = String.format(TopicConstant.ROOM_COVER_ADD, gatewayId); + LinkRequest request = new LinkRequest(topic, GsonConvert.getGson().toJson(senData), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("coverAddRoomList onSuccess"); + callBack.onSuccess(msg.toString()); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鑾峰彇鎴块棿缁戝畾鍏崇郴 + */ + public void getRoomBindList(HDLLinkTCallBack<List<LinkRoomBindBean>> callBack, List<String> uidRoomList) { + if (null == callBack) { + return; + } + String gatewayId = HDLLinkConfig.getInstance().getGatewayId(); + + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("id", IdUtils.getUUId()); + jsonObject.addProperty("time_stamp", time); + JsonArray array = new JsonArray(); + for (String uid : uidRoomList) { + array.add(uid); + } + jsonObject.add("objects", array); + String topic = String.format(TopicConstant.ROOM_BIND_LIST_GET, gatewayId); + LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("getRoomBindList onSuccess"); + Type type = new TypeToken<BaseLocalResponse<List<LinkRoomBindBean>>>() { + }.getType(); + List<LinkRoomBindBean> list = LinkResponseUtils.convertLinkResponse(msg, type); + if (list == null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_PARSING_ERROR)); + } else { + callBack.onSuccess(list); + } + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 璇诲彇缃戝叧缁忕含搴� + */ + public void getGatewayLocation(String gatewayId, HDLLinkTCallBack<GatewayLocationBean> callBack) { + if (null == callBack) { + return; + } + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("id", IdUtils.getUUId()); + jsonObject.addProperty("time_stamp", time); + String topic = String.format(TopicConstant.GATEWAY_LOCATION_GET, gatewayId); + LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("getGatewayLocation onSuccess"); + Type type = new TypeToken<BaseLocalResponse<GatewayLocationBean>>() { + }.getType(); + GatewayLocationBean list = LinkResponseUtils.convertLinkResponse(msg, type); + if (list == null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_PARSING_ERROR)); + } else { + callBack.onSuccess(list); + } + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 璁剧疆缃戝叧缁忕含搴� + */ + public void gatewayLocation(GatewayBean bean, String longitude, String lat, HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = bean.getGatewayId(); + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("id", IdUtils.getUUId()); + jsonObject.addProperty("time_stamp", time); + JsonObject jsonObject1 = new JsonObject(); + jsonObject1.addProperty("longitude", longitude); + jsonObject1.addProperty("latitude", lat); + jsonObject.add("objects", jsonObject1); + String topic = String.format(TopicConstant.GATEWAY_LOCATION_EDIT, gatewayId); + LinkRequest request = new LinkRequest(topic, jsonObject.toString(), HDLLinkConfig.getInstance().isLocalEncrypt()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("getRoomBindList onSuccess"); + callBack.onSuccess("Success"); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + /** + * 鍒氬垰缁戝畾缃戝叧鐨勬椂鍊欒缃綉鍏崇粡绾害 涓嶉渶瑕佸姞瀵� + */ + public void gatewayLocation(String mGatewayId, String longitude, String lat, boolean isEncrypt,HDLLinkTCallBack<String> callBack) { + if (null == callBack) { + return; + } + String gatewayId = mGatewayId; + if (!TextUtils.isEmpty(gatewayId)) { + String time = String.valueOf(System.currentTimeMillis()); + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("id", IdUtils.getUUId()); + jsonObject.addProperty("time_stamp", time); + JsonObject jsonObject1 = new JsonObject(); + jsonObject1.addProperty("longitude", longitude); + jsonObject1.addProperty("latitude", lat); + jsonObject.add("objects", jsonObject1); + String topic = String.format(TopicConstant.GATEWAY_LOCATION_EDIT, gatewayId); + LinkRequest request = new LinkRequest(topic, jsonObject.toString(), isEncrypt); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), request, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + if (msg instanceof LinkResponse) { + LogUtils.i("gatewayLocation onSuccess"); + callBack.onSuccess("Success"); + } + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(hdlLinkCode)); + } + } + }, true).send(); + } else { + if (callBack != null) { + callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_GATEWAY_NOT_EXIST)); + } + } + } + + + /*********************** 鏂囦欢浼犺緭 ****************************/ + /** + * 鏂囦欢鐢ㄩ�旈�氱煡 + * + * @param fileId 鏂囦欢Id + * @param fileName 鏂囦欢鍚嶇О + * @param purpose 鐢ㄩ�� 鐢ㄩ�旀灇涓� + * zigbee璁惧閰嶇疆鎭㈠锛� ConfigRecoveryForZigbeeDevices + * 鏁版嵁澶囦唤锛欴ataBackup + * 鏁版嵁鎭㈠锛欴ataRecovery + * @param callBack + */ + public void sendFileUserNotification(String fileId, String fileName, String purpose, HDLLinkCallBack callBack) { + //甯ф牸寮忥細head+鍛戒护瀛�+鏁版嵁闀垮害+浜岃繘鍒舵暟鎹� + String time = String.valueOf(System.currentTimeMillis()); + String data = "hex" + "0001" + fileId + "\r\n" + fileName + "\r\n" + purpose; + byte[] dataBytes = data.getBytes(StandardCharsets.UTF_8); + FileRequest linkRequest = new FileRequest(fileId, 0x0011, dataBytes, HDLLinkConfig.getInstance().isLocalEncrypt()); + linkRequest.setReplyTopic(linkRequest.getAckTopic()); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), linkRequest, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + } + }, true).send(); + } + + /** + * 鍙戦�佹枃浠剁浉鍏冲懡浠� + */ + public void sendFileCommand(byte[] dataBytes, Integer command, HDLLinkCallBack callBack) { + //甯ф牸寮忥細head+鍛戒护瀛�+鏁版嵁闀垮害+浜岃繘鍒舵暟鎹� + String time = String.valueOf(System.currentTimeMillis()); +// byte []dataBytes=data.getBytes(StandardCharsets.UTF_8); + FileRequest linkRequest = new FileRequest("65531", command, dataBytes, HDLLinkConfig.getInstance().isLocalEncrypt()); + linkRequest.setReplyTopic(linkRequest.getAckTopic()); + linkRequest.setCloudTopic(String.format(TopicConstant.NATIVE_LINK_DOWN, HDLLinkConfig.getInstance().getGatewayId())); + new HDLConnectHelper(HDLLinkConfig.getInstance().getIpAddress(), linkRequest, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + } + }, true).send(); + } + + + /********************************椹卞姩鍗囩骇***********************************/ + /** + * 鍙戦�佹枃浠剁浉鍏冲懡浠� + */ + public void sendFileCommand(String ipAddress, byte[] dataBytes, String fileId, Integer command, HDLLinkCallBack callBack) { + //甯ф牸寮忥細head+鍛戒护瀛�+鏁版嵁闀垮害+浜岃繘鍒舵暟鎹� + FileRequest linkRequest = new FileRequest(fileId, command, dataBytes, HDLLinkConfig.getInstance().isLocalEncrypt()); + linkRequest.setReplyTopic(linkRequest.getAckTopic()); + new HDLConnectHelper(ipAddress, linkRequest, new HDLConnectHelper.HdlSocketListener() { + @Override + public void onSucceed(Object msg) { + + } + + @Override + public void onFailure(HDLLinkCode hdlLinkCode) { + + } + }, true).send(); + } + +} -- Gitblit v1.8.0