From 5e43612bb0afc1202fe802d4307b02cdfc05756f Mon Sep 17 00:00:00 2001
From: mac <user@users-MacBook-Pro.local>
Date: 星期六, 07 十月 2023 17:32:42 +0800
Subject: [PATCH] 2023年10月07日17:32:35

---
 app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java |  114 +++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 106 insertions(+), 8 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 047566b..39ee3a0 100644
--- a/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java
+++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java
@@ -28,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;
@@ -36,10 +38,9 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import io.reactivex.rxjava3.disposables.Disposable;
 
 /**
- * 璁惧閫昏緫鐨勭晫闈�
+ * 璁惧閫昏緫
  */
 public class HdlDeviceLogic {
     private static volatile HdlDeviceLogic sHdlDeviceLogic;
@@ -55,6 +56,8 @@
                 GatewayBean gatewayBean = list.get(i);
                 if (gatewayBean.getMaster().equals("true")
                         && gatewayBean.getHomeId().equals(UserConfigManage.getInstance().getHomeId())) {
+//                    if ("0101050217BBC400".equals(gatewayBean.getOid()))//娴嬭瘯鏃惰繃婊ゆ帀鏃犳晥鐨勶紝杩欒鍚庨潰浠g爜瑕佸垹闄�
+//                        continue;
                     newList.add(gatewayBean);
                 }
             }
@@ -106,6 +109,31 @@
             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) {
+
+                        }
+                    });
                 }
             }
 
@@ -233,7 +261,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());
@@ -314,6 +342,64 @@
     }
 
     /**
+     * 缃戝叧鏃堕棿璇诲彇
+     *
+     * @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
@@ -340,7 +426,6 @@
         });
 
     }
-
 
     /**
      * 鑾峰彇缃戝叧璇︽儏淇℃伅
@@ -394,11 +479,17 @@
                     return;
                 }
                 Gson gson = new Gson();
-                Type typeOfT = new TypeToken<List<OidBean>>() {
+                Type typeOfT = new TypeToken<BaseLocalResponse<List<OidBean>>>() {
                 }.getType();
-                List<OidBean> list = gson.fromJson(json, typeOfT);
-                if (linkCallBack != null) {
-                    linkCallBack.onSuccess(list);
+                BaseLocalResponse<List<OidBean>> baseLocalResponse = gson.fromJson(json, typeOfT);
+
+                if (linkCallBack == null) {
+                    return;
+                }
+                if (baseLocalResponse == null || baseLocalResponse.getObjects() == null) {
+                    linkCallBack.onSuccess(new ArrayList<>());
+                } else {
+                    linkCallBack.onSuccess(baseLocalResponse.getObjects());
                 }
             }
 
@@ -480,15 +571,22 @@
                         HDLLinkLocalGateway.getInstance().getGatewayList().clear();
                         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_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());
+
                             //娣诲姞缃戝叧
                             HDLLinkLocalGateway.getInstance().getGatewayList().add(gatewayBean);
                         }

--
Gitblit v1.8.0