Skip to content

Commit

Permalink
扫描网关设备,子设备未自动绑定
Browse files Browse the repository at this point in the history
Change-Id: Ib3e1adb3972420cc18ae9a06ef5632acce9680aa
  • Loading branch information
sevenhhe authored and archurcode committed Apr 9, 2021
1 parent 6e9a5a2 commit 096c132
Show file tree
Hide file tree
Showing 11 changed files with 192 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import com.tencent.iot.explorer.link.core.link.entity.TrtcDeviceInfo
import com.tencent.iot.explorer.link.customview.recyclerview.CRecyclerView
import com.tencent.iot.explorer.link.kitlink.consts.CommonField
import com.tencent.iot.explorer.link.kitlink.consts.LoadViewTxtType
import com.tencent.iot.explorer.link.kitlink.entity.BindDevResponse
import com.tencent.iot.explorer.link.kitlink.entity.GatewaySubDevsResp
import com.tencent.iot.explorer.link.kitlink.entity.ProdConfigDetailEntity
import com.tencent.iot.explorer.link.kitlink.entity.ProductGlobal
import com.tencent.iot.explorer.link.kitlink.response.ProductsConfigResponse
Expand Down Expand Up @@ -158,13 +160,56 @@ class DeviceCategoryActivity : PActivity(), MyCallback, CRecyclerView.RecyclerI
T.show(getString(R.string.add_sucess)) //添加成功
App.data.setRefreshLevel(2)
finish()

var resData = JSON.parseObject(response.data.toString(), BindDevResponse::class.java)
bindSubDev(resData)
} else {
T.show(response.msg)
}
}

RequestCode.bind_gateway_sub_device -> {
if (response.isSuccess()) {
App.data.refresh = true
App.data.setRefreshLevel(2)
com.tencent.iot.explorer.link.kitlink.util.Utils.sendRefreshBroadcast(this@DeviceCategoryActivity)
} else {
T.show(response.msg)
}
}
}
}

private fun bindSubDev(gatwayDev: BindDevResponse) {
if (gatwayDev != null && gatwayDev.Data != null && gatwayDev.Data!!.AppDeviceInfo != null) {
var dev = gatwayDev.Data!!.AppDeviceInfo
if (dev == null) return

if (dev.DeviceType == "1") {
HttpRequest.instance.gatwaySubDevList(dev.ProductId, dev.DeviceName, object: MyCallback{
override fun fail(msg: String?, reqCode: Int) {
T.show(msg?:"")
}

override fun success(response: BaseResponse, reqCode: Int) {
if (response.isSuccess()) {
var gatewaySubDevsResp = JSON.parseObject(response.data.toString(), GatewaySubDevsResp::class.java)
if (gatewaySubDevsResp != null && gatewaySubDevsResp.DeviceList != null && gatewaySubDevsResp.DeviceList.size > 0) {
for (subDev in gatewaySubDevsResp.DeviceList) {
if (subDev.BindStatus == 0) {
HttpRequest.instance.bindGatwaySubDev(dev.ProductId, dev.DeviceName, subDev.ProductId, subDev.DeviceName, this@DeviceCategoryActivity)
}
}
}
} else {
T.show(response.msg)
}
}
})
}
}
}

override fun doAction(
viewHolder: CRecyclerView.CViewHolder<*>,
clickView: View,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ import com.tencent.iot.explorer.link.kitlink.popup.FamilyListPopup
import com.tencent.iot.explorer.link.kitlink.util.DateUtils
import com.tencent.iot.explorer.link.kitlink.util.HttpRequest
import com.tencent.iot.explorer.link.core.auth.callback.MyCallback
import com.tencent.iot.explorer.link.core.auth.entity.DeviceEntity
import com.tencent.iot.explorer.link.core.auth.util.JsonManager
import com.tencent.iot.explorer.link.core.link.entity.DeviceInfo
import com.tencent.iot.explorer.link.core.link.entity.TrtcDeviceInfo
import com.tencent.iot.explorer.link.kitlink.entity.BindDevResponse
import com.tencent.iot.explorer.link.kitlink.entity.GatewaySubDevsResp
import com.tencent.iot.explorer.link.kitlink.entity.ProdConfigDetailEntity
import com.tencent.iot.explorer.link.kitlink.entity.ProductGlobal
import com.tencent.iot.explorer.link.kitlink.response.ProductsConfigResponse
Expand Down Expand Up @@ -359,10 +362,53 @@ class MainActivity : PActivity(), MyCallback {
App.data.refresh = true
App.data.setRefreshLevel(2)
com.tencent.iot.explorer.link.kitlink.util.Utils.sendRefreshBroadcast(this@MainActivity)

var resData = JSON.parseObject(response.data.toString(), BindDevResponse::class.java)
bindSubDev(resData)
} else {
T.show(response.msg)
}
}

RequestCode.bind_gateway_sub_device -> {
if (response.isSuccess()) {
App.data.refresh = true
App.data.setRefreshLevel(2)
com.tencent.iot.explorer.link.kitlink.util.Utils.sendRefreshBroadcast(this@MainActivity)
} else {
T.show(response.msg)
}
}
}
}

private fun bindSubDev(gatwayDev: BindDevResponse) {
if (gatwayDev != null && gatwayDev.Data != null && gatwayDev.Data!!.AppDeviceInfo != null) {
var dev = gatwayDev.Data!!.AppDeviceInfo
if (dev == null) return

if (dev.DeviceType == "1") {
HttpRequest.instance.gatwaySubDevList(dev.ProductId, dev.DeviceName, object: MyCallback{
override fun fail(msg: String?, reqCode: Int) {
T.show(msg?:"")
}

override fun success(response: BaseResponse, reqCode: Int) {
if (response.isSuccess()) {
var gatewaySubDevsResp = JSON.parseObject(response.data.toString(), GatewaySubDevsResp::class.java)
if (gatewaySubDevsResp != null && gatewaySubDevsResp.DeviceList != null && gatewaySubDevsResp.DeviceList.size > 0) {
for (subDev in gatewaySubDevsResp.DeviceList) {
if (subDev.BindStatus == 0) {
HttpRequest.instance.bindGatwaySubDev(dev.ProductId, dev.DeviceName, subDev.ProductId, subDev.DeviceName, this@MainActivity)
}
}
}
} else {
T.show(response.msg)
}
}
})
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.tencent.iot.explorer.link.kitlink.entity

class BindDevResponse {
var RequestId = ""
var Data: DeviceInfo? = null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.tencent.iot.explorer.link.kitlink.entity

import com.tencent.iot.explorer.link.core.auth.entity.DeviceEntity

class DeviceInfo {
var AppDeviceInfo: DeviceEntity? = null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.tencent.iot.explorer.link.kitlink.entity

class GatewaySubDevsResp {
var RequestId = ""
var Total = 0
var DeviceList = arrayListOf<SubDevice>()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.tencent.iot.explorer.link.kitlink.entity

class SubDevice {
var ProductId = ""
var DeviceName = ""
var DeviceId = ""
var AliasName = ""
var IconUrl = ""
var IconUrlGrid = ""
var BindStatus = 0
}
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ class HomeFragment : BaseFragment(), HomeFragmentView, MyCallback, PayloadMessag
presenter.model!!.run {
showFamily()
showRoomList()
showDeviceList(App.data.deviceList.size, roomId, deviceListEnd, shareDeviceListEnd)
loadCurrentWeather()
}
}
Expand Down Expand Up @@ -552,11 +551,13 @@ class HomeFragment : BaseFragment(), HomeFragmentView, MyCallback, PayloadMessag

// 显示设备列表
override fun showDeviceList(deviceSize: Int, roomId: String, deviceListEnd: Boolean, shareDeviceListEnd: Boolean) {
devList.clear()
shareDevList.clear()
if (deviceSize > 0) {
if (deviceListEnd) {
devList.clear()
devList.addAll(presenter.getIModel(this).deviceList)
devList.removeAll(presenter.getIModel(this).shareDeviceList)
}

if (shareDeviceListEnd) {
shareDevList.clear()
shareDevList.addAll(presenter.getIModel(this).shareDeviceList)
}

Expand Down Expand Up @@ -586,13 +587,16 @@ class HomeFragment : BaseFragment(), HomeFragmentView, MyCallback, PayloadMessag

override fun showDeviceOnline() {
for (i in 0 until devList.size) {
if (i >= presenter.getIModel(this).deviceList.size) {
continue
}
devList.get(i).online = presenter.getIModel(this).deviceList.get(i).online
}
for (i in 0 until shareDevList.size) {
if (i + devList.size >= presenter.getIModel(this).deviceList.size) {
if (i >= presenter.getIModel(this).shareDeviceList.size) {
continue
}
shareDevList.get(i).online = presenter.getIModel(this).deviceList.get(i + devList.size).online
shareDevList.get(i).online = presenter.getIModel(this).shareDeviceList.get(i).online
}
roomDevAdapter?.notifyDataSetChanged()
roomShareDevAdapter?.notifyDataSetChanged()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ class HttpRequest private constructor() {
param["FamilyId"] = familyId
param["RoomId"] = roomId
param["Offset"] = offset
param["Limit"] = 20
param["Limit"] = 999
tokenPost(param, callback, RequestCode.device_list)
}

Expand Down Expand Up @@ -1099,6 +1099,32 @@ class HttpRequest private constructor() {
tokenPost(param, callback, RequestCode.check_device_bind_token_state)
}

fun gatwaySubDevList(productId: String, davName: String, callback: MyCallback) {
val param = baseParams()
param["RequestId"] = UUID.randomUUID().toString()
param["Action"] = "AppGetGatewayBindDeviceList"
param["AccessToken"] = App.data.getToken()
param["RegionId"] = App.data.regionId
param["Limit"] = 100
param["Offset"] = 0
param["GatewayDeviceName"] = davName
param["GatewayProductId"] = productId
tokenPost(param, callback, RequestCode.gateway_sub_device_list)
}

fun bindGatwaySubDev(productId: String, davName: String, subProductId: String, subDevName: String, callback: MyCallback) {
val param = baseParams()
param["RequestId"] = UUID.randomUUID().toString()
param["Action"] = "AppBindSubDeviceInFamily"
param["AccessToken"] = App.data.getToken()
param["RegionId"] = App.data.regionId
param["GatewayDeviceName"] = davName
param["GatewayProductId"] = productId
param["ProductId"] = subProductId
param["DeviceName"] = subDevName
tokenPost(param, callback, RequestCode.bind_gateway_sub_device)
}

/**
* 手机请求加入房间
*/
Expand Down Expand Up @@ -1227,7 +1253,7 @@ class HttpRequest private constructor() {
fun shareDeviceList(offset: Int, callback: MyCallback) {
val param = tokenParams("AppListUserShareDevices")
param["Offset"] = offset
param["Limit"] = 50
param["Limit"] = 999
tokenPost(param, callback, RequestCode.share_device_list)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ object RequestCode {
const val sig_bind_device = 3014
const val trtc_call_device = 3015
const val device_product_info = 3016
const val gateway_sub_device_list = 3017
const val bind_gateway_sub_device = 3018

/*************设备接口结束**************/

Expand Down
Loading

0 comments on commit 096c132

Please sign in to comment.