编辑 | blame | 历史 | 原始文档

地热类模块

地热类模块支持搜索和控制的类型

地热模块(大类 8 小类 0)

一、地热模块查询状态

接口描述

HDLCommand.getGeothermalStateFromNetwork(AppliancesInfo info)

调用该接口,获取地热模块设备状态。

代码范例

    //查询地热模块状态信息
    HDLCommand.getGeothermalStateFromNetwork(appliancesInfo);

查询状态回调事件监听

查询状态超时或成功,都会收到DeviceStateEvent订阅事件,SDK所有状态回调都统一用这个事件,如果event.isSuccess()值为false,则代表查询超时,没收到设备回复;

开发者可以在所需要获取状态回调的地方,订阅该事件;
并通过比较前设备和回调状态设备的子网号(getDeviceSubnetID)、设备号(getDeviceDeviceID)、AppliancesInfo里面的设备类型(getDeviceType)和回路号(getChannelNum)是否一致,从而判断该消息事件为当前设备查询状态返回的消息,进行下一步处理,不一致则过滤不处理。

代码范例
```java

@Subscribe(threadMode = ThreadMode.MAIN)
public void onDeviceStateEventMain(DeviceStateEvent event) {
    proDialog.dismiss();
    if (event.getAppliancesInfo().getDeviceSubnetID() == appliancesInfo.getDeviceSubnetID()
            && event.getAppliancesInfo().getDeviceDeviceID() == appliancesInfo.getDeviceDeviceID()
    ) {
        //这个返回的信息是当前状态的
        switch (event.getAppliancesInfo().getDeviceType()) {
            case HDLApConfig.TYPE_GEOTHERMAL_MODULE:
                if (appliancesInfo.getChannelNum() == event.getAppliancesInfo().getChannelNum()) {
                    if (!event.isSuccess()) {
                        showToast("获取地热状态失败,请重新再试");
                        return;
                    }
                    String message = "";
                    GeothermalBackInfo mGeothermalBackInfo = new GeothermalBackInfo(event.appliancesInfo, false);

                    if (mGeothermalBackInfo == null) {
                        showToast("获取地热状态失败,请重新再试");
                        return;
                    }

                    showGeothermalBackInfo(mGeothermalBackInfo);

                }
                break;
        }
    }
}


### 二、地热模块控制改变状态 **接口描述** HDLCommand.geothermalCtrl(AppliancesInfo info, int type, int state) type:需要控制功能命令参数 state:需要控制功能对应的状态值 调用该接口,可以控制改变地热模块的,开、关、模式、温度等状态。 模式:1 = 普通模式, 2 = 白天模式 , 3 = 夜间模式, 4 = 离开模式, 5 = 自动模式。 温度:普通温度,白天温度,夜间温度,离开温度 **代码范例**
.......
//发送控制地热模块 打开指令 
//地热开
HDLCommand.geothermalCtrl(appliancesInfo, GeothermalParser.gSwich, GeothermalParser.gSwichOn);
.......

.......
//发送控制地热模块 改变模式指令 
//若当前模式自动模式,则点击按钮设置为普通模式
HDLCommand.geothermalCtrl(appliancesInfo, GeothermalParser.gMode, GeothermalParser.gModeNormal);
.......

.......
//发送控制地热模块 改变温度指令 
HDLCommand.geothermalCtrlTemp(appliancesInfo, tempInt);//自动根据当前模式设置当前模式的温度。
.......

**控制状态回调事件监听** 控制状态超时或成功,都会收到GeothermalFeedBackEvent订阅事件,如果event.isSuccess()值为false,则代表控制超时,没收到设备回复; 并通过比较前设备和回调状态设备的子网号(getDeviceSubnetID)、设备号(getDeviceDeviceID)和回路号(getChannelNum)是否一致,从而判断该消息事件为当前设备控制状态返回的消息,进行下一步处理,不一致则过滤不处理。 **代码范例**
/**
 * 地热控制回调Event
 *
 * @param event
 */
@Subscribe(threadMode = ThreadMode.MAIN)
public void onGeothermalFeedBackEventMain(GeothermalFeedBackEvent event) {
    proDialog.dismiss();
    if (event.getGeothermalBackInfo().getAppliancesInfo().getDeviceDeviceID() == appliancesInfo.getDeviceDeviceID()
            && event.getGeothermalBackInfo().getAppliancesInfo().getDeviceSubnetID() == appliancesInfo.getDeviceSubnetID()
            && event.getGeothermalBackInfo().getAppliancesInfo().getChannelNum() == appliancesInfo.getChannelNum()
    ) {
        //先判断是否超时
        if (event.getStatusID() == EventCode.FAILURE_TIMEOUT) {
            showToast("地热模块控制超时,请重新再试");
            return;
        }

        if (event.getStatusID() == EventCode.FAILURE_DATA_ERROR) {
            showToast("地热模块,返回数据为空");
            return;
        }
        GeothermalBackInfo mGeothermalBackInfo = event.getGeothermalBackInfo();
        showGeothermalBackInfo(mGeothermalBackInfo);
    }
}

.......
/**
 * showGeothermalBackInfo
 * @param mGeothermalBackInfo
 */
private void showGeothermalBackInfo(GeothermalBackInfo mGeothermalBackInfo){
    String message = "";
    if(mGeothermalBackInfo.getIsOn() == GeothermalParser.gSwichOn) {
        message = getSwichStateString(mGeothermalBackInfo.getIsOn());

        message += "\n" + getModeStateString(mGeothermalBackInfo.getgMode());
        message += "\n" + "普通模式温度:" + mGeothermalBackInfo.getgNormalTemp();
        message += "\n" + "白天模式温度:" + mGeothermalBackInfo.getgDayTemp();
        message += "\n" + "夜间模式温度:" + mGeothermalBackInfo.getgNightTemp();
        message += "\n" + "离开模式温度:" + mGeothermalBackInfo.getgLeaveTemp();
    }else {
        message = getSwichStateString(mGeothermalBackInfo.getIsOn());
    }


    mTextView.setText(message);
    showToast(message);
    HDLLog.I(message);
}
.......

```