更新时间:2024-07-05 08:16:11下载pdf
替换故障网关能力包括:
获取替换故障网关管理类
val manager = DeviceBusinessDataManager.getInstance().getDeviceMigrationManager()
查看设备是否支持替换故障网关
manager?.isSupportedMigrationWithGwId(gwId, object : Business.ResultListener<Boolean> {
override fun onSuccess(response: BusinessResponse?, data: Boolean?, apiName: String?) {
}
override fun onFailure(response: BusinessResponse?, data: Boolean?, apiName: String?) {
}
})
只有当设备支持替换故障网关,方可根据下文的步骤来实现替换故障网关业务。
先查询当前家庭下是否有可以迁移的故障网关。若存在故障网关,则可进行故障网关替换。
manager?.getEnableMigratedGatewayList(
gwId,gid,object : Business.ResultListener<ArrayList<String>> {
override fun onSuccess(
response: BusinessResponse?,
data: ArrayList<String>?,
apiName: String?
) {
}
override fun onFailure(
response: BusinessResponse?,
data: ArrayList<String>?,
apiName: String?
) {
}
})
将步骤 1 查询到的故障网关的设备 ID(也可以是该设备的 SN 码)传入 startMigrateGateway
中,进行网关替换。
manager?.startMigrateGateway(
sourcesGwId,
targetGwId,
gid,
object : Business.ResultListener<MigrationInfo?> {
override fun onSuccess(
response: BusinessResponse?,
data: MigrationInfo?,
apiName: String?
) {
}
override fun onFailure(
response: BusinessResponse?,
data: MigrationInfo?,
apiName: String?
) {
}
})
可以通过接口直接查询当前网关迁移的状态,也可以通过注册监听器,监听网关迁移状态的变化,从而完成不同状态下的业务逻辑。
manager?.getMigratedGwState(gwId, object : Business.ResultListener<MigrationInfo?> {
override fun onSuccess(
response: BusinessResponse?,
data: MigrationInfo?,
apiName: String?
) {
}
override fun onFailure(
response: BusinessResponse?,
data: MigrationInfo?,
apiName: String?
) {
}
})
// 注册监听
private val listener = object : IMigratedStateListener {
override fun onMigratedStateChange(migrationInfo: MigrationInfo?) {
Toast.makeText(
this@DeviceMigrateActivity,
"迁移状态:${migrationInfo?.status}",
Toast.LENGTH_SHORT
).show()
}
}
manager?.addMigratedStateListener(listener)
// 注销监听
manager?.addMigratedStateListener(listener)
上述的步骤是按照查增的思路,完成替换故障网关业务。实际业务开发时,可灵活组合。
该内容对您有帮助吗?
是意见反馈该内容对您有帮助吗?
是意见反馈