Skip to content

Commit

Permalink
腾讯连连支持字符串枚举
Browse files Browse the repository at this point in the history
http://tapd.oa.com/NEW_IOT/prong/stories/view/1020393192866423729

Change-Id: I056611c5d7eb630ffeb6748f2d79584715c3a5b6
  • Loading branch information
sevenhhe committed Sep 8, 2021
1 parent dd44880 commit 0585aba
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class DeviceModeInfoActivity : BaseActivity(), MyCallback {
if (devModeInfo.define == null) return

var type = devModeInfo.define!!.get("type")
if (type == "bool" || type == "enum") {
if (type == "bool" || type == "enum" || type == "stringenum") {
showMapDialog(pos, devModeInfo)
} else if (type == "int") {
showNumDialog(true, pos, devModeInfo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ class EditAutoicTaskActivity : BaseActivity(), MyCallback {
if (devModeInfo.id == task.actionId) {
task.taskTip = devModeInfo.name
var type = devModeInfo.define!!.get("type")
if (type == "bool" || type == "enum") {
if (type == "bool" || type == "enum" || type == "stringenum") {
var mapJson = devModeInfo.define!!.getJSONObject("mapping")
for (key in mapJson.keys) {
if (key == task.taskKey) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class EditManualTaskActivity : BaseActivity(), MyCallback {
if (devModeInfo.id == task.actionId) {
task.taskTip = devModeInfo.name
var type = devModeInfo.define!!.get("type")
if (type == "bool" || type == "enum") {
if (type == "bool" || type == "enum" || type == "stringenum") {
var mapJson = devModeInfo.define!!.getJSONObject("mapping")
for (key in mapJson.keys) {
if (key == task.taskKey) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,21 @@ class DevicePropertyEntity {

fun getValue(): String {
return when {
isEnumType() -> value?.toString() ?: "0"
isEnumType() -> {
if (valueType == "enum") {
value?.toString() ?: "0"
} else {
var ret = "0"
enumEntity?.mapping?.keys?.let {
for (key in it) {
ret = key
break
}
}
ret
value?.toString() ?: ret
}
}
isNumberType() -> value?.toString()?.toDouble()?.toInt()?.toString()
?: numberEntity!!.min.toDouble().toInt().toString()
isTimestampType() -> value?.toString() ?: "0"
Expand Down Expand Up @@ -134,7 +148,7 @@ class DevicePropertyEntity {
}

fun isEnumType(): Boolean {
if (valueType == "enum") {
if (valueType == "enum" || valueType == "stringenum") {
return true
}
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ class HomeFragment : BaseFragment(), HomeFragmentView, MyCallback, PayloadMessag
devOption.id = devModeInfo.id
devOption.res = res
var type = devModeInfo.define!!.get("type")
if (type == "bool" || type == "enum") {
if (type == "bool" || type == "enum" || type == "stringenum") {
var mapJson = devModeInfo.define!!.getJSONObject("mapping")
devOption.mapJson = mapJson
devOption.type = DevOption.TYPE_LIST
Expand All @@ -445,7 +445,7 @@ class HomeFragment : BaseFragment(), HomeFragmentView, MyCallback, PayloadMessag
for (devData in dev.deviceDataList) {
if (devModeInfo.id == devData.id) {
var type = devModeInfo.define!!.get("type")
if (type == "bool" || type == "enum") {
if (type == "bool" || type == "enum" || type == "stringenum") {
var mapJson = devModeInfo.define!!.getJSONObject("mapping")
if (!TextUtils.isEmpty(devData.value)) {
devOption.value = mapJson.getString(devData.value)
Expand All @@ -469,7 +469,7 @@ class HomeFragment : BaseFragment(), HomeFragmentView, MyCallback, PayloadMessag
if (!hasValue) {
var initData = DeviceDataEntity()
initData.id = devModeInfo.id
if (type == "bool" || type == "enum") {
if (type == "bool" || type == "enum" || type == "stringenum") {

} else if (type == "int" || type == "float") {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ControlPanel {

fun isEnumType(): Boolean {
return when (valueType) {
"enum" -> true
"enum", "stringenum" -> true
else -> false
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tencent.iot.explorer.link.core.auth.entity

import android.util.Log
import com.alibaba.fastjson.JSON
import com.tencent.iot.explorer.link.core.auth.util.JsonManager

Expand All @@ -20,7 +21,7 @@ class EventParam {
"int", "float" -> {
productDefine = JsonManager.parseJson(define, NumberDefine::class.java)
}
"enum" -> {
"enum", "stringenum" -> {
productDefine = JsonManager.parseJson(define, EnumDefine::class.java)
}
"bool" -> {
Expand Down Expand Up @@ -58,7 +59,7 @@ class EventParam {

fun isEnumType(): Boolean {
return when (getType()) {
"enum" -> true
"enum", "stringenum" -> true
else -> false
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tencent.iot.explorer.link.core.auth.entity

import android.util.Log
import com.alibaba.fastjson.JSON
import com.alibaba.fastjson.JSONObject
import com.tencent.iot.explorer.link.core.auth.util.JsonManager
Expand Down Expand Up @@ -28,7 +29,7 @@ class ProductProperty {
"int", "float" -> {
productDefine = JsonManager.parseJson(define, NumberDefine::class.java)
}
"enum" -> {
"enum", "stringenum" -> {
productDefine = JsonManager.parseJson(define, EnumDefine::class.java)
}
"bool" -> {
Expand Down Expand Up @@ -71,7 +72,7 @@ class ProductProperty {

fun isEnumType(): Boolean {
return when (getType()) {
"enum" -> true
"enum", "stringenum" -> true
else -> false
}
}
Expand Down

0 comments on commit 0585aba

Please sign in to comment.