Skip to content

Commit

Permalink
Support timeout null instead of requiring ZERO for no timeout (#30967)
Browse files Browse the repository at this point in the history
* Support timeout null instead of requiring ZERO for no timeout

* Address review comments
  • Loading branch information
yufengwangca authored and pull[bot] committed Feb 16, 2024
1 parent a5a6d67 commit 1531752
Show file tree
Hide file tree
Showing 82 changed files with 1,174 additions and 2,206 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,33 +185,19 @@ class {{cluster.name}}Cluster(private val controller: MatterController, private
{% for command in cluster.commands | sort(attribute='code') -%}
{%- set callbackName = command | javaCommandCallbackName() %}
suspend fun {{command.name | lowfirst_except_acronym}}(
{%- if command.input_param -%}
{%- for field in (cluster.structs | named(command.input_param)).fields -%}
{{field.name | lowfirst_except_acronym}}: {{encode_value(cluster, field | asEncodable(typeLookup), 0)}}
{%- if not loop.last -%}, {% endif %}
{%- endfor -%}
{%- if command.is_timed_invoke -%}
, timedInvokeTimeoutMs: Int)
{%- else -%}
, timedInvokeTimeoutMs: Int? = null)
{%- endif -%}
{%- else -%}
{%- if command.is_timed_invoke -%}
timedInvokeTimeoutMs: Int)
{%- else -%}
timedInvokeTimeoutMs: Int? = null)
{%- endif -%}
{%- endif -%}
{%- if command.input_param -%}
{%- for field in (cluster.structs | named(command.input_param)).fields -%}
{{field.name | lowfirst_except_acronym}}: {{encode_value(cluster, field | asEncodable(typeLookup), 0)}}
,
{%- endfor -%}
{%- endif -%}
timedInvokeTimeout: Duration {%- if not command.is_timed_invoke -%}? = null {%- endif -%}
)
{%- if command | hasResponse -%}
: {{callbackName}} {
{%- else %} {
{%- endif %}
val commandId: UInt = {{command.code}}u
{% if command.is_timed_invoke -%}
val timeoutMs: Duration = Duration.ofMillis(timedInvokeTimeoutMs.toLong())
{%- else -%}
val timeoutMs: Duration = timedInvokeTimeoutMs?.let { Duration.ofMillis(it.toLong()) } ?: Duration.ZERO
{%- endif %}

val tlvWriter = TlvWriter()
tlvWriter.startStructure(AnonymousTag)
Expand All @@ -229,7 +215,7 @@ class {{cluster.name}}Cluster(private val controller: MatterController, private
InvokeRequest(
CommandPath(endpointId, clusterId = CLUSTER_ID, commandId),
tlvPayload = tlvWriter.getEncoded(),
timedRequest = timeoutMs
timedRequest = timedInvokeTimeout
)

val response: InvokeResponse = controller.invoke(request)
Expand Down Expand Up @@ -271,7 +257,6 @@ class {{cluster.name}}Cluster(private val controller: MatterController, private
{% endfor %}

else {
// Skip unknown tags
tlvReader.skipElement()
}
}
Expand Down Expand Up @@ -351,18 +336,9 @@ class {{cluster.name}}Cluster(private val controller: MatterController, private
{%- set attribute_id = "ATTRIBUTE_ID_" + attribute.definition.name | upper %}
suspend fun write{{ attribute.definition.name | upfirst }}Attribute(
value: {{ encode_value_without_optional_nullable(cluster, encodable, 0) }},
{%- if attribute.requires_timed_write -%}
timedWriteTimeoutMs: Int
{%- else %}
timedWriteTimeoutMs: Int? = null
{%- endif %}
timedWriteTimeout: Duration {%- if not attribute.requires_timed_write -%}? = null {%- endif -%}
) {
val ATTRIBUTE_ID: UInt = {{attribute.definition.code}}u
{% if attribute.requires_timed_write -%}
val timeoutMs: Duration = Duration.ofMillis(timedWriteTimeoutMs.toLong())
{%- else -%}
val timeoutMs: Duration = timedWriteTimeoutMs?.let { Duration.ofMillis(it.toLong()) } ?: Duration.ZERO
{%- endif %}

val tlvWriter = TlvWriter()
{%- set encodable = attribute.definition | asEncodable(typeLookup) %}
Expand All @@ -387,7 +363,7 @@ class {{cluster.name}}Cluster(private val controller: MatterController, private
tlvPayload = tlvWriter.getEncoded()
)
),
timedRequest = timeoutMs
timedRequest = timedWriteTimeout
)

val response: WriteResponse = controller.write(writeRequests)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,9 @@ class AccessControlCluster(

suspend fun writeAclAttribute(
value: List<AccessControlClusterAccessControlEntryStruct>,
timedWriteTimeoutMs: Int? = null
timedWriteTimeout: Duration? = null
) {
val ATTRIBUTE_ID: UInt = 0u
val timeoutMs: Duration =
timedWriteTimeoutMs?.let { Duration.ofMillis(it.toLong()) } ?: Duration.ZERO

val tlvWriter = TlvWriter()
tlvWriter.startArray(AnonymousTag)
Expand All @@ -111,7 +109,7 @@ class AccessControlCluster(
tlvPayload = tlvWriter.getEncoded()
)
),
timedRequest = timeoutMs
timedRequest = timedWriteTimeout
)

val response: WriteResponse = controller.write(writeRequests)
Expand Down Expand Up @@ -179,11 +177,9 @@ class AccessControlCluster(

suspend fun writeExtensionAttribute(
value: List<AccessControlClusterAccessControlExtensionStruct>,
timedWriteTimeoutMs: Int? = null
timedWriteTimeout: Duration? = null
) {
val ATTRIBUTE_ID: UInt = 1u
val timeoutMs: Duration =
timedWriteTimeoutMs?.let { Duration.ofMillis(it.toLong()) } ?: Duration.ZERO

val tlvWriter = TlvWriter()
tlvWriter.startArray(AnonymousTag)
Expand All @@ -202,7 +198,7 @@ class AccessControlCluster(
tlvPayload = tlvWriter.getEncoded()
)
),
timedRequest = timeoutMs
timedRequest = timedWriteTimeout
)

val response: WriteResponse = controller.write(writeRequests)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@ class AccountLoginCluster(

suspend fun getSetupPIN(
tempAccountIdentifier: String,
timedInvokeTimeoutMs: Int
timedInvokeTimeout: Duration
): GetSetupPINResponse {
val commandId: UInt = 0u
val timeoutMs: Duration = Duration.ofMillis(timedInvokeTimeoutMs.toLong())

val tlvWriter = TlvWriter()
tlvWriter.startStructure(AnonymousTag)
Expand All @@ -65,7 +64,7 @@ class AccountLoginCluster(
InvokeRequest(
CommandPath(endpointId, clusterId = CLUSTER_ID, commandId),
tlvPayload = tlvWriter.getEncoded(),
timedRequest = timeoutMs
timedRequest = timedInvokeTimeout
)

val response: InvokeResponse = controller.invoke(request)
Expand All @@ -82,7 +81,6 @@ class AccountLoginCluster(
if (tag == ContextSpecificTag(TAG_SETUP_P_I_N)) {
setupPIN_decoded = tlvReader.getString(tag)
} else {
// Skip unknown tags
tlvReader.skipElement()
}
}
Expand All @@ -100,10 +98,9 @@ class AccountLoginCluster(
tempAccountIdentifier: String,
setupPIN: String,
node: ULong?,
timedInvokeTimeoutMs: Int
timedInvokeTimeout: Duration
) {
val commandId: UInt = 2u
val timeoutMs: Duration = Duration.ofMillis(timedInvokeTimeoutMs.toLong())

val tlvWriter = TlvWriter()
tlvWriter.startStructure(AnonymousTag)
Expand All @@ -122,16 +119,15 @@ class AccountLoginCluster(
InvokeRequest(
CommandPath(endpointId, clusterId = CLUSTER_ID, commandId),
tlvPayload = tlvWriter.getEncoded(),
timedRequest = timeoutMs
timedRequest = timedInvokeTimeout
)

val response: InvokeResponse = controller.invoke(request)
logger.log(Level.FINE, "Invoke command succeeded: ${response}")
}

suspend fun logout(node: ULong?, timedInvokeTimeoutMs: Int) {
suspend fun logout(node: ULong?, timedInvokeTimeout: Duration) {
val commandId: UInt = 3u
val timeoutMs: Duration = Duration.ofMillis(timedInvokeTimeoutMs.toLong())

val tlvWriter = TlvWriter()
tlvWriter.startStructure(AnonymousTag)
Expand All @@ -144,7 +140,7 @@ class AccountLoginCluster(
InvokeRequest(
CommandPath(endpointId, clusterId = CLUSTER_ID, commandId),
tlvPayload = tlvWriter.getEncoded(),
timedRequest = timeoutMs
timedRequest = timedInvokeTimeout
)

val response: InvokeResponse = controller.invoke(request)
Expand Down
Loading

0 comments on commit 1531752

Please sign in to comment.