panlili2024
2025-03-05 134209ad70f82051da3ce63471df0cc8f778e57d
HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/HDLLink.java
@@ -3,29 +3,29 @@
import android.content.Context;
import com.hdl.hdlhttp.HxHttpConfig;
import com.hdl.sdk.common.event.DeleteNetworkListener;
import com.hdl.sdk.common.event.EventDispatcher;
import com.hdl.sdk.common.event.EventListener;
import com.hdl.sdk.common.utils.LogUtils;
import com.hdl.sdk.common.utils.ThreadToolUtils;
import com.hdl.sdk.connect.bean.request.DeviceAuthRequest;
import com.hdl.sdk.connect.bean.request.AuthenticateRequest;
import com.hdl.sdk.connect.bean.request.DeviceControlRequest;
import com.hdl.sdk.connect.bean.request.ListSidRequest;
import com.hdl.sdk.connect.bean.request.ListUploadRequest;
import com.hdl.sdk.connect.callback.HDLLinkCallBack;
import com.hdl.sdk.connect.callback.HDLLinkResponseCallBack;
import com.hdl.sdk.connect.cloud.CallBackListener;
import com.hdl.sdk.connect.cloud.CheckAppVersionListener;
import com.hdl.sdk.connect.cloud.HdlCloudApi;
import com.hdl.sdk.connect.cloud.HdlCloudController;
import com.hdl.sdk.connect.cloud.interceptor.EncryptInterceptor;
import com.hdl.sdk.connect.cloud.interceptor.SmartHeaderInterceptor;
import com.hdl.sdk.connect.cloud.listener.GatewayListener;
import com.hdl.sdk.connect.cloud.listener.SibichiListener;
import com.hdl.sdk.connect.config.HDLCloudConfig;
import com.hdl.sdk.connect.config.HDLLinkConfig;
import com.hdl.sdk.common.event.EventDispatcher;
import com.hdl.sdk.common.event.EventListener;
import com.hdl.sdk.connect.bean.request.AuthenticateRequest;
import com.hdl.sdk.connect.socket.HDLAuthSocket;
import com.hdl.sdk.connect.socket.HDLSocket;
import java.util.List;
import java.util.concurrent.TimeUnit;
import io.reactivex.rxjava3.disposables.Disposable;
import okhttp3.logging.HttpLoggingInterceptor;
/**
@@ -40,6 +40,7 @@
    private static final HDLLink instance = new HDLLink();
    private String appKey, appSecret;
    public DeleteNetworkListener listener;
    /**
     * getInstance
@@ -92,6 +93,15 @@
        EventDispatcher.getInstance().removeAllTopicsListener(listener);
    }
    /**
     * 注册退网主题的监听
     *
     * @param listener
     */
    public synchronized void setDeleteNetworkListener(DeleteNetworkListener listener) {
        this.listener = listener;
    }
    /***********************三方设备和网关通信之前的认证流程****************************/
    /**
     * 检测是否已经认证过
@@ -105,6 +115,10 @@
    public void selectNetwork(String networkName) {
        HDLLinkConfig.getInstance().setNetworkName(networkName);
    }
    public String getParentOid() {
        return HDLLinkConfig.getInstance().getParentOid();
    }
    /**
@@ -140,6 +154,7 @@
     */
    public void UploadDeviceAuth(String mac, String result, String message, String auth_code, HDLLinkCallBack callBack) {
        HDLSocket.getInstance().UploadDeviceAuth(mac, result, message, auth_code, callBack);
    }
    /**
@@ -150,23 +165,59 @@
     * @param spk      设备spk
     * @param callBack 结果回调
     */
    public void applyDeviceSecret(Context context, String appKey, String appSecret, String supplier, String mac, String spk, CallBackListener callBack) {
    public void applyDeviceSecret(String supplier, String mac, String spk, CallBackListener callBack) {
        LogUtils.i("申请设备密钥");
        HxHttpConfig.getInstance().init(context, HdlCloudApi.BASE_CHINA_URL)
                .addInterceptor(
                        new EncryptInterceptor(),
                        new SmartHeaderInterceptor());
        this.appKey = appKey;
        this.appSecret = appSecret;
        HdlCloudController.applyDeviceSecret(supplier, mac, spk, callBack);
    }
    /**
     * 检测更新
     *
     * @param versionCode 当前版本
     * @param appCode     appCode
     * @param listener    结果回调
     */
    public void checkAppVersion(String versionCode, String appCode, CheckAppVersionListener listener) {
        LogUtils.i("检测更新");
        HdlCloudController.checkAppVersion(versionCode, appCode, listener);
    }
    /**
     * 初始化云端
     */
    public void initCloud(Context context, String appKey, String appSecret) {
        HDLCloudConfig.getInstance().init(context, appKey, appSecret, HdlCloudApi.BASE_CHINA_URL);
        HxHttpConfig.getInstance().ignoreSSL();
        HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
        httpLoggingInterceptor.level(HttpLoggingInterceptor.Level.BODY);
        HxHttpConfig.getInstance().addInterceptor(httpLoggingInterceptor);
        HxHttpConfig.getInstance()
                //.addInterceptor(new HttpCacheInterceptor())
                .addInterceptor(httpLoggingInterceptor).ignoreSSL();
    }
        HdlCloudController.applyDeviceSecret(supplier, mac, spk, callBack);
    /**
     * 获取思必驰token
     *
     * @param homeId   homeId
     * @param clientId clientId
     * @param listener 结果回调
     */
    public void getSibichiToken(String homeId, String clientId, SibichiListener listener) {
        LogUtils.i("获取思必驰token");
        HdlCloudController.getSibichiToken(homeId, clientId, listener);
    }
    /**
     * 获取主网关信息
     *
     * @param homeId   homeId
     * @param listener 结果回调
     */
    public void syncMainGateway(String homeId, GatewayListener listener) {
        LogUtils.i("获取主网关信息");
        HdlCloudController.syncMainGateway(homeId, listener);
    }
    /**
@@ -207,14 +258,14 @@
    }
    /**
     * 获取功能列表
     * 获取设备列表
     */
    public void getFunctionList(HDLLinkCallBack callBack) {
        HDLSocket.getInstance().getFunctionList(callBack);
    }
    /**
     * 获取功能属性
     * 获取设备功能属性
     *
     * @param sids
     * @param callBack
@@ -251,6 +302,16 @@
    }
    /**
     * 场景详情
     *
     * @param sids     场景sid列表
     * @param callBack 回调
     */
    public void getScene(List<String> sids, HDLLinkCallBack callBack) {
        HDLSocket.getInstance().getScene(sids, callBack);
    }
    /**
     * 场景控制
     *
     * @param sids     场景sid列表
@@ -271,6 +332,51 @@
    }
    /**
     * 上报sid列表
     *
     * @param requestList sid列表
     * @param callBack    回调
     */
    public void UploadSidList(List<ListSidRequest> requestList, HDLLinkCallBack callBack) {
        HDLSocket.getInstance().UploadSidList(requestList, callBack);
    }
    /**
     * 获取房间列表
     */
    public void getRoomList(HDLLinkCallBack callBack) {
        HDLSocket.getInstance().getRoomList(callBack);
    }
    /**
     * 房间绑定关系列表获取
     *
     * @param uid      房间uid列表
     * @param callBack 回调
     */
    public void getRoomBindList(List<String> uid, HDLLinkCallBack callBack) {
        HDLSocket.getInstance().getRoomBindList(uid, callBack);
    }
    /**
     * 获取自动化列表
     */
    public void getLogicList(HDLLinkCallBack callBack) {
        HDLSocket.getInstance().getLogicList(callBack);
    }
    /**
     * ⾃动化启⽤禁⽤
     *
     * @param sid      自动化sid
     * @param enable   true=启⽤ false=禁⽤
     * @param callBack 回调
     */
    public void editEnableLogic(String sid, boolean enable, HDLLinkCallBack callBack) {
        HDLSocket.getInstance().editEnableLogic(sid, enable, callBack);
    }
    /**
     * 通用UDP发送指令
     * 1秒没响应就让他重新发送,重试3次
     *