Skip to content

Commit

Permalink
feature(TestApp): Remove Field.METADATA from "casual" queries
Browse files Browse the repository at this point in the history
Splitting up fetching the FIELD_TYPE and fetching the actual
query from the user into two separate ones.
Unfortunately this did not fix the crash when logging vehicle
because the json contained to many lineBreaks ("\n").

Closes: #24
Signed-off-by: Andre Weber <andre.weber3@etas.com>
  • Loading branch information
wba2hi committed Dec 6, 2023
1 parent eb58139 commit fac8d85
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class KuksaDataBrokerActivity : ComponentActivity() {
}

vssPropertiesViewModel.onGetProperty = { property: Property ->
fetchPropertyFieldType(property)
fetchProperty(property)
}

Expand Down Expand Up @@ -212,26 +213,40 @@ class KuksaDataBrokerActivity : ComponentActivity() {
dataBrokerEngine.unregisterDisconnectListener(onDisconnectListener)
}

private fun fetchPropertyFieldType(property: Property) {
dataBrokerEngine.fetch(
property.copy(fields = listOf(Field.FIELD_METADATA)),
object : CoroutineCallback<GetResponse>() {
override fun onSuccess(result: GetResponse?) {
val automaticValueType = result?.metadata?.valueType ?: Datapoint.ValueCase.VALUE_NOT_SET
Log.d(TAG, "Fetched automatic value type from meta data: $automaticValueType")

val vssProperties = vssPropertiesViewModel.vssProperties
.copy(valueType = automaticValueType)
vssPropertiesViewModel.updateVssProperties(vssProperties)
}

override fun onError(error: Throwable) {
// intentionally ignored
}
},
)
}

private fun fetchProperty(property: Property) {
Log.d(TAG, "Fetch property: $property")

dataBrokerEngine.fetch(
property,
object : CoroutineCallback<GetResponse>() {
override fun onSuccess(result: GetResponse?) {
val automaticValueType = result?.metadata?.valueType ?: Datapoint.ValueCase.VALUE_NOT_SET
Log.d(TAG, "Fetched automatic value type from meta data: $automaticValueType")

val errorsList = result?.errorsList
errorsList?.forEach {
outputViewModel.appendOutput(it.toString())

return
}

val vssProperties = vssPropertiesViewModel.vssProperties
.copy(valueType = automaticValueType)
vssPropertiesViewModel.updateVssProperties(vssProperties)

outputViewModel.appendOutput(result.toString())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,18 @@ class VSSPropertiesViewModel : ViewModel() {
private set

val valueTypes: List<ValueCase> = ValueCase.values().toList()
val fieldTypes: List<Field> = listOf(Field.FIELD_VALUE, Field.FIELD_ACTUATOR_TARGET)
val fieldTypes: List<Field> = listOf(
Field.FIELD_VALUE,
Field.FIELD_ACTUATOR_TARGET,
Field.FIELD_METADATA,
)

val datapoint: Datapoint
get() = vssProperties.valueType.createDatapoint(vssProperties.value)

// Meta data are always part of the properties
val property: Property
get() = Property(vssProperties.vssPath, listOf(vssProperties.fieldType, Field.FIELD_METADATA))
get() = Property(vssProperties.vssPath, listOf(vssProperties.fieldType))

fun updateVssProperties(vssProperties: VSSProperties = VSSProperties()) {
this.vssProperties = vssProperties
Expand Down

0 comments on commit fac8d85

Please sign in to comment.