From 2c7615cd73dfa6a7ca4df975430d2217524513d2 Mon Sep 17 00:00:00 2001
From: mac <user@users-MacBook-Pro.local>
Date: 星期四, 28 九月 2023 11:38:28 +0800
Subject: [PATCH] 2023年09月28日11:38:24

---
 app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java |  104 ++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 96 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 49d7dce..820d6b8 100644
--- a/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java
+++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java
@@ -9,6 +9,7 @@
 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;
@@ -27,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;
@@ -42,6 +45,26 @@
  */
 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 (gatewayBean.getMaster().equals("true")
+                        && gatewayBean.getHomeId().equals(UserConfigManage.getInstance().getHomeId())) {
+//                    if ("0101050217BBC400".equals(gatewayBean.getOid()))//娴嬭瘯鏃惰繃婊ゆ帀鏃犳晥鐨勶紝杩欒鍚庨潰浠g爜瑕佸垹闄�
+//                        continue;
+                    newList.add(gatewayBean);
+                }
+            }
+        }
+        return newList;
+    }
 
     /**
      * 鑾峰彇褰撳墠瀵硅薄
@@ -68,7 +91,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) {
 
@@ -263,7 +286,7 @@
      * @param mac          璁惧mac
      * @param linkCallBack 鍥炶皟update
      */
-    public void steGatewayParam(String mac, LinkCallBack<Boolean> linkCallBack) {
+    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());
@@ -295,6 +318,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
@@ -321,7 +402,6 @@
         });
 
     }
-
 
     /**
      * 鑾峰彇缃戝叧璇︽儏淇℃伅
@@ -375,11 +455,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());
                 }
             }
 
@@ -428,7 +514,7 @@
                             }
                         }
                         for (int i = 0; i < removeSidList.size(); i++) {
-                            //鑾峰彇鏈湴鐨勬绫虫尝
+                            //鑾峰彇鏈湴鐨勯�嗗彉鍣�
                             removeInverter(removeSidList.get(i));
                         }
 
@@ -461,11 +547,13 @@
                         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);

--
Gitblit v1.8.0