panlili2024
2025-08-26 4a42989853dd83c0519d0684383430006b7e9625
HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/HDLLink.java
@@ -2,33 +2,36 @@
import android.content.Context;
import com.google.gson.reflect.TypeToken;
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.exception.HDLLinkException;
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.common.utils.gson.GsonConvert;
import com.hdl.sdk.connect.bean.LinkFunctionInfo;
import com.hdl.sdk.connect.bean.LinkResponse;
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.bean.response.BaseLocalResponse;
import com.hdl.sdk.connect.callback.HDLLinkCallBack;
import com.hdl.sdk.connect.callback.HDLLinkResponseCallBack;
import com.hdl.sdk.connect.callback.HDLLinkTCallBack;
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;
/**
@@ -168,51 +171,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;
        HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
        httpLoggingInterceptor.level(HttpLoggingInterceptor.Level.BODY);
        HxHttpConfig.getInstance()
                //.addInterceptor(new HttpCacheInterceptor())
                .addInterceptor(httpLoggingInterceptor).ignoreSSL();
        HdlCloudController.applyDeviceSecret(supplier, mac, spk, callBack);
    }
    /**
     * 检测更新
     *
     * @param appKey      appKey
     * @param appSecret   appSecret
     * @param versionCode 当前版本
     * @param appCode     appCode
     * @param listener    结果回调
     */
    public void checkAppVersion(Context context, String appKey, String appSecret, String versionCode, String appCode, CheckAppVersionListener listener) {
    public void checkAppVersion(String versionCode, String appCode, CheckAppVersionListener listener) {
        LogUtils.i("检测更新");
        HxHttpConfig.getInstance().init(context, HdlCloudApi.BASE_CHINA_URL)
                .addInterceptor(
                        new EncryptInterceptor(),
                        new SmartHeaderInterceptor());
        this.appKey = appKey;
        this.appSecret = appSecret;
        HdlCloudController.checkAppVersion(versionCode, appCode, listener);
    }
    /**
     * 初始化云端
     */
    public void initCloud(Context context, String appKey, String appSecret, String url) {
        HDLCloudConfig.getInstance().init(context, appKey, appSecret, 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.checkAppVersion(versionCode, appCode, listener);
    /**
     * 获取思必驰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);
    }
    /**
@@ -253,20 +264,76 @@
    }
    /**
     * 获取功能列表
     * 获取设备列表
     */
    public void getFunctionList(HDLLinkCallBack callBack) {
        HDLSocket.getInstance().getFunctionList(callBack);
    }
    /**
     * 获取功能属性
     * 获取设备列表
     */
    public void getFunctionInfoList(HDLLinkTCallBack<List<LinkFunctionInfo>> callBack) {
        getFunctionList(new HDLLinkCallBack() {
            @Override
            public void onSuccess(String msg) {
                LinkResponse linkResponse = GsonConvert.getGson().fromJson(msg, new TypeToken<LinkResponse>() {
                }.getType());
                final BaseLocalResponse<List<LinkFunctionInfo>> listBaseLocalResponse = GsonConvert.getGson().fromJson(linkResponse.getData(), new TypeToken<BaseLocalResponse<List<LinkFunctionInfo>>>() {
                }.getType());
                if (callBack != null) {
                    callBack.onSuccess(listBaseLocalResponse.getObjects());
                }
            }
            @Override
            public void onError(HDLLinkException e) {
                if (callBack != null) {
                    callBack.onError(e);
                }
            }
        });
    }
    /**
     * 获取设备功能属性
     *
     * @param sids
     * @param callBack
     */
    public void getFunctionAttribute(List<String> sids, HDLLinkCallBack callBack) {
        HDLSocket.getInstance().getFunctionAttribute(sids, callBack);
    }
    /**
     * 获取设备功能属性
     *
     * @param sids
     * @param callBack
     */
    public void getFunctionAttributeInfo(List<String> sids, HDLLinkTCallBack<List<LinkFunctionInfo>> callBack) {
        getFunctionAttribute(sids, new HDLLinkCallBack() {
            @Override
            public void onSuccess(String msg) {
                LinkResponse linkResponse = GsonConvert.getGson().fromJson(msg, new TypeToken<LinkResponse>() {
                }.getType());
                final BaseLocalResponse<List<LinkFunctionInfo>> listBaseLocalResponse = GsonConvert.getGson().fromJson(linkResponse.getData(), new TypeToken<BaseLocalResponse<List<LinkFunctionInfo>>>() {
                }.getType());
                if (callBack != null) {
                    callBack.onSuccess(listBaseLocalResponse.getObjects());
                }
            }
            @Override
            public void onError(HDLLinkException e) {
                if (callBack != null) {
                    callBack.onError(e);
                }
            }
        });
    }
    /**
@@ -277,6 +344,35 @@
     */
    public void propertyDown(List<DeviceControlRequest> request, HDLLinkCallBack callBack) {
        HDLSocket.getInstance().propertyDown(request, callBack);
    }
    /**
     * 设备控制
     *
     * @param request  控制状态参数
     * @param callBack 结果回调
     */
    public void propertyDownDevice(List<DeviceControlRequest> request, HDLLinkTCallBack<String> callBack) {
        propertyDown(request, new HDLLinkCallBack() {
            @Override
            public void onSuccess(String msg) {
                LinkResponse linkResponse = GsonConvert.getGson().fromJson(msg, new TypeToken<LinkResponse>() {
                }.getType());
                final BaseLocalResponse<String> listBaseLocalResponse = GsonConvert.getGson().fromJson(linkResponse.getData(), new TypeToken<BaseLocalResponse<String>>() {
                }.getType());
                if (callBack != null) {
                    callBack.onSuccess(listBaseLocalResponse.getObjects());
                }
            }
            @Override
            public void onError(HDLLinkException e) {
                if (callBack != null) {
                    callBack.onError(e);
                }
            }
        });
    }
    /**
@@ -337,6 +433,41 @@
    }
    /**
     * 获取房间列表
     */
    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次
     *