Last Updated on : 2024-07-15 09:58:47download
The methods for replacing a faulty gateway include:
Get the management class for replacing a faulty gateway
val manager = DeviceBusinessDataManager.getInstance().getDeviceMigrationManager()
Check support for replacing the faulty gateway
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?) {
}
})
Implement replacement of faulty gateways as shown below only when the device supports it.
Check for any faulty gateways in the current home that can be migrated. If there is a faulty gateway, proceed with the replacement process.
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?
) {
}
})
Pass the device ID or the SN of the faulty gateway from step 1 to startMigrateGateway
to replace the gateway.
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?
) {
}
})
You can check the replacement status using a method or listener and then implement your business logic based on that status.
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?
) {
}
})
// Register a listener
private val listener = object : IMigratedStateListener {
override fun onMigratedStateChange(migrationInfo: MigrationInfo?) {
Toast.makeText(
this@DeviceMigrateActivity,
"Migration status: ${migrationInfo?.status}",
Toast.LENGTH_SHORT
).show()
}
}
manager?.addMigratedStateListener(listener)
// Unregister listener
manager?.addMigratedStateListener(listener)
This topic describes the service implementation in the sequence of read and create operations. In real-world projects, you can implement them as needed.
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback