From a59bbb7890e107a681f677765f2600e278c06a0d Mon Sep 17 00:00:00 2001
From: mac <user@users-MacBook-Pro.local>
Date: 星期一, 09 十月 2023 10:16:37 +0800
Subject: [PATCH] 2023年10月09日10:16:35

---
 app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java |  384 +++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 249 insertions(+), 135 deletions(-)

diff --git a/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java b/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java
index 08d8f54..6462ac8 100644
--- a/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java
+++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java
@@ -7,7 +7,9 @@
 import com.google.gson.JsonObject;
 import com.google.gson.reflect.TypeToken;
 import com.hdl.hdlhttp.HxHttp;
+import com.hdl.linkpm.sdk.core.exception.HDLException;
 import com.hdl.photovoltaic.bean.HttpResponsePack;
+import com.hdl.photovoltaic.bean.LocalResponse;
 import com.hdl.photovoltaic.config.AppConfigManage;
 import com.hdl.photovoltaic.config.UserConfigManage;
 import com.hdl.photovoltaic.internet.HttpClient;
@@ -16,6 +18,7 @@
 import com.hdl.photovoltaic.internet.api.TopicApi;
 import com.hdl.photovoltaic.listener.BaseSuccessFailureCallBeak;
 import com.hdl.photovoltaic.listener.CloudCallBeak;
+import com.hdl.photovoltaic.listener.LinkCallBack;
 import com.hdl.photovoltaic.ui.bean.CloudInverterChildDeviceBean;
 import com.hdl.photovoltaic.ui.bean.CloudInverterDeviceBean;
 import com.hdl.photovoltaic.ui.bean.InverterDeviceBean;
@@ -25,6 +28,8 @@
 import com.hdl.sdk.link.common.exception.HDLLinkCode;
 import com.hdl.sdk.link.common.exception.HDLLinkException;
 import com.hdl.sdk.link.core.bean.gateway.GatewayBean;
+import com.hdl.sdk.link.core.bean.request.BaseLocalRequest;
+import com.hdl.sdk.link.core.bean.response.BaseLocalResponse;
 import com.hdl.sdk.link.core.callback.GatewayCallBack;
 import com.hdl.sdk.link.core.callback.HDLLinkCallBack;
 import com.hdl.sdk.link.gateway.HDLLinkLocalGateway;
@@ -33,13 +38,35 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import io.reactivex.rxjava3.disposables.Disposable;
 
 /**
- * 璁惧閫昏緫鐨勭晫闈�
+ * 璁惧閫昏緫
  */
 public class HdlDeviceLogic {
     private static volatile HdlDeviceLogic sHdlDeviceLogic;
+
+    /**
+     * 鑾峰彇褰撳墠浣忓畢鐨勯�嗗彉鍣ㄥ垪琛�
+     */
+    public List<GatewayBean> getGatewayList() {
+        List<GatewayBean> newList = new ArrayList<>();
+        List<GatewayBean> list = HDLLinkLocalGateway.getInstance().getGatewayList();
+        if (list.size() > 0) {
+            for (int i = 0; i < list.size(); i++) {
+                GatewayBean gatewayBean = list.get(i);
+                if (TextUtils.isEmpty(gatewayBean.getDevice_mac())) {
+                    continue;
+                }
+                if (gatewayBean.getMaster().equals("true")
+                        && gatewayBean.getHomeId().equals(UserConfigManage.getInstance().getHomeId())) {
+//                    if ("0101050217BBC400".equals(gatewayBean.getOid()))//娴嬭瘯鏃惰繃婊ゆ帀鏃犳晥鐨勶紝杩欒鍚庨潰浠g爜瑕佸垹闄�
+//                        continue;
+                    newList.add(gatewayBean);
+                }
+            }
+        }
+        return newList;
+    }
 
     /**
      * 鑾峰彇褰撳墠瀵硅薄
@@ -66,7 +93,7 @@
      * @param sid           -
      * @param oid           -
      * @param name          -
-     * @param cloudCallBeak
+     * @param cloudCallBeak -
      */
     public void addInverterDeviceToCloud(String mac, String spk, String sid, String oid, String name, CloudCallBeak<Boolean> cloudCallBeak) {
 
@@ -80,18 +107,43 @@
         json.addProperty("name", name);
         // json.addProperty("zoneType", "password");//鍖哄煙
 
-        HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() {
+        HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() {
             @Override
-            public void onSuccess(HttpResponsePack httpResponsePack) {
+            public void onSuccess(String str) {
                 if (cloudCallBeak != null) {
                     cloudCallBeak.onSuccess(true);
+                    //涓存椂鐨勯�昏緫锛屼笂浼爋id鍒楄〃鍒颁簯绔�
+                    getGatewayOidList(mac, new LinkCallBack<List<OidBean>>() {
+                        @Override
+                        public void onSuccess(List<OidBean> obj) {
+                            if (obj == null) {
+                                return;
+                            }
+                            fullUpdateOid(obj, new CloudCallBeak<Boolean>() {
+                                @Override
+                                public void onSuccess(Boolean obj) {
+
+                                }
+
+                                @Override
+                                public void onFailure(HDLException e) {
+
+                                }
+                            });
+                        }
+
+                        @Override
+                        public void onError(HDLLinkException e) {
+
+                        }
+                    });
                 }
             }
 
             @Override
-            public void onFailure(Exception exception) {
+            public void onFailure(HDLException e) {
                 if (cloudCallBeak != null) {
-                    cloudCallBeak.onFailure(exception);
+                    cloudCallBeak.onFailure(e);
                 }
             }
         });
@@ -109,29 +161,24 @@
         json.addProperty("homeId", homeId);
         // json.addProperty("zoneType", "password");//鍖哄煙
 
-        HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() {
+        HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() {
             @Override
-            public void onSuccess(HttpResponsePack httpResponsePack) {
-                try {
-                    if (httpResponsePack != null && httpResponsePack.getData() != null) {
-                        Gson gson = new Gson();
-                        String json = gson.toJson(httpResponsePack.getData());
-                        Type type = new TypeToken<List<CloudInverterDeviceBean>>() {
-                        }.getType();
-                        List<CloudInverterDeviceBean> list = new Gson().fromJson(json, type);
-                        if (cloudCallBeak != null) {
-                            cloudCallBeak.onSuccess(list);
-                        }
-                    }
-                } catch (Exception e) {
+            public void onSuccess(String jsonStr) {
+                if (TextUtils.isEmpty(jsonStr)) {
                     if (cloudCallBeak != null) {
-                        cloudCallBeak.onFailure(e);
+                        cloudCallBeak.onSuccess(null);
                     }
+                }
+                Type type = new TypeToken<List<CloudInverterDeviceBean>>() {
+                }.getType();
+                List<CloudInverterDeviceBean> list = new Gson().fromJson(jsonStr, type);
+                if (cloudCallBeak != null) {
+                    cloudCallBeak.onSuccess(list);
                 }
             }
 
             @Override
-            public void onFailure(Exception e) {
+            public void onFailure(HDLException e) {
                 if (cloudCallBeak != null) {
                     cloudCallBeak.onFailure(e);
                 }
@@ -153,18 +200,18 @@
         json.addProperty("deviceId", deviceId);
         // json.addProperty("zoneType", "password");//鍖哄煙
 
-        HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() {
+        HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() {
             @Override
-            public void onSuccess(HttpResponsePack httpResponsePack) {
+            public void onSuccess(String str) {
                 if (cloudCallBeak != null) {
                     cloudCallBeak.onSuccess(true);
                 }
             }
 
             @Override
-            public void onFailure(Exception exception) {
+            public void onFailure(HDLException e) {
                 if (cloudCallBeak != null) {
-                    cloudCallBeak.onFailure(exception);
+                    cloudCallBeak.onFailure(e);
                 }
             }
         });
@@ -183,25 +230,28 @@
         json.addProperty("parentOid", parentOid);
         // json.addProperty("zoneType", "password");//鍖哄煙
 
-        HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() {
+        HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() {
             @Override
-            public void onSuccess(HttpResponsePack httpResponsePack) {
-                if (httpResponsePack != null && httpResponsePack.getData() != null) {
-                    Gson gson = new Gson();
-                    String json = gson.toJson(httpResponsePack.getData());
-                    Type typeOfT = new TypeToken<List<CloudInverterChildDeviceBean>>() {
-                    }.getType();
-                    List<CloudInverterChildDeviceBean> list = gson.fromJson(json, typeOfT);
+            public void onSuccess(String jsonStr) {
+                if (TextUtils.isEmpty(jsonStr)) {
                     if (cloudCallBeak != null) {
-                        cloudCallBeak.onSuccess(list);
+                        cloudCallBeak.onSuccess(null);
                     }
+                    return;
+                }
+                Gson gson = new Gson();
+                Type typeOfT = new TypeToken<List<CloudInverterChildDeviceBean>>() {
+                }.getType();
+                List<CloudInverterChildDeviceBean> list = gson.fromJson(jsonStr, typeOfT);
+                if (cloudCallBeak != null) {
+                    cloudCallBeak.onSuccess(list);
                 }
             }
 
             @Override
-            public void onFailure(Exception exception) {
+            public void onFailure(HDLException e) {
                 if (cloudCallBeak != null) {
-                    cloudCallBeak.onFailure(exception);
+                    cloudCallBeak.onFailure(e);
                 }
             }
         });
@@ -214,7 +264,7 @@
      * @param cloudCallBeak 鍥炶皟update
      */
     public void fullUpdateOid(List<OidBean> oidList, CloudCallBeak<Boolean> cloudCallBeak) {
-        String requestUrl = HttpApi.POST_Device_ChildDevices_List;
+        String requestUrl = HttpApi.POST_Device_Oid;
         JsonObject json = new JsonObject();
         json.addProperty("operationSource", "PROGRAM_ENERGY");//
         json.addProperty("homeId", UserConfigManage.getInstance().getHomeId());
@@ -224,7 +274,7 @@
             JsonObject jsonObject = new JsonObject();
             jsonObject.addProperty("protocolType", oidBean.getProtocolType());
             jsonObject.addProperty("deviceType", oidBean.getDeviceType());
-            jsonObject.addProperty("mac", oidBean.getMac());
+            jsonObject.addProperty("mac", oidBean.getDevice_mac());
             jsonObject.addProperty("oid", oidBean.getOid());
             jsonObject.addProperty("device_name", oidBean.getDevice_name());
             jsonObject.addProperty("device_model", oidBean.getDevice_model());
@@ -236,9 +286,9 @@
         json.add("devices", jsonArray);
         // json.addProperty("zoneType", "password");//鍖哄煙
 
-        HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() {
+        HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() {
             @Override
-            public void onSuccess(HttpResponsePack httpResponsePack) {
+            public void onSuccess(String str) {
 
                 if (cloudCallBeak != null) {
                     cloudCallBeak.onSuccess(true);
@@ -247,9 +297,9 @@
             }
 
             @Override
-            public void onFailure(Exception exception) {
+            public void onFailure(HDLException e) {
                 if (cloudCallBeak != null) {
-                    cloudCallBeak.onFailure(exception);
+                    cloudCallBeak.onFailure(e);
                 }
             }
         });
@@ -260,10 +310,10 @@
     /**
      * 璁剧疆缃戝叧杩滅▼鍙傛暟
      *
-     * @param mac           璁惧mac
-     * @param cloudCallBeak 鍥炶皟update
+     * @param mac          璁惧mac
+     * @param linkCallBack 鍥炶皟update
      */
-    public void steGatewayParam(String mac, CloudCallBeak<Boolean> cloudCallBeak) {
+    public void setGatewayRemoteParam(String mac, LinkCallBack<Boolean> linkCallBack) {
         String requestUrl = TopicApi.SET_GATEWAY_REMOTE_EDIT;
         JsonObject json = new JsonObject();
         json.addProperty("homeId", UserConfigManage.getInstance().getHomeId());
@@ -279,86 +329,135 @@
                         gatewayBean.setLocalEncrypt(true);
                     }
                 }
-                if (cloudCallBeak != null) {
-                    cloudCallBeak.onSuccess(true);
+                if (linkCallBack != null) {
+                    linkCallBack.onSuccess(true);
                 }
 
             }
 
             @Override
             public void onError(HDLLinkException e) {
-                if (cloudCallBeak != null) {
-                    cloudCallBeak.onFailure(e);
+                if (linkCallBack != null) {
+                    linkCallBack.onError(e);
                 }
             }
         });
     }
 
     /**
+     * 缃戝叧鏃堕棿璇诲彇
+     *
+     * @param mac          璁惧mac
+     * @param linkCallBack 鍥炶皟update
+     */
+    public void getGatewayTime(String mac, LinkCallBack<Boolean> linkCallBack) {
+        String requestUrl = TopicApi.GET_GATEWAY_TIME;
+        TcpClient.getInstance().sendDataToLinkGateway(mac, requestUrl, null, "", new HDLLinkCallBack() {
+            @Override
+            public void onSuccess(String msg) {
+                if (linkCallBack != null) {
+                    linkCallBack.onSuccess(true);
+                }
+            }
+
+            @Override
+            public void onError(HDLLinkException e) {
+                if (linkCallBack != null) {
+                    linkCallBack.onError(e);
+                }
+            }
+        });
+
+    }
+
+    /**
+     * 缃戝叧鏃堕棿淇敼
+     *
+     * @param mac          璁惧mac
+     * @param linkCallBack 鍥炶皟update
+     */
+    public void editGatewayTime(String mac, JsonObject jsonObject, LinkCallBack<Boolean> linkCallBack) {
+        String requestUrl = TopicApi.SET_GATEWAY_TIME_EDIT;
+//        JsonObject json = new JsonObject();
+//        json.addProperty("master", "true");
+//        "objects": {
+//            "date": "2020-08-15",
+//                    "time": "17:25:20"
+//        }
+        TcpClient.getInstance().sendDataToLinkGateway(mac, requestUrl, jsonObject, "", new HDLLinkCallBack() {
+            @Override
+            public void onSuccess(String msg) {
+                if (linkCallBack != null) {
+                    linkCallBack.onSuccess(true);
+                }
+            }
+
+            @Override
+            public void onError(HDLLinkException e) {
+                if (linkCallBack != null) {
+                    linkCallBack.onError(e);
+                }
+            }
+        });
+
+    }
+
+    /**
      * 缂栬緫缃戝叧鍙傛暟
      *
-     * @param mac           璁惧mac
-     * @param cloudCallBeak 鍥炶皟update
+     * @param mac          璁惧mac
+     * @param linkCallBack 鍥炶皟update
      */
-    public void editGatewayParam(String mac, CloudCallBeak<Boolean> cloudCallBeak) {
+    public void editGatewayParam(String mac, LinkCallBack<Boolean> linkCallBack) {
         String requestUrl = TopicApi.SET_GATEWAY_EDIT;
         JsonObject json = new JsonObject();
         json.addProperty("master", "true");
         TcpClient.getInstance().sendDataToLinkGateway(mac, requestUrl, json, "", new HDLLinkCallBack() {
             @Override
             public void onSuccess(String msg) {
-                if (cloudCallBeak != null) {
-                    cloudCallBeak.onSuccess(true);
+                if (linkCallBack != null) {
+                    linkCallBack.onSuccess(true);
                 }
             }
 
             @Override
             public void onError(HDLLinkException e) {
-                if (cloudCallBeak != null) {
-                    cloudCallBeak.onFailure(e);
+                if (linkCallBack != null) {
+                    linkCallBack.onError(e);
                 }
             }
         });
 
     }
 
-
     /**
      * 鑾峰彇缃戝叧璇︽儏淇℃伅
      *
-     * @param mac           缃戝叧mac
-     * @param cloudCallBeak 鍥炶皟
+     * @param mac          缃戝叧mac
+     * @param linkCallBack 鍥炶皟
      */
-    public void getGatewayInfo(String mac, CloudCallBeak<GatewayBean> cloudCallBeak) {
+    public void getGatewayInfo(String mac, LinkCallBack<GatewayBean> linkCallBack) {
         String requestUrl = TopicApi.GET_GATEWAY_INFO;
         TcpClient.getInstance().sendDataToLinkGateway(mac, requestUrl, null, "", new HDLLinkCallBack() {
             @Override
-            public void onSuccess(String msg) {
-                try {
-                    if (!TextUtils.isEmpty(msg)) {
-                        Gson gson = new Gson();
-                        String json = gson.toJson(msg);
-                        GatewayBean gatewayBean = gson.fromJson(json, GatewayBean.class);
-                        if (cloudCallBeak != null) {
-                            cloudCallBeak.onSuccess(gatewayBean);
-                        }
-                    } else {
-                        if (cloudCallBeak != null) {
-                            cloudCallBeak.onSuccess(new GatewayBean());
-                        }
+            public void onSuccess(String json) {
+                if (TextUtils.isEmpty(json)) {
+                    if (linkCallBack != null) {
+                        linkCallBack.onSuccess(null);
                     }
-
-                } catch (Exception e) {
-                    if (cloudCallBeak != null) {
-                        cloudCallBeak.onFailure(e);
-                    }
+                    return;
+                }
+                Gson gson = new Gson();
+                GatewayBean gatewayBean = gson.fromJson(json, GatewayBean.class);
+                if (linkCallBack != null) {
+                    linkCallBack.onSuccess(gatewayBean);
                 }
             }
 
             @Override
             public void onError(HDLLinkException e) {
-                if (cloudCallBeak != null) {
-                    cloudCallBeak.onFailure(e);
+                if (linkCallBack != null) {
+                    linkCallBack.onError(e);
                 }
             }
         });
@@ -368,41 +467,39 @@
     /**
      * 鑾峰彇缃戝叧oid鍒楄〃
      *
-     * @param mac           缃戝叧mac
-     * @param cloudCallBeak 鍥炶皟
+     * @param mac          缃戝叧mac
+     * @param linkCallBack 鍥炶皟
      */
-    public void getGatewayOidList(String mac, CloudCallBeak<List<OidBean>> cloudCallBeak) {
+    public void getGatewayOidList(String mac, LinkCallBack<List<OidBean>> linkCallBack) {
         String requestUrl = TopicApi.GET_GATEWAY_OID_LIST;
         TcpClient.getInstance().sendDataToLinkGateway(mac, requestUrl, null, "", new HDLLinkCallBack() {
             @Override
-            public void onSuccess(String msg) {
-                try {
-                    if (!TextUtils.isEmpty(msg)) {
-                        Gson gson = new Gson();
-                        String json = gson.toJson(msg);
-                        Type typeOfT = new TypeToken<List<OidBean>>() {
-                        }.getType();
-                        List<OidBean> list = gson.fromJson(json, typeOfT);
-                        if (cloudCallBeak != null) {
-                            cloudCallBeak.onSuccess(list);
-                        }
-                    } else {
-                        if (cloudCallBeak != null) {
-                            cloudCallBeak.onSuccess(new ArrayList<>());
-                        }
+            public void onSuccess(String json) {
+                if (TextUtils.isEmpty(json)) {
+                    if (linkCallBack != null) {
+                        linkCallBack.onSuccess(null);
                     }
+                    return;
+                }
+                Gson gson = new Gson();
+                Type typeOfT = new TypeToken<BaseLocalResponse<List<OidBean>>>() {
+                }.getType();
+                BaseLocalResponse<List<OidBean>> baseLocalResponse = gson.fromJson(json, typeOfT);
 
-                } catch (Exception e) {
-                    if (cloudCallBeak != null) {
-                        cloudCallBeak.onFailure(e);
-                    }
+                if (linkCallBack == null) {
+                    return;
+                }
+                if (baseLocalResponse == null || baseLocalResponse.getObjects() == null) {
+                    linkCallBack.onSuccess(new ArrayList<>());
+                } else {
+                    linkCallBack.onSuccess(baseLocalResponse.getObjects());
                 }
             }
 
             @Override
             public void onError(HDLLinkException e) {
-                if (cloudCallBeak != null) {
-                    cloudCallBeak.onFailure(e);
+                if (linkCallBack != null) {
+                    linkCallBack.onError(e);
                 }
             }
         });
@@ -422,9 +519,9 @@
                 HdlDeviceLogic.getInstance().getCloudInverterDeviceList(UserConfigManage.getInstance().getHomeId(), new CloudCallBeak<List<CloudInverterDeviceBean>>() {
                     @Override
                     public void onSuccess(List<CloudInverterDeviceBean> list) {
-                        if (list == null) {
-                            //浜戠娌℃湁缁戝畾閫嗗彉鍣�,娓呯┖鏈湴鍒楄〃;
-                            HDLLinkLocalGateway.getInstance().getGatewayList().clear();
+                        if (list == null || list.size() == 0) {
+//                            //浜戠娌℃湁缁戝畾閫嗗彉鍣�,浠ユ湰鍦颁负涓�;
+//                            HDLLinkLocalGateway.getInstance().getGatewayList().clear();
                             if (cloudCallBeak != null) {
                                 cloudCallBeak.onSuccess(true);
                             }
@@ -444,8 +541,14 @@
                             }
                         }
                         for (int i = 0; i < removeSidList.size(); i++) {
-                            //鑾峰彇鏈湴鐨勬绫虫尝
+                            //鍒犻櫎鏈湴鐨勯�嗗彉鍣�
                             removeInverter(removeSidList.get(i));
+                        }
+
+                        for (int i = 0; i < list.size(); i++) {
+                            CloudInverterDeviceBean cloudInverterDeviceBean = list.get(i);
+                            GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getLocalGateway(cloudInverterDeviceBean.getSid());
+                            objectAssignment(cloudInverterDeviceBean, gatewayBean);
                         }
 
                         if (cloudCallBeak != null) {
@@ -454,9 +557,9 @@
                     }
 
                     @Override
-                    public void onFailure(Exception exception) {
+                    public void onFailure(HDLException e) {
                         if (cloudCallBeak != null) {
-                            cloudCallBeak.onFailure(exception);
+                            cloudCallBeak.onFailure(e);
                         }
                     }
                 });
@@ -467,30 +570,21 @@
                 HdlDeviceLogic.getInstance().getCloudInverterDeviceList(UserConfigManage.getInstance().getHomeId(), new CloudCallBeak<List<CloudInverterDeviceBean>>() {
                     @Override
                     public void onSuccess(List<CloudInverterDeviceBean> list) {
-                        if (list == null) {
-                            if (cloudCallBeak != null) {
-                                cloudCallBeak.onSuccess(true);
-                            }
-                            return;
-                        }
-                        if (list.size() <= 0) {
-                            if (cloudCallBeak != null) {
-                                cloudCallBeak.onSuccess(true);
-                            }
-                            return;
-                        }
+                        //娓呮鏈湴缃戝叧鍒楄〃
                         HDLLinkLocalGateway.getInstance().getGatewayList().clear();
+                        if (list == null || list.size() == 0) {
+                            if (cloudCallBeak != null) {
+                                cloudCallBeak.onSuccess(true);
+                            }
+                            return;
+                        }
                         for (int i = 0; i < list.size(); i++) {
                             CloudInverterDeviceBean cloudInverterDeviceBean = list.get(i);
+                            //浜戠瀵硅薄鏁版嵁浜ゆ崲鍒版湰鍦板璞�
                             GatewayBean gatewayBean = new GatewayBean();
-                            gatewayBean.setOid(cloudInverterDeviceBean.getOid());
-                            gatewayBean.setSid(cloudInverterDeviceBean.getSid());
-                            gatewayBean.setGatewayId(cloudInverterDeviceBean.getGatewayId());
-                            gatewayBean.setOnline(cloudInverterDeviceBean.isOnline());
-                            gatewayBean.setDevice_name(cloudInverterDeviceBean.getGatewayName());
-                            gatewayBean.setHomeId(UserConfigManage.getInstance().getHomeId());
-                            gatewayBean.setLocalEncrypt(true);
-                            gatewayBean.setMaster("true");
+                            objectAssignment(cloudInverterDeviceBean, gatewayBean);
+
+                            //娣诲姞缃戝叧
                             HDLLinkLocalGateway.getInstance().getGatewayList().add(gatewayBean);
                         }
                         if (cloudCallBeak != null) {
@@ -500,9 +594,9 @@
                     }
 
                     @Override
-                    public void onFailure(Exception exception) {
+                    public void onFailure(HDLException e) {
                         if (cloudCallBeak != null) {
-                            cloudCallBeak.onFailure(exception);
+                            cloudCallBeak.onFailure(e);
                         }
                     }
                 });
@@ -516,7 +610,6 @@
      * @param sid 璁惧sid
      */
     private void removeInverter(String sid) {
-        //鑾峰彇鏈湴鐨勬绫虫尝
         GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getLocalGateway(sid);
         if (gatewayBean != null) {
             HDLLinkLocalGateway.getInstance().getGatewayList().remove(gatewayBean);
@@ -534,6 +627,27 @@
         HDLLinkLocalGateway.getInstance().refreshGatewayByHomeIdAndSpk(UserConfigManage.getInstance().getHomeId(), spks, true, gatewayCallBack);
     }
 
+
+    private void objectAssignment(CloudInverterDeviceBean cloudInverterDeviceBean, GatewayBean gatewayBean) {
+        if (cloudInverterDeviceBean == null || gatewayBean == null) {
+            return;
+        }
+        gatewayBean.setOid(cloudInverterDeviceBean.getOid());
+        gatewayBean.setSid(cloudInverterDeviceBean.getSid());
+        gatewayBean.setGatewayId(cloudInverterDeviceBean.getGatewayId());
+        gatewayBean.setOnline(cloudInverterDeviceBean.isOnline());
+        gatewayBean.setDevice_mac(cloudInverterDeviceBean.getOsn());//璁惧mac
+        gatewayBean.setDevice_name(cloudInverterDeviceBean.getGatewayName());
+        gatewayBean.setHomeId(UserConfigManage.getInstance().getHomeId());
+        gatewayBean.setLocalEncrypt(true);
+        gatewayBean.setMaster("true");
+        gatewayBean.setSystemStatusDesc(cloudInverterDeviceBean.getSystemStatusDesc());
+        gatewayBean.setHwVersion(cloudInverterDeviceBean.getHwVersion());
+        gatewayBean.setCategorySecondName(cloudInverterDeviceBean.getCategorySecondName());
+        gatewayBean.setDeviceId(cloudInverterDeviceBean.getDeviceId());
+
+    }
+
     /**
      * 鑾峰彇缃戝叧spk鍒楄〃
      *

--
Gitblit v1.8.0