From bd80ca98ffb4f483ca2eba47051281fa69e790ac Mon Sep 17 00:00:00 2001 From: 刘卫锦 <lwj@hdlchina.com.cn> Date: 星期一, 14 八月 2023 10:24:25 +0800 Subject: [PATCH] 代码同步 --- app/src/main/java/com/hdl/photovoltaic/other/HdlResidenceLogic.java | 128 +++++++++++++++++++++++++++++++++++++----- 1 files changed, 111 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/com/hdl/photovoltaic/other/HdlResidenceLogic.java b/app/src/main/java/com/hdl/photovoltaic/other/HdlResidenceLogic.java index 73039a7..370410a 100644 --- a/app/src/main/java/com/hdl/photovoltaic/other/HdlResidenceLogic.java +++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlResidenceLogic.java @@ -17,6 +17,7 @@ import com.hdl.sdk.link.core.bean.gateway.GatewayBean; import com.hdl.sdk.link.core.callback.GatewayCallBack; import com.hdl.sdk.link.core.config.HDLLinkConfig; +import com.hdl.sdk.link.gateway.HDLLinkLocalGateway; import java.util.ArrayList; import java.util.List; @@ -258,13 +259,19 @@ HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() { @Override public void onSuccess(HttpResponsePack httpResponsePack) { - if (httpResponsePack != null && httpResponsePack.getData() != null) { - Gson gson = new Gson(); - String jsonStr = gson.toJson(httpResponsePack.getData()); - HouseInfoBean houseInfoBean = gson.fromJson(jsonStr, HouseInfoBean.class); + try { + if (httpResponsePack != null && httpResponsePack.getData() != null) { + Gson gson = new Gson(); + String jsonStr = gson.toJson(httpResponsePack.getData()); + HouseInfoBean houseInfoBean = gson.fromJson(jsonStr, HouseInfoBean.class); + if (cloudCallBeak != null) { + cloudCallBeak.onSuccess(houseInfoBean); + } + } + } catch (Exception exception) { if (cloudCallBeak != null) { - cloudCallBeak.onSuccess(houseInfoBean); + cloudCallBeak.onFailure(exception); } } } @@ -524,31 +531,118 @@ HdlFileLogic.getInstance().createDirectory(); //閰嶇疆鏈湴閫氫俊鐨勪俊鎭� initLocalLinkSdk(); + getGatewayList(null); -// HdlDeviceLogic.getInstance().getInverterDeviceList(UserConfigManage.getInstance().getHomeId(), new CloudCallBeak<CloudInverterDeviceBean>() { -// @Override -// public void onSuccess(CloudInverterDeviceBean obj) { -// -// -// } -// -// @Override -// public void onFailure(Exception exception) { -// -// } -// }); + } + + + public void getGatewayList(CloudCallBeak<Boolean> baseSuccessFailureCallBeak) { 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) { + if (list == null||list.size()==0) { + //浜戠娌℃湁缁戝畾閫嗗彉鍣�,娓呯┖鏈湴鍒楄〃; + HDLLinkLocalGateway.getInstance().getGatewayList().clear(); + if (baseSuccessFailureCallBeak != null) { + baseSuccessFailureCallBeak.onSuccess(true); + } + return; + } + //鏀堕泦鍒犻櫎閫嗗彉鍣╯id + List<String> removeSidList = new ArrayList<>(); + for (int i = 0; i < list.size(); i++) { + CloudInverterDeviceBean cloudInverterDeviceBean = list.get(i); + for (int j = 0; j < HDLLinkLocalGateway.getInstance().getGatewayList().size(); j++) { + GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getGatewayList().get(j); + if (!cloudInverterDeviceBean.getSid().equals(gatewayBean.getSid())) { + //鏈湴鏈夛紝浜戠娌℃湁,鍒犻櫎鏈湴锛� + removeSidList.add(gatewayBean.getSid()); + } + } + } + for (int i = 0; i < removeSidList.size(); i++) { + //鑾峰彇鏈湴鐨勬绫虫尝 + removeInverter(removeSidList.get(i)); + } + + if (baseSuccessFailureCallBeak != null) { + baseSuccessFailureCallBeak.onSuccess(true); + } + } + + @Override + public void onFailure(Exception exception) { + if (baseSuccessFailureCallBeak != null) { + baseSuccessFailureCallBeak.onFailure(exception); + } + } + }); } @Override public void onError(HDLLinkException e) { + HdlDeviceLogic.getInstance().getCloudInverterDeviceList(UserConfigManage.getInstance().getHomeId(), new CloudCallBeak<List<CloudInverterDeviceBean>>() { + @Override + public void onSuccess(List<CloudInverterDeviceBean> list) { + if (list == null) { + if (baseSuccessFailureCallBeak != null) { + baseSuccessFailureCallBeak.onSuccess(true); + } + return; + } + if (list.size() <= 0) { + if (baseSuccessFailureCallBeak != null) { + baseSuccessFailureCallBeak.onSuccess(true); + } + return; + } + 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_name(cloudInverterDeviceBean.getGatewayName()); + gatewayBean.setDevice_mac(cloudInverterDeviceBean.getOsn()); + gatewayBean.setHomeId(UserConfigManage.getInstance().getHomeId()); + gatewayBean.setLocalEncrypt(true); + gatewayBean.setMaster("true"); + HDLLinkLocalGateway.getInstance().getGatewayList().add(gatewayBean); + } + if (baseSuccessFailureCallBeak != null) { + baseSuccessFailureCallBeak.onSuccess(true); + } + } + + @Override + public void onFailure(Exception exception) { + if (baseSuccessFailureCallBeak != null) { + baseSuccessFailureCallBeak.onFailure(exception); + } + } + }); } }); + } + /** + * 鍒犻櫎鏈湴閫嗗彉鍣� + * + * @param sid 璁惧sid + */ + private void removeInverter(String sid) { + //鑾峰彇鏈湴 + GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getLocalGateway(sid); + if (gatewayBean != null) { + HDLLinkLocalGateway.getInstance().getGatewayList().remove(gatewayBean); + } } /** -- Gitblit v1.8.0