Skip to content

Commit 0ed559c

Browse files
committed
Add CumulativeEnergyResetStruct and CumulativeEnergyReset attribute to EEM
1 parent a951bf1 commit 0ed559c

File tree

9 files changed

+539
-7
lines changed

9 files changed

+539
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/*
2+
*
3+
* Copyright (c) 2023 Project CHIP Authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package chip.devicecontroller.cluster.structs
18+
19+
import chip.devicecontroller.cluster.*
20+
import matter.tlv.AnonymousTag
21+
import matter.tlv.ContextSpecificTag
22+
import matter.tlv.Tag
23+
import matter.tlv.TlvParsingException
24+
import matter.tlv.TlvReader
25+
import matter.tlv.TlvWriter
26+
27+
import java.util.Optional
28+
29+
class ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct (
30+
val importedResetTimestamp: Optional<ULong>?,
31+
val exportedResetTimestamp: Optional<ULong>?,
32+
val importedResetSystime: Optional<ULong>?,
33+
val exportedResetSystime: Optional<ULong>?) {
34+
override fun toString(): String = buildString {
35+
append("ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct {\n")
36+
append("\timportedResetTimestamp : $importedResetTimestamp\n")
37+
append("\texportedResetTimestamp : $exportedResetTimestamp\n")
38+
append("\timportedResetSystime : $importedResetSystime\n")
39+
append("\texportedResetSystime : $exportedResetSystime\n")
40+
append("}\n")
41+
}
42+
43+
fun toTlv(tlvTag: Tag, tlvWriter: TlvWriter) {
44+
tlvWriter.apply {
45+
startStructure(tlvTag)
46+
if (importedResetTimestamp != null) {
47+
if (importedResetTimestamp.isPresent) {
48+
val optimportedResetTimestamp = importedResetTimestamp.get()
49+
put(ContextSpecificTag(TAG_IMPORTED_RESET_TIMESTAMP), optimportedResetTimestamp)
50+
}
51+
} else {
52+
putNull(ContextSpecificTag(TAG_IMPORTED_RESET_TIMESTAMP))
53+
}
54+
if (exportedResetTimestamp != null) {
55+
if (exportedResetTimestamp.isPresent) {
56+
val optexportedResetTimestamp = exportedResetTimestamp.get()
57+
put(ContextSpecificTag(TAG_EXPORTED_RESET_TIMESTAMP), optexportedResetTimestamp)
58+
}
59+
} else {
60+
putNull(ContextSpecificTag(TAG_EXPORTED_RESET_TIMESTAMP))
61+
}
62+
if (importedResetSystime != null) {
63+
if (importedResetSystime.isPresent) {
64+
val optimportedResetSystime = importedResetSystime.get()
65+
put(ContextSpecificTag(TAG_IMPORTED_RESET_SYSTIME), optimportedResetSystime)
66+
}
67+
} else {
68+
putNull(ContextSpecificTag(TAG_IMPORTED_RESET_SYSTIME))
69+
}
70+
if (exportedResetSystime != null) {
71+
if (exportedResetSystime.isPresent) {
72+
val optexportedResetSystime = exportedResetSystime.get()
73+
put(ContextSpecificTag(TAG_EXPORTED_RESET_SYSTIME), optexportedResetSystime)
74+
}
75+
} else {
76+
putNull(ContextSpecificTag(TAG_EXPORTED_RESET_SYSTIME))
77+
}
78+
endStructure()
79+
}
80+
}
81+
82+
companion object {
83+
private const val TAG_IMPORTED_RESET_TIMESTAMP = 0
84+
private const val TAG_EXPORTED_RESET_TIMESTAMP = 1
85+
private const val TAG_IMPORTED_RESET_SYSTIME = 2
86+
private const val TAG_EXPORTED_RESET_SYSTIME = 3
87+
88+
fun fromTlv(tlvTag: Tag, tlvReader: TlvReader) : ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct {
89+
tlvReader.enterStructure(tlvTag)
90+
val importedResetTimestamp = if (!tlvReader.isNull()) {
91+
if (tlvReader.isNextTag(ContextSpecificTag(TAG_IMPORTED_RESET_TIMESTAMP))) {
92+
Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_IMPORTED_RESET_TIMESTAMP)))
93+
} else {
94+
Optional.empty()
95+
}
96+
} else {
97+
tlvReader.getNull(ContextSpecificTag(TAG_IMPORTED_RESET_TIMESTAMP))
98+
null
99+
}
100+
val exportedResetTimestamp = if (!tlvReader.isNull()) {
101+
if (tlvReader.isNextTag(ContextSpecificTag(TAG_EXPORTED_RESET_TIMESTAMP))) {
102+
Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_EXPORTED_RESET_TIMESTAMP)))
103+
} else {
104+
Optional.empty()
105+
}
106+
} else {
107+
tlvReader.getNull(ContextSpecificTag(TAG_EXPORTED_RESET_TIMESTAMP))
108+
null
109+
}
110+
val importedResetSystime = if (!tlvReader.isNull()) {
111+
if (tlvReader.isNextTag(ContextSpecificTag(TAG_IMPORTED_RESET_SYSTIME))) {
112+
Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_IMPORTED_RESET_SYSTIME)))
113+
} else {
114+
Optional.empty()
115+
}
116+
} else {
117+
tlvReader.getNull(ContextSpecificTag(TAG_IMPORTED_RESET_SYSTIME))
118+
null
119+
}
120+
val exportedResetSystime = if (!tlvReader.isNull()) {
121+
if (tlvReader.isNextTag(ContextSpecificTag(TAG_EXPORTED_RESET_SYSTIME))) {
122+
Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_EXPORTED_RESET_SYSTIME)))
123+
} else {
124+
Optional.empty()
125+
}
126+
} else {
127+
tlvReader.getNull(ContextSpecificTag(TAG_EXPORTED_RESET_SYSTIME))
128+
null
129+
}
130+
131+
tlvReader.exitContainer()
132+
133+
return ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct(importedResetTimestamp, exportedResetTimestamp, importedResetSystime, exportedResetSystime)
134+
}
135+
}
136+
}

src/controller/java/generated/java/matter/controller/cluster/clusters/ElectricalEnergyMeasurementCluster.kt

+112
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,19 @@ class ElectricalEnergyMeasurementCluster(
103103
object SubscriptionEstablished : PeriodicEnergyExportedAttributeSubscriptionState()
104104
}
105105

106+
class CumulativeEnergyResetAttribute(
107+
val value: ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct?
108+
)
109+
110+
sealed class CumulativeEnergyResetAttributeSubscriptionState {
111+
data class Success(val value: ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct?) :
112+
CumulativeEnergyResetAttributeSubscriptionState()
113+
114+
data class Error(val exception: Exception) : CumulativeEnergyResetAttributeSubscriptionState()
115+
116+
object SubscriptionEstablished : CumulativeEnergyResetAttributeSubscriptionState()
117+
}
118+
106119
class GeneratedCommandListAttribute(val value: List<UInt>)
107120

108121
sealed class GeneratedCommandListAttributeSubscriptionState {
@@ -653,6 +666,105 @@ class ElectricalEnergyMeasurementCluster(
653666
}
654667
}
655668

669+
suspend fun readCumulativeEnergyResetAttribute(): CumulativeEnergyResetAttribute {
670+
val ATTRIBUTE_ID: UInt = 5u
671+
672+
val attributePath =
673+
AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID)
674+
675+
val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath))
676+
677+
val response = controller.read(readRequest)
678+
679+
if (response.successes.isEmpty()) {
680+
logger.log(Level.WARNING, "Read command failed")
681+
throw IllegalStateException("Read command failed with failures: ${response.failures}")
682+
}
683+
684+
logger.log(Level.FINE, "Read command succeeded")
685+
686+
val attributeData =
687+
response.successes.filterIsInstance<ReadData.Attribute>().firstOrNull {
688+
it.path.attributeId == ATTRIBUTE_ID
689+
}
690+
691+
requireNotNull(attributeData) { "Cumulativeenergyreset attribute not found in response" }
692+
693+
// Decode the TLV data into the appropriate type
694+
val tlvReader = TlvReader(attributeData.data)
695+
val decodedValue: ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct? =
696+
if (tlvReader.isNextTag(AnonymousTag)) {
697+
ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct.fromTlv(
698+
AnonymousTag,
699+
tlvReader
700+
)
701+
} else {
702+
null
703+
}
704+
705+
return CumulativeEnergyResetAttribute(decodedValue)
706+
}
707+
708+
suspend fun subscribeCumulativeEnergyResetAttribute(
709+
minInterval: Int,
710+
maxInterval: Int
711+
): Flow<CumulativeEnergyResetAttributeSubscriptionState> {
712+
val ATTRIBUTE_ID: UInt = 5u
713+
val attributePaths =
714+
listOf(
715+
AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID)
716+
)
717+
718+
val subscribeRequest: SubscribeRequest =
719+
SubscribeRequest(
720+
eventPaths = emptyList(),
721+
attributePaths = attributePaths,
722+
minInterval = Duration.ofSeconds(minInterval.toLong()),
723+
maxInterval = Duration.ofSeconds(maxInterval.toLong())
724+
)
725+
726+
return controller.subscribe(subscribeRequest).transform { subscriptionState ->
727+
when (subscriptionState) {
728+
is SubscriptionState.SubscriptionErrorNotification -> {
729+
emit(
730+
CumulativeEnergyResetAttributeSubscriptionState.Error(
731+
Exception(
732+
"Subscription terminated with error code: ${subscriptionState.terminationCause}"
733+
)
734+
)
735+
)
736+
}
737+
is SubscriptionState.NodeStateUpdate -> {
738+
val attributeData =
739+
subscriptionState.updateState.successes
740+
.filterIsInstance<ReadData.Attribute>()
741+
.firstOrNull { it.path.attributeId == ATTRIBUTE_ID }
742+
743+
requireNotNull(attributeData) {
744+
"Cumulativeenergyreset attribute not found in Node State update"
745+
}
746+
747+
// Decode the TLV data into the appropriate type
748+
val tlvReader = TlvReader(attributeData.data)
749+
val decodedValue: ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct? =
750+
if (tlvReader.isNextTag(AnonymousTag)) {
751+
ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct.fromTlv(
752+
AnonymousTag,
753+
tlvReader
754+
)
755+
} else {
756+
null
757+
}
758+
759+
decodedValue?.let { emit(CumulativeEnergyResetAttributeSubscriptionState.Success(it)) }
760+
}
761+
SubscriptionState.SubscriptionEstablished -> {
762+
emit(CumulativeEnergyResetAttributeSubscriptionState.SubscriptionEstablished)
763+
}
764+
}
765+
}
766+
}
767+
656768
suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute {
657769
val ATTRIBUTE_ID: UInt = 65528u
658770

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/*
2+
*
3+
* Copyright (c) 2023 Project CHIP Authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package matter.controller.cluster.structs
18+
19+
import java.util.Optional
20+
import matter.controller.cluster.*
21+
import matter.tlv.AnonymousTag
22+
import matter.tlv.ContextSpecificTag
23+
import matter.tlv.Tag
24+
import matter.tlv.TlvReader
25+
import matter.tlv.TlvWriter
26+
27+
class ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct(
28+
val importedResetTimestamp: Optional<UInt>?,
29+
val exportedResetTimestamp: Optional<UInt>?,
30+
val importedResetSystime: Optional<ULong>?,
31+
val exportedResetSystime: Optional<ULong>?
32+
) {
33+
override fun toString(): String = buildString {
34+
append("ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct {\n")
35+
append("\timportedResetTimestamp : $importedResetTimestamp\n")
36+
append("\texportedResetTimestamp : $exportedResetTimestamp\n")
37+
append("\timportedResetSystime : $importedResetSystime\n")
38+
append("\texportedResetSystime : $exportedResetSystime\n")
39+
append("}\n")
40+
}
41+
42+
fun toTlv(tlvTag: Tag, tlvWriter: TlvWriter) {
43+
tlvWriter.apply {
44+
startStructure(tlvTag)
45+
if (importedResetTimestamp != null) {
46+
if (importedResetTimestamp.isPresent) {
47+
val optimportedResetTimestamp = importedResetTimestamp.get()
48+
put(ContextSpecificTag(TAG_IMPORTED_RESET_TIMESTAMP), optimportedResetTimestamp)
49+
}
50+
} else {
51+
putNull(ContextSpecificTag(TAG_IMPORTED_RESET_TIMESTAMP))
52+
}
53+
if (exportedResetTimestamp != null) {
54+
if (exportedResetTimestamp.isPresent) {
55+
val optexportedResetTimestamp = exportedResetTimestamp.get()
56+
put(ContextSpecificTag(TAG_EXPORTED_RESET_TIMESTAMP), optexportedResetTimestamp)
57+
}
58+
} else {
59+
putNull(ContextSpecificTag(TAG_EXPORTED_RESET_TIMESTAMP))
60+
}
61+
if (importedResetSystime != null) {
62+
if (importedResetSystime.isPresent) {
63+
val optimportedResetSystime = importedResetSystime.get()
64+
put(ContextSpecificTag(TAG_IMPORTED_RESET_SYSTIME), optimportedResetSystime)
65+
}
66+
} else {
67+
putNull(ContextSpecificTag(TAG_IMPORTED_RESET_SYSTIME))
68+
}
69+
if (exportedResetSystime != null) {
70+
if (exportedResetSystime.isPresent) {
71+
val optexportedResetSystime = exportedResetSystime.get()
72+
put(ContextSpecificTag(TAG_EXPORTED_RESET_SYSTIME), optexportedResetSystime)
73+
}
74+
} else {
75+
putNull(ContextSpecificTag(TAG_EXPORTED_RESET_SYSTIME))
76+
}
77+
endStructure()
78+
}
79+
}
80+
81+
companion object {
82+
private const val TAG_IMPORTED_RESET_TIMESTAMP = 0
83+
private const val TAG_EXPORTED_RESET_TIMESTAMP = 1
84+
private const val TAG_IMPORTED_RESET_SYSTIME = 2
85+
private const val TAG_EXPORTED_RESET_SYSTIME = 3
86+
87+
fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct {
88+
tlvReader.enterStructure(tlvTag)
89+
val importedResetTimestamp = if (!tlvReader.isNull()) {
90+
if (tlvReader.isNextTag(ContextSpecificTag(TAG_IMPORTED_RESET_TIMESTAMP))) {
91+
Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_IMPORTED_RESET_TIMESTAMP)))
92+
} else {
93+
Optional.empty()
94+
}
95+
} else {
96+
tlvReader.getNull(ContextSpecificTag(TAG_IMPORTED_RESET_TIMESTAMP))
97+
null
98+
}
99+
val exportedResetTimestamp = if (!tlvReader.isNull()) {
100+
if (tlvReader.isNextTag(ContextSpecificTag(TAG_EXPORTED_RESET_TIMESTAMP))) {
101+
Optional.of(tlvReader.getUInt(ContextSpecificTag(TAG_EXPORTED_RESET_TIMESTAMP)))
102+
} else {
103+
Optional.empty()
104+
}
105+
} else {
106+
tlvReader.getNull(ContextSpecificTag(TAG_EXPORTED_RESET_TIMESTAMP))
107+
null
108+
}
109+
val importedResetSystime = if (!tlvReader.isNull()) {
110+
if (tlvReader.isNextTag(ContextSpecificTag(TAG_IMPORTED_RESET_SYSTIME))) {
111+
Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_IMPORTED_RESET_SYSTIME)))
112+
} else {
113+
Optional.empty()
114+
}
115+
} else {
116+
tlvReader.getNull(ContextSpecificTag(TAG_IMPORTED_RESET_SYSTIME))
117+
null
118+
}
119+
val exportedResetSystime = if (!tlvReader.isNull()) {
120+
if (tlvReader.isNextTag(ContextSpecificTag(TAG_EXPORTED_RESET_SYSTIME))) {
121+
Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_EXPORTED_RESET_SYSTIME)))
122+
} else {
123+
Optional.empty()
124+
}
125+
} else {
126+
tlvReader.getNull(ContextSpecificTag(TAG_EXPORTED_RESET_SYSTIME))
127+
null
128+
}
129+
130+
tlvReader.exitContainer()
131+
132+
return ElectricalEnergyMeasurementClusterCumulativeEnergyResetStruct(importedResetTimestamp, exportedResetTimestamp, importedResetSystime, exportedResetSystime)
133+
}
134+
}
135+
}

0 commit comments

Comments
 (0)