Replace Faulty Gateway

Last Updated on : 2024-07-15 09:58:47download

The methods for replacing a faulty gateway include:

  • Check support for replacing the faulty gateway
  • Query the list of faulty gateways
  • Start replacing faulty gateway
  • Check replacement status
  • Replacement status listener

Prerequisites

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.

Step 1: Query the list of faulty gateways eligible for migration

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?
        ) {

        }
    })

Step 2: Start replacing faulty gateway

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?
        ) {

        }
    })

Step 3: Check replacement status

You can check the replacement status using a method or listener and then implement your business logic based on that status.

Request replacement 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 for replacement status events

// 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)

Demo

This topic describes the service implementation in the sequence of read and create operations. In real-world projects, you can implement them as needed.