From 32b5f366ceaad4aa9a33eccf0b109eef24175495 Mon Sep 17 00:00:00 2001
From: mac <user@users-MacBook-Pro.local>
Date: 星期二, 10 十月 2023 14:55:01 +0800
Subject: [PATCH] 2023年10月10日14:54:56

---
 app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java |   79 +++++++++++++++++++++------------------
 1 files changed, 43 insertions(+), 36 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 2db7010..037b4bf 100644
--- a/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java
+++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java
@@ -40,6 +40,7 @@
 import com.hdl.sdk.link.core.callback.HDLLinkCallBack;
 import com.hdl.sdk.link.core.config.HDLLinkConfig;
 import com.hdl.sdk.link.gateway.HDLLinkLocalGateway;
+import com.hdl.sdk.link.gateway.type.GatewayMasterType;
 
 import java.lang.reflect.Type;
 import java.util.ArrayList;
@@ -54,27 +55,6 @@
  */
 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())) {
-                    newList.add(gatewayBean);
-                }
-            }
-        }
-        return newList;
-    }
 
     /**
      * 鑾峰彇褰撳墠瀵硅薄
@@ -92,6 +72,28 @@
         }
         return sHdlDeviceLogic;
     }
+
+    /**
+     * 鑾峰彇褰撳墠浣忓畢鐨勯�嗗彉鍣ㄥ垪琛�
+     */
+    public List<GatewayBean> getCurrentHomeGatewayList() {
+        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(GatewayMasterType.MasterTrue)
+                        && gatewayBean.getHomeId().equals(UserConfigManage.getInstance().getHomeId())) {
+                    newList.add(gatewayBean);
+                }
+            }
+        }
+        return newList;
+    }
+
 
     /**
      * 娣诲姞閫嗗彉鍣ㄥ埌浜戠涓�
@@ -419,7 +421,7 @@
     public void editGatewayParam(String mac, LinkCallBack<Boolean> linkCallBack) {
         String requestUrl = TopicApi.SET_GATEWAY_EDIT;
         JsonObject json = new JsonObject();
-        json.addProperty("master", "true");
+        json.addProperty("master", GatewayMasterType.MasterTrue);
         TcpClient.getInstance().sendDataToLinkGateway(mac, requestUrl, json, "", new HDLLinkCallBack() {
             @Override
             public void onSuccess(String msg) {
@@ -515,15 +517,16 @@
     }
 
     /**
-     * 鑾峰彇鏈湴閫嗗彉鍣ㄥ垪琛�
+     * 鑾峰彇閫嗗彉鍣ㄥ垪琛�
      * 娉ㄦ剰:鏈夊缃戜互浜戠璁惧涓哄噯,鏈湴瀛樺湪锛屼簯绔病鏈夊垯鍒犻櫎锛涘唴缃戜互鏈湴涓轰富,鎼滅储澶氬皯涓澶囧氨鏄剧ず澶氬皯涓紱
      *
-     * @param cloudCallBeak -
+     * @param cloudCallBeak 杩斿洖閫嗗彉鍣ㄥ垪琛�
      */
-    public void getLocalGatewayList(CloudCallBeak<Boolean> cloudCallBeak) {
+    public void getCurrentHomeLocalAndCloudGatewayList(CloudCallBeak<List<GatewayBean>> cloudCallBeak) {
         HdlDeviceLogic.getInstance().searchGateway(new GatewayCallBack() {
             @Override
             public void onSuccess(List<GatewayBean> gatewayBeanList) {
+                //灞�鍩熺綉鎯呭喌
                 HdlDeviceLogic.getInstance().getCloudInverterDeviceList(UserConfigManage.getInstance().getHomeId(), new CloudCallBeak<List<CloudInverterDeviceBean>>() {
                     @Override
                     public void onSuccess(List<CloudInverterDeviceBean> list) {
@@ -531,7 +534,7 @@
 //                            //浜戠娌℃湁缁戝畾閫嗗彉鍣�,浠ユ湰鍦颁负涓�;
 //                            HDLLinkLocalGateway.getInstance().getGatewayList().clear();
                             if (cloudCallBeak != null) {
-                                cloudCallBeak.onSuccess(true);
+                                cloudCallBeak.onSuccess(getCurrentHomeGatewayList());
                             }
                             return;
                         }
@@ -563,7 +566,7 @@
                                             removeInverter(removeSidList.get(i));
                                         }
                                         if (cloudCallBeak != null) {
-                                            cloudCallBeak.onSuccess(true);
+                                            cloudCallBeak.onSuccess(getCurrentHomeGatewayList());
                                         }
                                     }
                                 }
@@ -591,7 +594,7 @@
                                             removeInverter(removeSidList.get(i));
                                         }
                                         if (cloudCallBeak != null) {
-                                            cloudCallBeak.onSuccess(true);
+                                            cloudCallBeak.onSuccess(getCurrentHomeGatewayList());
                                         }
                                     }
                                     HdlLogLogic.print("鑾峰彇璁惧杩滅▼閫氳淇℃伅澶辫触->msg->" + e.getMsg() + "(" + e.getCode() + ")");
@@ -613,15 +616,15 @@
 
             @Override
             public void onError(HDLLinkException e) {
+                //澶栫綉鎯呭喌
                 HdlDeviceLogic.getInstance().getCloudInverterDeviceList(UserConfigManage.getInstance().getHomeId(), new CloudCallBeak<List<CloudInverterDeviceBean>>() {
                     @Override
                     public void onSuccess(List<CloudInverterDeviceBean> list) {
-                        //娓呮鏈湴缃戝叧鍒楄〃
+                        //浜戠娌℃湁,娓呯┖鏈湴閫嗗彉鍣ㄥ垪琛�
                         HDLLinkLocalGateway.getInstance().getGatewayList().clear();
-
                         if (list == null || list.size() == 0) {
                             if (cloudCallBeak != null) {
-                                cloudCallBeak.onSuccess(true);
+                                cloudCallBeak.onSuccess(getCurrentHomeGatewayList());
                             }
                             return;
                         }
@@ -636,7 +639,7 @@
                                     refreshGatewayCacheData(false, cloudInverterDeviceBean, deviceRemoteInfo);
                                     if (atomicInteger.get() == list.size()) {
                                         if (cloudCallBeak != null) {
-                                            cloudCallBeak.onSuccess(true);
+                                            cloudCallBeak.onSuccess(getCurrentHomeGatewayList());
                                         }
                                     }
                                 }
@@ -646,7 +649,7 @@
                                     atomicInteger.set(atomicInteger.get() + 1);
                                     if (atomicInteger.get() == list.size()) {
                                         if (cloudCallBeak != null) {
-                                            cloudCallBeak.onSuccess(true);
+                                            cloudCallBeak.onSuccess(getCurrentHomeGatewayList());
                                         }
                                     }
                                     HdlLogLogic.print("鑾峰彇璁惧杩滅▼閫氳淇℃伅澶辫触->msg->" + e.getMsg() + "(" + e.getCode() + ")");
@@ -678,7 +681,7 @@
      * @return -
      */
     public void getDeviceRemoteInfo(String homeId, String spk, String mac, CloudCallBeak<DeviceRemoteInfo> cloudCallBeak) {
-        String requestUrl = HttpApi.POST_Device_remoteInfo;
+        String requestUrl = HttpApi.POST_Device_RemoteInfo;
         JsonObject json = new JsonObject();
         json.addProperty("homeId", homeId);
         json.addProperty("spk", spk);
@@ -721,7 +724,7 @@
     }
 
     /**
-     * 鎼滅储缃戝叧鍒楄〃
+     * 鎼滅储閫嗗彉鍣ㄥ垪琛�
      *
      * @param gatewayCallBack -
      */
@@ -752,6 +755,10 @@
         if (deviceRemoteInfo != null) {
             gatewayBean.setAesKey(deviceRemoteInfo.getSecret());//璁剧疆mqtt閫氳绉橀挜
             gatewayBean.setGatewayId(deviceRemoteInfo.getGatewayId());//璁剧疆gatewayId
+            //鐢ㄤ箣鍓嶇殑搴�,搴曞眰mqtt璁㈤槄锛屽姞瑙e瘑浼氱敤鍒拌鍙傛暟;
+            HDLLinkConfig.getInstance().setAesKey(deviceRemoteInfo.getSecret());//璁剧疆mqtt閫氳绉橀挜搴�
+            HDLLinkConfig.getInstance().setGatewayId(deviceRemoteInfo.getGatewayId());//璁剧疆gatewayId
+
         }
         gatewayBean.setHomeId(UserConfigManage.getInstance().getHomeId());//浣忓畢id
         gatewayBean.setDeviceStatus(cloudInverterDeviceBean.getDeviceStatus());//璁剧疆缃戝叧鐘舵��
@@ -762,7 +769,7 @@
         gatewayBean.setDevice_name(cloudInverterDeviceBean.getName());//璁惧鍚嶇О
         gatewayBean.setGatewayType(cloudInverterDeviceBean.getSpk());//璁剧疆spk
         gatewayBean.setLocalEncrypt(true);
-        gatewayBean.setMaster("true");
+        gatewayBean.setMaster(GatewayMasterType.MasterTrue);
         gatewayBean.setSystemStatusDesc(cloudInverterDeviceBean.getSystemStatusDesc());//璁惧鐘舵��
         gatewayBean.setHwVersion(cloudInverterDeviceBean.getHwVersion());//杞欢鐗堟湰鍙�
         gatewayBean.setCategorySecondName(cloudInverterDeviceBean.getCategorySecondName());//璁惧绫诲瀷(浜у搧浜岀骇鍒嗙被鍚嶇О

--
Gitblit v1.8.0