panlili2024
9 天以前 84bb9a10e795b8839d9770eeb37aab71bf22e107
HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/HDLLink.java
@@ -2,23 +2,30 @@
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.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.connect.socket.HDLAuthSocket;
import com.hdl.sdk.connect.socket.HDLSocket;
@@ -164,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);
    }
    /**
@@ -256,6 +271,33 @@
    }
    /**
     * 获取设备列表
     */
    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
@@ -266,6 +308,35 @@
    }
    /**
     * 获取设备功能属性
     *
     * @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);
                }
            }
        });
    }
    /**
     * 设备控制
     *
     * @param request  控制状态参数
@@ -276,6 +347,35 @@
    }
    /**
     * 设备控制
     *
     * @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);
                }
            }
        });
    }
    /**
     * 读取状态
     *
     * @param sids     请求参数 指定读取的设备sid列表