| | |
| | | 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; |
| | |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | |
| | | */ |
| | | public void switchHouse(HouseIdBean houseIdBean) { |
| | | String oidHomeId = UserConfigManage.getInstance().getHomeId(); |
| | | if (houseIdBean.getHomeId().equals(oidHomeId)) { |
| | | return; |
| | | } |
| | | // if (houseIdBean.getHomeId().equals(oidHomeId)) { |
| | | // return; |
| | | // } |
| | | //删除旧的住宅文件夹 |
| | | HdlFileLogic.getInstance().deleteDirectory(HdlFileLogic.getInstance().getCurrentHomeRootPath()); |
| | | //重新设置住宅id |
| | |
| | | //配置本地通信的信息 |
| | | initLocalLinkSdk(); |
| | | |
| | | // HdlDeviceLogic.getInstance().getInverterDeviceList(UserConfigManage.getInstance().getHomeId(), new CloudCallBeak<CloudInverterDeviceBean>() { |
| | | // @Override |
| | | // public void onSuccess(CloudInverterDeviceBean obj) { |
| | | // |
| | | // |
| | | // } |
| | | // |
| | | // @Override |
| | | // public void onFailure(Exception exception) { |
| | | // |
| | | // } |
| | | // }); |
| | | 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) { |
| | | //云端没有绑定逆变器,清空本地列表; |
| | | HDLLinkLocalGateway.getInstance().getGatewayList().clear(); |
| | | return; |
| | | } |
| | | //收集删除逆变器sid |
| | | 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)); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(Exception 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) { |
| | | return; |
| | | } |
| | | if (list.size() <= 0) { |
| | | 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.setHomeId(UserConfigManage.getInstance().getHomeId()); |
| | | gatewayBean.setLocalEncrypt(true); |
| | | gatewayBean.setMaster("true"); |
| | | HDLLinkLocalGateway.getInstance().getGatewayList().add(gatewayBean); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(Exception exception) { |
| | | |
| | | } |
| | | }); |
| | | } |
| | | }); |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 删除本地逆变器 |
| | | * |
| | | * @param sid 设备sid |
| | | */ |
| | | private void removeInverter(String sid) { |
| | | //获取本地的毫米波 |
| | | GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getLocalGateway(sid); |
| | | if (gatewayBean != null) { |
| | | HDLLinkLocalGateway.getInstance().getGatewayList().remove(gatewayBean); |
| | | } |
| | | } |
| | | |
| | | /** |