| | |
| | | import com.hdl.photovoltaic.internet.api.HttpApi; |
| | | import com.hdl.photovoltaic.listener.BaseSuccessFailureCallBeak; |
| | | import com.hdl.photovoltaic.listener.CloudCallBeak; |
| | | import com.hdl.photovoltaic.ui.bean.CloudInverterDeviceBean; |
| | | import com.hdl.photovoltaic.ui.bean.HouseInfoBean; |
| | | import com.hdl.photovoltaic.ui.bean.HouseIdBean; |
| | | import com.hdl.sdk.link.common.exception.HDLLinkException; |
| | | 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 getResidenceImage(String imageUrl, CloudCallBeak<List<HouseIdBean>> cloudCallBeak) { |
| | | String requestUrl = imageUrl; |
| | | JsonObject json = new JsonObject(); |
| | | List<HouseIdBean> list = new ArrayList<>(); |
| | | 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()); |
| | | HouseBeanClass houseInfoBeanClass = gson.fromJson(jsonStr, HouseBeanClass.class); |
| | | } else { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(list); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(Exception exception) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onFailure(exception); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 添加【住宅详情】到本地缓存 |
| | |
| | | /** |
| | | * 切换住宅 |
| | | * |
| | | * @param homeId 住宅id |
| | | * @param houseIdBean 住宅Id对象 |
| | | */ |
| | | public Boolean switchHouse(String homeId) { |
| | | UserConfigManage.getInstance().setHomeId(homeId); |
| | | HdlThreadLogic.runThread(new Runnable() { |
| | | public void switchHouse(HouseIdBean houseIdBean) { |
| | | String oidHomeId = UserConfigManage.getInstance().getHomeId(); |
| | | // if (houseIdBean.getHomeId().equals(oidHomeId)) { |
| | | // return; |
| | | // } |
| | | //删除旧的住宅文件夹 |
| | | HdlFileLogic.getInstance().deleteDirectory(HdlFileLogic.getInstance().getCurrentHomeRootPath()); |
| | | //重新设置住宅id |
| | | UserConfigManage.getInstance().setHomeId(houseIdBean.getHomeId()); |
| | | //重新设置本地通讯秘钥 |
| | | UserConfigManage.getInstance().setLocalSecret(houseIdBean.getLocalSecret()); |
| | | //重新创建住宅文件夹 |
| | | HdlFileLogic.getInstance().createDirectory(); |
| | | //配置本地通信的信息 |
| | | initLocalLinkSdk(); |
| | | |
| | | HdlDeviceLogic.getInstance().searchGateway(new GatewayCallBack() { |
| | | @Override |
| | | public void run() { |
| | | //搜索一下住宅设备 |
| | | 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) { |
| | | |
| | | } |
| | | }); |
| | | } |
| | | }, null, null); |
| | | return true; |
| | | |
| | | @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); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 配置本地通信的信息(tcp通信用到) |
| | | */ |
| | | private void initLocalLinkSdk() { |
| | | HDLLinkConfig.getInstance().setHomeId(UserConfigManage.getInstance().getHomeId()); |
| | | HDLLinkConfig.getInstance().setLocalSecret(UserConfigManage.getInstance().getLocalSecret()); |
| | | |
| | | |
| | | } |
| | | |
| | | |