diff --git a/src/controller/java/generated/java/matter/devicecontroller/cluster/clusters/ElectricalEnergyMeasurementCluster.kt b/src/controller/java/generated/java/matter/devicecontroller/cluster/clusters/ElectricalEnergyMeasurementCluster.kt index c51f3bf35e1d55..d9c3677d557c85 100644 --- a/src/controller/java/generated/java/matter/devicecontroller/cluster/clusters/ElectricalEnergyMeasurementCluster.kt +++ b/src/controller/java/generated/java/matter/devicecontroller/cluster/clusters/ElectricalEnergyMeasurementCluster.kt @@ -17,8 +17,13 @@ package matter.devicecontroller.cluster.clusters -import matter.controller.MatterController +import java.util.logging.Level +import java.util.logging.Logger +import matter.controller.* +import matter.controller.model.AttributePath import matter.devicecontroller.cluster.structs.* +import matter.tlv.AnonymousTag +import matter.tlv.TlvReader class ElectricalEnergyMeasurementCluster( private val controller: MatterController, @@ -51,115 +56,417 @@ class ElectricalEnergyMeasurementCluster( class AttributeListAttribute(val value: List) suspend fun readAccuracyAttribute(): AccuracyAttribute { - // Implementation needs to be added here - } + val ATTRIBUTE_ID: UInt = 0u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + + val response = controller.read(readRequest) + + if (response.successes.isEmpty()) { + logger.log(Level.WARNING, "Read command failed") + throw IllegalStateException("Read command failed with failures: ${response.failures}") + } + + logger.log(Level.FINE, "Read command succeeded") + + val attributeData = + response.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } - suspend fun subscribeAccuracyAttribute(minInterval: Int, maxInterval: Int): AccuracyAttribute { - // Implementation needs to be added here + requireNotNull(attributeData) { "Accuracy attribute not found in response" } + + // Decode the TLV data into the appropriate type + val tlvReader = TlvReader(attributeData.data) + val decodedValue: ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct = + ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct.fromTlv(AnonymousTag, tlvReader) + + return AccuracyAttribute(decodedValue) } suspend fun readCumulativeEnergyImportedAttribute(): CumulativeEnergyImportedAttribute { - // Implementation needs to be added here - } + val ATTRIBUTE_ID: UInt = 1u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + + val response = controller.read(readRequest) - suspend fun subscribeCumulativeEnergyImportedAttribute( - minInterval: Int, - maxInterval: Int - ): CumulativeEnergyImportedAttribute { - // Implementation needs to be added here + if (response.successes.isEmpty()) { + logger.log(Level.WARNING, "Read command failed") + throw IllegalStateException("Read command failed with failures: ${response.failures}") + } + + logger.log(Level.FINE, "Read command succeeded") + + val attributeData = + response.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { "Cumulativeenergyimported attribute not found in response" } + + // Decode the TLV data into the appropriate type + val tlvReader = TlvReader(attributeData.data) + val decodedValue: ElectricalEnergyMeasurementClusterEnergyMeasurementStruct? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + ElectricalEnergyMeasurementClusterEnergyMeasurementStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + return CumulativeEnergyImportedAttribute(decodedValue) } suspend fun readCumulativeEnergyExportedAttribute(): CumulativeEnergyExportedAttribute { - // Implementation needs to be added here - } + val ATTRIBUTE_ID: UInt = 2u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + + val response = controller.read(readRequest) + + if (response.successes.isEmpty()) { + logger.log(Level.WARNING, "Read command failed") + throw IllegalStateException("Read command failed with failures: ${response.failures}") + } + + logger.log(Level.FINE, "Read command succeeded") + + val attributeData = + response.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } - suspend fun subscribeCumulativeEnergyExportedAttribute( - minInterval: Int, - maxInterval: Int - ): CumulativeEnergyExportedAttribute { - // Implementation needs to be added here + requireNotNull(attributeData) { "Cumulativeenergyexported attribute not found in response" } + + // Decode the TLV data into the appropriate type + val tlvReader = TlvReader(attributeData.data) + val decodedValue: ElectricalEnergyMeasurementClusterEnergyMeasurementStruct? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + ElectricalEnergyMeasurementClusterEnergyMeasurementStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + return CumulativeEnergyExportedAttribute(decodedValue) } suspend fun readPeriodicEnergyImportedAttribute(): PeriodicEnergyImportedAttribute { - // Implementation needs to be added here - } + val ATTRIBUTE_ID: UInt = 3u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + + val response = controller.read(readRequest) + + if (response.successes.isEmpty()) { + logger.log(Level.WARNING, "Read command failed") + throw IllegalStateException("Read command failed with failures: ${response.failures}") + } - suspend fun subscribePeriodicEnergyImportedAttribute( - minInterval: Int, - maxInterval: Int - ): PeriodicEnergyImportedAttribute { - // Implementation needs to be added here + logger.log(Level.FINE, "Read command succeeded") + + val attributeData = + response.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { "Periodicenergyimported attribute not found in response" } + + // Decode the TLV data into the appropriate type + val tlvReader = TlvReader(attributeData.data) + val decodedValue: ElectricalEnergyMeasurementClusterEnergyMeasurementStruct? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + ElectricalEnergyMeasurementClusterEnergyMeasurementStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + return PeriodicEnergyImportedAttribute(decodedValue) } suspend fun readPeriodicEnergyExportedAttribute(): PeriodicEnergyExportedAttribute { - // Implementation needs to be added here - } + val ATTRIBUTE_ID: UInt = 4u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - suspend fun subscribePeriodicEnergyExportedAttribute( - minInterval: Int, - maxInterval: Int - ): PeriodicEnergyExportedAttribute { - // Implementation needs to be added here + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + + val response = controller.read(readRequest) + + if (response.successes.isEmpty()) { + logger.log(Level.WARNING, "Read command failed") + throw IllegalStateException("Read command failed with failures: ${response.failures}") + } + + logger.log(Level.FINE, "Read command succeeded") + + val attributeData = + response.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { "Periodicenergyexported attribute not found in response" } + + // Decode the TLV data into the appropriate type + val tlvReader = TlvReader(attributeData.data) + val decodedValue: ElectricalEnergyMeasurementClusterEnergyMeasurementStruct? = + if (!tlvReader.isNull()) { + if (tlvReader.isNextTag(AnonymousTag)) { + ElectricalEnergyMeasurementClusterEnergyMeasurementStruct.fromTlv(AnonymousTag, tlvReader) + } else { + null + } + } else { + tlvReader.getNull(AnonymousTag) + null + } + + return PeriodicEnergyExportedAttribute(decodedValue) } suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { - // Implementation needs to be added here - } + val ATTRIBUTE_ID: UInt = 65528u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + + val response = controller.read(readRequest) + + if (response.successes.isEmpty()) { + logger.log(Level.WARNING, "Read command failed") + throw IllegalStateException("Read command failed with failures: ${response.failures}") + } - suspend fun subscribeGeneratedCommandListAttribute( - minInterval: Int, - maxInterval: Int - ): GeneratedCommandListAttribute { - // Implementation needs to be added here + logger.log(Level.FINE, "Read command succeeded") + + val attributeData = + response.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { "Generatedcommandlist attribute not found in response" } + + // Decode the TLV data into the appropriate type + val tlvReader = TlvReader(attributeData.data) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } + + return GeneratedCommandListAttribute(decodedValue) } suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute { - // Implementation needs to be added here - } + val ATTRIBUTE_ID: UInt = 65529u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + + val response = controller.read(readRequest) + + if (response.successes.isEmpty()) { + logger.log(Level.WARNING, "Read command failed") + throw IllegalStateException("Read command failed with failures: ${response.failures}") + } + + logger.log(Level.FINE, "Read command succeeded") + + val attributeData = + response.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { "Acceptedcommandlist attribute not found in response" } + + // Decode the TLV data into the appropriate type + val tlvReader = TlvReader(attributeData.data) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } - suspend fun subscribeAcceptedCommandListAttribute( - minInterval: Int, - maxInterval: Int - ): AcceptedCommandListAttribute { - // Implementation needs to be added here + return AcceptedCommandListAttribute(decodedValue) } suspend fun readEventListAttribute(): EventListAttribute { - // Implementation needs to be added here - } + val ATTRIBUTE_ID: UInt = 65530u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + + val response = controller.read(readRequest) + + if (response.successes.isEmpty()) { + logger.log(Level.WARNING, "Read command failed") + throw IllegalStateException("Read command failed with failures: ${response.failures}") + } + + logger.log(Level.FINE, "Read command succeeded") - suspend fun subscribeEventListAttribute(minInterval: Int, maxInterval: Int): EventListAttribute { - // Implementation needs to be added here + val attributeData = + response.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { "Eventlist attribute not found in response" } + + // Decode the TLV data into the appropriate type + val tlvReader = TlvReader(attributeData.data) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } + + return EventListAttribute(decodedValue) } suspend fun readAttributeListAttribute(): AttributeListAttribute { - // Implementation needs to be added here - } + val ATTRIBUTE_ID: UInt = 65531u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) - suspend fun subscribeAttributeListAttribute( - minInterval: Int, - maxInterval: Int - ): AttributeListAttribute { - // Implementation needs to be added here + val response = controller.read(readRequest) + + if (response.successes.isEmpty()) { + logger.log(Level.WARNING, "Read command failed") + throw IllegalStateException("Read command failed with failures: ${response.failures}") + } + + logger.log(Level.FINE, "Read command succeeded") + + val attributeData = + response.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { "Attributelist attribute not found in response" } + + // Decode the TLV data into the appropriate type + val tlvReader = TlvReader(attributeData.data) + val decodedValue: List = + buildList { + tlvReader.enterArray(AnonymousTag) + while (!tlvReader.isEndOfContainer()) { + add(tlvReader.getUInt(AnonymousTag)) + } + tlvReader.exitContainer() + } + + return AttributeListAttribute(decodedValue) } suspend fun readFeatureMapAttribute(): UInt { - // Implementation needs to be added here - } + val ATTRIBUTE_ID: UInt = 65532u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + + val response = controller.read(readRequest) + + if (response.successes.isEmpty()) { + logger.log(Level.WARNING, "Read command failed") + throw IllegalStateException("Read command failed with failures: ${response.failures}") + } + + logger.log(Level.FINE, "Read command succeeded") - suspend fun subscribeFeatureMapAttribute(minInterval: Int, maxInterval: Int): UInt { - // Implementation needs to be added here + val attributeData = + response.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { "Featuremap attribute not found in response" } + + // Decode the TLV data into the appropriate type + val tlvReader = TlvReader(attributeData.data) + val decodedValue: UInt = tlvReader.getUInt(AnonymousTag) + + return decodedValue } suspend fun readClusterRevisionAttribute(): UShort { - // Implementation needs to be added here - } + val ATTRIBUTE_ID: UInt = 65533u + + val attributePath = + AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) + + val readRequest = ReadRequest(eventPaths = emptyList(), attributePaths = listOf(attributePath)) + + val response = controller.read(readRequest) + + if (response.successes.isEmpty()) { + logger.log(Level.WARNING, "Read command failed") + throw IllegalStateException("Read command failed with failures: ${response.failures}") + } + + logger.log(Level.FINE, "Read command succeeded") + + val attributeData = + response.successes.filterIsInstance().firstOrNull { + it.path.attributeId == ATTRIBUTE_ID + } + + requireNotNull(attributeData) { "Clusterrevision attribute not found in response" } + + // Decode the TLV data into the appropriate type + val tlvReader = TlvReader(attributeData.data) + val decodedValue: UShort = tlvReader.getUShort(AnonymousTag) - suspend fun subscribeClusterRevisionAttribute(minInterval: Int, maxInterval: Int): UShort { - // Implementation needs to be added here + return decodedValue } companion object { + private val logger = Logger.getLogger(ElectricalEnergyMeasurementCluster::class.java.name) const val CLUSTER_ID: UInt = 145u } } diff --git a/src/controller/java/generated/java/matter/devicecontroller/cluster/structs/ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct.kt b/src/controller/java/generated/java/matter/devicecontroller/cluster/structs/ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct.kt index 6fa6a4b048c2a2..9324ea44aebf88 100644 --- a/src/controller/java/generated/java/matter/devicecontroller/cluster/structs/ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct.kt +++ b/src/controller/java/generated/java/matter/devicecontroller/cluster/structs/ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct.kt @@ -24,7 +24,7 @@ import matter.tlv.TlvReader import matter.tlv.TlvWriter class ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct( - val measurementType: UInt, + val measurementType: UShort, val measured: Boolean, val minMeasuredValue: Long, val maxMeasuredValue: Long, @@ -68,7 +68,7 @@ class ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct( tlvReader: TlvReader ): ElectricalEnergyMeasurementClusterMeasurementAccuracyStruct { tlvReader.enterStructure(tlvTag) - val measurementType = tlvReader.getUInt(ContextSpecificTag(TAG_MEASUREMENT_TYPE)) + val measurementType = tlvReader.getUShort(ContextSpecificTag(TAG_MEASUREMENT_TYPE)) val measured = tlvReader.getBoolean(ContextSpecificTag(TAG_MEASURED)) val minMeasuredValue = tlvReader.getLong(ContextSpecificTag(TAG_MIN_MEASURED_VALUE)) val maxMeasuredValue = tlvReader.getLong(ContextSpecificTag(TAG_MAX_MEASURED_VALUE))