From 27727562d7ec386a2990dda2ca9dae3237f8d80a Mon Sep 17 00:00:00 2001 From: lpbeliveau-silabs Date: Fri, 15 Dec 2023 11:21:24 -0500 Subject: [PATCH] Removed Kotlin files generated with previous cluster name --- .../ScenesClusterAttributeValuePair.kt | 56 - .../structs/ScenesClusterExtensionFieldSet.kt | 71 - .../structs/ScenesClusterSceneInfoStruct.kt | 86 - .../cluster/clusters/ScenesCluster.kt | 2310 ----------------- .../ScenesClusterAttributeValuePair.kt | 56 - .../structs/ScenesClusterExtensionFieldSet.kt | 71 - .../structs/ScenesClusterSceneInfoStruct.kt | 86 - 7 files changed, 2736 deletions(-) delete mode 100644 src/controller/java/generated/java/chip/devicecontroller/cluster/structs/ScenesClusterAttributeValuePair.kt delete mode 100644 src/controller/java/generated/java/chip/devicecontroller/cluster/structs/ScenesClusterExtensionFieldSet.kt delete mode 100644 src/controller/java/generated/java/chip/devicecontroller/cluster/structs/ScenesClusterSceneInfoStruct.kt delete mode 100644 src/controller/java/generated/java/matter/controller/cluster/clusters/ScenesCluster.kt delete mode 100644 src/controller/java/generated/java/matter/controller/cluster/structs/ScenesClusterAttributeValuePair.kt delete mode 100644 src/controller/java/generated/java/matter/controller/cluster/structs/ScenesClusterExtensionFieldSet.kt delete mode 100644 src/controller/java/generated/java/matter/controller/cluster/structs/ScenesClusterSceneInfoStruct.kt diff --git a/src/controller/java/generated/java/chip/devicecontroller/cluster/structs/ScenesClusterAttributeValuePair.kt b/src/controller/java/generated/java/chip/devicecontroller/cluster/structs/ScenesClusterAttributeValuePair.kt deleted file mode 100644 index f26ab20211dd8d..00000000000000 --- a/src/controller/java/generated/java/chip/devicecontroller/cluster/structs/ScenesClusterAttributeValuePair.kt +++ /dev/null @@ -1,56 +0,0 @@ -/* - * - * Copyright (c) 2023 Project CHIP Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package chip.devicecontroller.cluster.structs - -import chip.devicecontroller.cluster.* -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvReader -import matter.tlv.TlvWriter - -class ScenesClusterAttributeValuePair(val attributeID: ULong, val attributeValue: ULong) { - override fun toString(): String = buildString { - append("ScenesClusterAttributeValuePair {\n") - append("\tattributeID : $attributeID\n") - append("\tattributeValue : $attributeValue\n") - append("}\n") - } - - fun toTlv(tlvTag: Tag, tlvWriter: TlvWriter) { - tlvWriter.apply { - startStructure(tlvTag) - put(ContextSpecificTag(TAG_ATTRIBUTE_I_D), attributeID) - put(ContextSpecificTag(TAG_ATTRIBUTE_VALUE), attributeValue) - endStructure() - } - } - - companion object { - private const val TAG_ATTRIBUTE_I_D = 0 - private const val TAG_ATTRIBUTE_VALUE = 1 - - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ScenesClusterAttributeValuePair { - tlvReader.enterStructure(tlvTag) - val attributeID = tlvReader.getULong(ContextSpecificTag(TAG_ATTRIBUTE_I_D)) - val attributeValue = tlvReader.getULong(ContextSpecificTag(TAG_ATTRIBUTE_VALUE)) - - tlvReader.exitContainer() - - return ScenesClusterAttributeValuePair(attributeID, attributeValue) - } - } -} diff --git a/src/controller/java/generated/java/chip/devicecontroller/cluster/structs/ScenesClusterExtensionFieldSet.kt b/src/controller/java/generated/java/chip/devicecontroller/cluster/structs/ScenesClusterExtensionFieldSet.kt deleted file mode 100644 index 7999a24e2d78de..00000000000000 --- a/src/controller/java/generated/java/chip/devicecontroller/cluster/structs/ScenesClusterExtensionFieldSet.kt +++ /dev/null @@ -1,71 +0,0 @@ -/* - * - * Copyright (c) 2023 Project CHIP Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package chip.devicecontroller.cluster.structs - -import chip.devicecontroller.cluster.* -import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvReader -import matter.tlv.TlvWriter - -class ScenesClusterExtensionFieldSet( - val clusterID: ULong, - val attributeValueList: List -) { - override fun toString(): String = buildString { - append("ScenesClusterExtensionFieldSet {\n") - append("\tclusterID : $clusterID\n") - append("\tattributeValueList : $attributeValueList\n") - append("}\n") - } - - fun toTlv(tlvTag: Tag, tlvWriter: TlvWriter) { - tlvWriter.apply { - startStructure(tlvTag) - put(ContextSpecificTag(TAG_CLUSTER_I_D), clusterID) - startArray(ContextSpecificTag(TAG_ATTRIBUTE_VALUE_LIST)) - for (item in attributeValueList.iterator()) { - item.toTlv(AnonymousTag, this) - } - endArray() - endStructure() - } - } - - companion object { - private const val TAG_CLUSTER_I_D = 0 - private const val TAG_ATTRIBUTE_VALUE_LIST = 1 - - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ScenesClusterExtensionFieldSet { - tlvReader.enterStructure(tlvTag) - val clusterID = tlvReader.getULong(ContextSpecificTag(TAG_CLUSTER_I_D)) - val attributeValueList = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_ATTRIBUTE_VALUE_LIST)) - while (!tlvReader.isEndOfContainer()) { - add(ScenesClusterAttributeValuePair.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - - tlvReader.exitContainer() - - return ScenesClusterExtensionFieldSet(clusterID, attributeValueList) - } - } -} diff --git a/src/controller/java/generated/java/chip/devicecontroller/cluster/structs/ScenesClusterSceneInfoStruct.kt b/src/controller/java/generated/java/chip/devicecontroller/cluster/structs/ScenesClusterSceneInfoStruct.kt deleted file mode 100644 index 066ade4d02a12f..00000000000000 --- a/src/controller/java/generated/java/chip/devicecontroller/cluster/structs/ScenesClusterSceneInfoStruct.kt +++ /dev/null @@ -1,86 +0,0 @@ -/* - * - * Copyright (c) 2023 Project CHIP Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package chip.devicecontroller.cluster.structs - -import chip.devicecontroller.cluster.* -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvReader -import matter.tlv.TlvWriter - -class ScenesClusterSceneInfoStruct( - val sceneCount: UInt, - val currentScene: UInt, - val currentGroup: UInt, - val sceneValid: Boolean, - val remainingCapacity: UInt, - val fabricIndex: UInt -) { - override fun toString(): String = buildString { - append("ScenesClusterSceneInfoStruct {\n") - append("\tsceneCount : $sceneCount\n") - append("\tcurrentScene : $currentScene\n") - append("\tcurrentGroup : $currentGroup\n") - append("\tsceneValid : $sceneValid\n") - append("\tremainingCapacity : $remainingCapacity\n") - append("\tfabricIndex : $fabricIndex\n") - append("}\n") - } - - fun toTlv(tlvTag: Tag, tlvWriter: TlvWriter) { - tlvWriter.apply { - startStructure(tlvTag) - put(ContextSpecificTag(TAG_SCENE_COUNT), sceneCount) - put(ContextSpecificTag(TAG_CURRENT_SCENE), currentScene) - put(ContextSpecificTag(TAG_CURRENT_GROUP), currentGroup) - put(ContextSpecificTag(TAG_SCENE_VALID), sceneValid) - put(ContextSpecificTag(TAG_REMAINING_CAPACITY), remainingCapacity) - put(ContextSpecificTag(TAG_FABRIC_INDEX), fabricIndex) - endStructure() - } - } - - companion object { - private const val TAG_SCENE_COUNT = 0 - private const val TAG_CURRENT_SCENE = 1 - private const val TAG_CURRENT_GROUP = 2 - private const val TAG_SCENE_VALID = 3 - private const val TAG_REMAINING_CAPACITY = 4 - private const val TAG_FABRIC_INDEX = 254 - - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ScenesClusterSceneInfoStruct { - tlvReader.enterStructure(tlvTag) - val sceneCount = tlvReader.getUInt(ContextSpecificTag(TAG_SCENE_COUNT)) - val currentScene = tlvReader.getUInt(ContextSpecificTag(TAG_CURRENT_SCENE)) - val currentGroup = tlvReader.getUInt(ContextSpecificTag(TAG_CURRENT_GROUP)) - val sceneValid = tlvReader.getBoolean(ContextSpecificTag(TAG_SCENE_VALID)) - val remainingCapacity = tlvReader.getUInt(ContextSpecificTag(TAG_REMAINING_CAPACITY)) - val fabricIndex = tlvReader.getUInt(ContextSpecificTag(TAG_FABRIC_INDEX)) - - tlvReader.exitContainer() - - return ScenesClusterSceneInfoStruct( - sceneCount, - currentScene, - currentGroup, - sceneValid, - remainingCapacity, - fabricIndex - ) - } - } -} diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ScenesCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ScenesCluster.kt deleted file mode 100644 index a1428d2a98780f..00000000000000 --- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ScenesCluster.kt +++ /dev/null @@ -1,2310 +0,0 @@ -/* - * - * Copyright (c) 2023 Project CHIP Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package matter.controller.cluster.clusters - -import java.time.Duration -import java.util.logging.Level -import java.util.logging.Logger -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.transform -import matter.controller.BooleanSubscriptionState -import matter.controller.InvokeRequest -import matter.controller.InvokeResponse -import matter.controller.MatterController -import matter.controller.ReadData -import matter.controller.ReadRequest -import matter.controller.SubscribeRequest -import matter.controller.SubscriptionState -import matter.controller.UByteSubscriptionState -import matter.controller.UIntSubscriptionState -import matter.controller.UShortSubscriptionState -import matter.controller.cluster.structs.* -import matter.controller.model.AttributePath -import matter.controller.model.CommandPath -import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.TlvReader -import matter.tlv.TlvWriter - -class ScenesCluster(private val controller: MatterController, private val endpointId: UShort) { - class AddSceneResponse(val status: UByte, val groupID: UShort, val sceneID: UByte) - - class ViewSceneResponse( - val status: UByte, - val groupID: UShort, - val sceneID: UByte, - val transitionTime: UShort?, - val sceneName: String?, - val extensionFieldSets: List? - ) - - class RemoveSceneResponse(val status: UByte, val groupID: UShort, val sceneID: UByte) - - class RemoveAllScenesResponse(val status: UByte, val groupID: UShort) - - class StoreSceneResponse(val status: UByte, val groupID: UShort, val sceneID: UByte) - - class GetSceneMembershipResponse( - val status: UByte, - val capacity: UByte?, - val groupID: UShort, - val sceneList: List? - ) - - class EnhancedAddSceneResponse(val status: UByte, val groupID: UShort, val sceneID: UByte) - - class EnhancedViewSceneResponse( - val status: UByte, - val groupID: UShort, - val sceneID: UByte, - val transitionTime: UShort?, - val sceneName: String?, - val extensionFieldSets: List? - ) - - class CopySceneResponse( - val status: UByte, - val groupIdentifierFrom: UShort, - val sceneIdentifierFrom: UByte - ) - - class LastConfiguredByAttribute(val value: ULong?) - - sealed class LastConfiguredByAttributeSubscriptionState { - data class Success(val value: ULong?) : LastConfiguredByAttributeSubscriptionState() - - data class Error(val exception: Exception) : LastConfiguredByAttributeSubscriptionState() - - object SubscriptionEstablished : LastConfiguredByAttributeSubscriptionState() - } - - class FabricSceneInfoAttribute(val value: List) - - sealed class FabricSceneInfoAttributeSubscriptionState { - data class Success(val value: List) : - FabricSceneInfoAttributeSubscriptionState() - - data class Error(val exception: Exception) : FabricSceneInfoAttributeSubscriptionState() - - object SubscriptionEstablished : FabricSceneInfoAttributeSubscriptionState() - } - - class GeneratedCommandListAttribute(val value: List) - - sealed class GeneratedCommandListAttributeSubscriptionState { - data class Success(val value: List) : GeneratedCommandListAttributeSubscriptionState() - - data class Error(val exception: Exception) : GeneratedCommandListAttributeSubscriptionState() - - object SubscriptionEstablished : GeneratedCommandListAttributeSubscriptionState() - } - - class AcceptedCommandListAttribute(val value: List) - - sealed class AcceptedCommandListAttributeSubscriptionState { - data class Success(val value: List) : AcceptedCommandListAttributeSubscriptionState() - - data class Error(val exception: Exception) : AcceptedCommandListAttributeSubscriptionState() - - object SubscriptionEstablished : AcceptedCommandListAttributeSubscriptionState() - } - - class EventListAttribute(val value: List) - - sealed class EventListAttributeSubscriptionState { - data class Success(val value: List) : EventListAttributeSubscriptionState() - - data class Error(val exception: Exception) : EventListAttributeSubscriptionState() - - object SubscriptionEstablished : EventListAttributeSubscriptionState() - } - - class AttributeListAttribute(val value: List) - - sealed class AttributeListAttributeSubscriptionState { - data class Success(val value: List) : AttributeListAttributeSubscriptionState() - - data class Error(val exception: Exception) : AttributeListAttributeSubscriptionState() - - object SubscriptionEstablished : AttributeListAttributeSubscriptionState() - } - - suspend fun addScene( - groupID: UShort, - sceneID: UByte, - transitionTime: UShort, - sceneName: String, - extensionFieldSets: List, - timedInvokeTimeout: Duration? = null - ): AddSceneResponse { - val commandId: UInt = 0u - - val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) - - val TAG_GROUP_I_D_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_GROUP_I_D_REQ), groupID) - - val TAG_SCENE_I_D_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_SCENE_I_D_REQ), sceneID) - - val TAG_TRANSITION_TIME_REQ: Int = 2 - tlvWriter.put(ContextSpecificTag(TAG_TRANSITION_TIME_REQ), transitionTime) - - val TAG_SCENE_NAME_REQ: Int = 3 - tlvWriter.put(ContextSpecificTag(TAG_SCENE_NAME_REQ), sceneName) - - val TAG_EXTENSION_FIELD_SETS_REQ: Int = 4 - tlvWriter.startArray(ContextSpecificTag(TAG_EXTENSION_FIELD_SETS_REQ)) - for (item in extensionFieldSets.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() - tlvWriter.endStructure() - - val request: InvokeRequest = - InvokeRequest( - CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), - tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout - ) - - val response: InvokeResponse = controller.invoke(request) - logger.log(Level.FINE, "Invoke command succeeded: ${response}") - - val tlvReader = TlvReader(response.payload) - tlvReader.enterStructure(AnonymousTag) - val TAG_STATUS: Int = 0 - var status_decoded: UByte? = null - - val TAG_GROUP_I_D: Int = 1 - var groupID_decoded: UShort? = null - - val TAG_SCENE_I_D: Int = 2 - var sceneID_decoded: UByte? = null - - while (!tlvReader.isEndOfContainer()) { - val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_GROUP_I_D)) { - groupID_decoded = tlvReader.getUShort(tag) - } - - if (tag == ContextSpecificTag(TAG_SCENE_I_D)) { - sceneID_decoded = tlvReader.getUByte(tag) - } else { - tlvReader.skipElement() - } - } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") - } - - if (groupID_decoded == null) { - throw IllegalStateException("groupID not found in TLV") - } - - if (sceneID_decoded == null) { - throw IllegalStateException("sceneID not found in TLV") - } - - tlvReader.exitContainer() - - return AddSceneResponse(status_decoded, groupID_decoded, sceneID_decoded) - } - - suspend fun viewScene( - groupID: UShort, - sceneID: UByte, - timedInvokeTimeout: Duration? = null - ): ViewSceneResponse { - val commandId: UInt = 1u - - val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) - - val TAG_GROUP_I_D_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_GROUP_I_D_REQ), groupID) - - val TAG_SCENE_I_D_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_SCENE_I_D_REQ), sceneID) - tlvWriter.endStructure() - - val request: InvokeRequest = - InvokeRequest( - CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), - tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout - ) - - val response: InvokeResponse = controller.invoke(request) - logger.log(Level.FINE, "Invoke command succeeded: ${response}") - - val tlvReader = TlvReader(response.payload) - tlvReader.enterStructure(AnonymousTag) - val TAG_STATUS: Int = 0 - var status_decoded: UByte? = null - - val TAG_GROUP_I_D: Int = 1 - var groupID_decoded: UShort? = null - - val TAG_SCENE_I_D: Int = 2 - var sceneID_decoded: UByte? = null - - val TAG_TRANSITION_TIME: Int = 3 - var transitionTime_decoded: UShort? = null - - val TAG_SCENE_NAME: Int = 4 - var sceneName_decoded: String? = null - - val TAG_EXTENSION_FIELD_SETS: Int = 5 - var extensionFieldSets_decoded: List? = null - - while (!tlvReader.isEndOfContainer()) { - val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_GROUP_I_D)) { - groupID_decoded = tlvReader.getUShort(tag) - } - - if (tag == ContextSpecificTag(TAG_SCENE_I_D)) { - sceneID_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_TRANSITION_TIME)) { - transitionTime_decoded = - if (tlvReader.isNull()) { - tlvReader.getNull(tag) - null - } else { - if (tlvReader.isNextTag(tag)) { - tlvReader.getUShort(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_SCENE_NAME)) { - sceneName_decoded = - if (tlvReader.isNull()) { - tlvReader.getNull(tag) - null - } else { - if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_EXTENSION_FIELD_SETS)) { - extensionFieldSets_decoded = - if (tlvReader.isNull()) { - tlvReader.getNull(tag) - null - } else { - if (tlvReader.isNextTag(tag)) { - buildList { - tlvReader.enterArray(tag) - while (!tlvReader.isEndOfContainer()) { - add(ScenesClusterExtensionFieldSet.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - } - } else { - tlvReader.skipElement() - } - } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") - } - - if (groupID_decoded == null) { - throw IllegalStateException("groupID not found in TLV") - } - - if (sceneID_decoded == null) { - throw IllegalStateException("sceneID not found in TLV") - } - - tlvReader.exitContainer() - - return ViewSceneResponse( - status_decoded, - groupID_decoded, - sceneID_decoded, - transitionTime_decoded, - sceneName_decoded, - extensionFieldSets_decoded - ) - } - - suspend fun removeScene( - groupID: UShort, - sceneID: UByte, - timedInvokeTimeout: Duration? = null - ): RemoveSceneResponse { - val commandId: UInt = 2u - - val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) - - val TAG_GROUP_I_D_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_GROUP_I_D_REQ), groupID) - - val TAG_SCENE_I_D_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_SCENE_I_D_REQ), sceneID) - tlvWriter.endStructure() - - val request: InvokeRequest = - InvokeRequest( - CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), - tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout - ) - - val response: InvokeResponse = controller.invoke(request) - logger.log(Level.FINE, "Invoke command succeeded: ${response}") - - val tlvReader = TlvReader(response.payload) - tlvReader.enterStructure(AnonymousTag) - val TAG_STATUS: Int = 0 - var status_decoded: UByte? = null - - val TAG_GROUP_I_D: Int = 1 - var groupID_decoded: UShort? = null - - val TAG_SCENE_I_D: Int = 2 - var sceneID_decoded: UByte? = null - - while (!tlvReader.isEndOfContainer()) { - val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_GROUP_I_D)) { - groupID_decoded = tlvReader.getUShort(tag) - } - - if (tag == ContextSpecificTag(TAG_SCENE_I_D)) { - sceneID_decoded = tlvReader.getUByte(tag) - } else { - tlvReader.skipElement() - } - } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") - } - - if (groupID_decoded == null) { - throw IllegalStateException("groupID not found in TLV") - } - - if (sceneID_decoded == null) { - throw IllegalStateException("sceneID not found in TLV") - } - - tlvReader.exitContainer() - - return RemoveSceneResponse(status_decoded, groupID_decoded, sceneID_decoded) - } - - suspend fun removeAllScenes( - groupID: UShort, - timedInvokeTimeout: Duration? = null - ): RemoveAllScenesResponse { - val commandId: UInt = 3u - - val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) - - val TAG_GROUP_I_D_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_GROUP_I_D_REQ), groupID) - tlvWriter.endStructure() - - val request: InvokeRequest = - InvokeRequest( - CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), - tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout - ) - - val response: InvokeResponse = controller.invoke(request) - logger.log(Level.FINE, "Invoke command succeeded: ${response}") - - val tlvReader = TlvReader(response.payload) - tlvReader.enterStructure(AnonymousTag) - val TAG_STATUS: Int = 0 - var status_decoded: UByte? = null - - val TAG_GROUP_I_D: Int = 1 - var groupID_decoded: UShort? = null - - while (!tlvReader.isEndOfContainer()) { - val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_GROUP_I_D)) { - groupID_decoded = tlvReader.getUShort(tag) - } else { - tlvReader.skipElement() - } - } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") - } - - if (groupID_decoded == null) { - throw IllegalStateException("groupID not found in TLV") - } - - tlvReader.exitContainer() - - return RemoveAllScenesResponse(status_decoded, groupID_decoded) - } - - suspend fun storeScene( - groupID: UShort, - sceneID: UByte, - timedInvokeTimeout: Duration? = null - ): StoreSceneResponse { - val commandId: UInt = 4u - - val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) - - val TAG_GROUP_I_D_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_GROUP_I_D_REQ), groupID) - - val TAG_SCENE_I_D_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_SCENE_I_D_REQ), sceneID) - tlvWriter.endStructure() - - val request: InvokeRequest = - InvokeRequest( - CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), - tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout - ) - - val response: InvokeResponse = controller.invoke(request) - logger.log(Level.FINE, "Invoke command succeeded: ${response}") - - val tlvReader = TlvReader(response.payload) - tlvReader.enterStructure(AnonymousTag) - val TAG_STATUS: Int = 0 - var status_decoded: UByte? = null - - val TAG_GROUP_I_D: Int = 1 - var groupID_decoded: UShort? = null - - val TAG_SCENE_I_D: Int = 2 - var sceneID_decoded: UByte? = null - - while (!tlvReader.isEndOfContainer()) { - val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_GROUP_I_D)) { - groupID_decoded = tlvReader.getUShort(tag) - } - - if (tag == ContextSpecificTag(TAG_SCENE_I_D)) { - sceneID_decoded = tlvReader.getUByte(tag) - } else { - tlvReader.skipElement() - } - } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") - } - - if (groupID_decoded == null) { - throw IllegalStateException("groupID not found in TLV") - } - - if (sceneID_decoded == null) { - throw IllegalStateException("sceneID not found in TLV") - } - - tlvReader.exitContainer() - - return StoreSceneResponse(status_decoded, groupID_decoded, sceneID_decoded) - } - - suspend fun recallScene( - groupID: UShort, - sceneID: UByte, - transitionTime: UShort?, - timedInvokeTimeout: Duration? = null - ) { - val commandId: UInt = 5u - - val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) - - val TAG_GROUP_I_D_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_GROUP_I_D_REQ), groupID) - - val TAG_SCENE_I_D_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_SCENE_I_D_REQ), sceneID) - - val TAG_TRANSITION_TIME_REQ: Int = 2 - transitionTime?.let { - tlvWriter.put(ContextSpecificTag(TAG_TRANSITION_TIME_REQ), transitionTime) - } - tlvWriter.endStructure() - - val request: InvokeRequest = - InvokeRequest( - CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), - tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout - ) - - val response: InvokeResponse = controller.invoke(request) - logger.log(Level.FINE, "Invoke command succeeded: ${response}") - } - - suspend fun getSceneMembership( - groupID: UShort, - timedInvokeTimeout: Duration? = null - ): GetSceneMembershipResponse { - val commandId: UInt = 6u - - val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) - - val TAG_GROUP_I_D_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_GROUP_I_D_REQ), groupID) - tlvWriter.endStructure() - - val request: InvokeRequest = - InvokeRequest( - CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), - tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout - ) - - val response: InvokeResponse = controller.invoke(request) - logger.log(Level.FINE, "Invoke command succeeded: ${response}") - - val tlvReader = TlvReader(response.payload) - tlvReader.enterStructure(AnonymousTag) - val TAG_STATUS: Int = 0 - var status_decoded: UByte? = null - - val TAG_CAPACITY: Int = 1 - var capacity_decoded: UByte? = null - - val TAG_GROUP_I_D: Int = 2 - var groupID_decoded: UShort? = null - - val TAG_SCENE_LIST: Int = 3 - var sceneList_decoded: List? = null - - while (!tlvReader.isEndOfContainer()) { - val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_CAPACITY)) { - capacity_decoded = - if (tlvReader.isNull()) { - tlvReader.getNull(tag) - null - } else { - if (!tlvReader.isNull()) { - tlvReader.getUByte(tag) - } else { - tlvReader.getNull(tag) - null - } - } - } - - if (tag == ContextSpecificTag(TAG_GROUP_I_D)) { - groupID_decoded = tlvReader.getUShort(tag) - } - - if (tag == ContextSpecificTag(TAG_SCENE_LIST)) { - sceneList_decoded = - if (tlvReader.isNull()) { - tlvReader.getNull(tag) - null - } else { - if (tlvReader.isNextTag(tag)) { - buildList { - tlvReader.enterArray(tag) - while (!tlvReader.isEndOfContainer()) { - add(tlvReader.getUByte(AnonymousTag)) - } - tlvReader.exitContainer() - } - } else { - null - } - } - } else { - tlvReader.skipElement() - } - } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") - } - - if (groupID_decoded == null) { - throw IllegalStateException("groupID not found in TLV") - } - - tlvReader.exitContainer() - - return GetSceneMembershipResponse( - status_decoded, - capacity_decoded, - groupID_decoded, - sceneList_decoded - ) - } - - suspend fun enhancedAddScene( - groupID: UShort, - sceneID: UByte, - transitionTime: UShort, - sceneName: String, - extensionFieldSets: List, - timedInvokeTimeout: Duration? = null - ): EnhancedAddSceneResponse { - val commandId: UInt = 64u - - val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) - - val TAG_GROUP_I_D_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_GROUP_I_D_REQ), groupID) - - val TAG_SCENE_I_D_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_SCENE_I_D_REQ), sceneID) - - val TAG_TRANSITION_TIME_REQ: Int = 2 - tlvWriter.put(ContextSpecificTag(TAG_TRANSITION_TIME_REQ), transitionTime) - - val TAG_SCENE_NAME_REQ: Int = 3 - tlvWriter.put(ContextSpecificTag(TAG_SCENE_NAME_REQ), sceneName) - - val TAG_EXTENSION_FIELD_SETS_REQ: Int = 4 - tlvWriter.startArray(ContextSpecificTag(TAG_EXTENSION_FIELD_SETS_REQ)) - for (item in extensionFieldSets.iterator()) { - item.toTlv(AnonymousTag, tlvWriter) - } - tlvWriter.endArray() - tlvWriter.endStructure() - - val request: InvokeRequest = - InvokeRequest( - CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), - tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout - ) - - val response: InvokeResponse = controller.invoke(request) - logger.log(Level.FINE, "Invoke command succeeded: ${response}") - - val tlvReader = TlvReader(response.payload) - tlvReader.enterStructure(AnonymousTag) - val TAG_STATUS: Int = 0 - var status_decoded: UByte? = null - - val TAG_GROUP_I_D: Int = 1 - var groupID_decoded: UShort? = null - - val TAG_SCENE_I_D: Int = 2 - var sceneID_decoded: UByte? = null - - while (!tlvReader.isEndOfContainer()) { - val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_GROUP_I_D)) { - groupID_decoded = tlvReader.getUShort(tag) - } - - if (tag == ContextSpecificTag(TAG_SCENE_I_D)) { - sceneID_decoded = tlvReader.getUByte(tag) - } else { - tlvReader.skipElement() - } - } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") - } - - if (groupID_decoded == null) { - throw IllegalStateException("groupID not found in TLV") - } - - if (sceneID_decoded == null) { - throw IllegalStateException("sceneID not found in TLV") - } - - tlvReader.exitContainer() - - return EnhancedAddSceneResponse(status_decoded, groupID_decoded, sceneID_decoded) - } - - suspend fun enhancedViewScene( - groupID: UShort, - sceneID: UByte, - timedInvokeTimeout: Duration? = null - ): EnhancedViewSceneResponse { - val commandId: UInt = 65u - - val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) - - val TAG_GROUP_I_D_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_GROUP_I_D_REQ), groupID) - - val TAG_SCENE_I_D_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_SCENE_I_D_REQ), sceneID) - tlvWriter.endStructure() - - val request: InvokeRequest = - InvokeRequest( - CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), - tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout - ) - - val response: InvokeResponse = controller.invoke(request) - logger.log(Level.FINE, "Invoke command succeeded: ${response}") - - val tlvReader = TlvReader(response.payload) - tlvReader.enterStructure(AnonymousTag) - val TAG_STATUS: Int = 0 - var status_decoded: UByte? = null - - val TAG_GROUP_I_D: Int = 1 - var groupID_decoded: UShort? = null - - val TAG_SCENE_I_D: Int = 2 - var sceneID_decoded: UByte? = null - - val TAG_TRANSITION_TIME: Int = 3 - var transitionTime_decoded: UShort? = null - - val TAG_SCENE_NAME: Int = 4 - var sceneName_decoded: String? = null - - val TAG_EXTENSION_FIELD_SETS: Int = 5 - var extensionFieldSets_decoded: List? = null - - while (!tlvReader.isEndOfContainer()) { - val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_GROUP_I_D)) { - groupID_decoded = tlvReader.getUShort(tag) - } - - if (tag == ContextSpecificTag(TAG_SCENE_I_D)) { - sceneID_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_TRANSITION_TIME)) { - transitionTime_decoded = - if (tlvReader.isNull()) { - tlvReader.getNull(tag) - null - } else { - if (tlvReader.isNextTag(tag)) { - tlvReader.getUShort(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_SCENE_NAME)) { - sceneName_decoded = - if (tlvReader.isNull()) { - tlvReader.getNull(tag) - null - } else { - if (tlvReader.isNextTag(tag)) { - tlvReader.getString(tag) - } else { - null - } - } - } - - if (tag == ContextSpecificTag(TAG_EXTENSION_FIELD_SETS)) { - extensionFieldSets_decoded = - if (tlvReader.isNull()) { - tlvReader.getNull(tag) - null - } else { - if (tlvReader.isNextTag(tag)) { - buildList { - tlvReader.enterArray(tag) - while (!tlvReader.isEndOfContainer()) { - add(ScenesClusterExtensionFieldSet.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - } else { - null - } - } - } else { - tlvReader.skipElement() - } - } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") - } - - if (groupID_decoded == null) { - throw IllegalStateException("groupID not found in TLV") - } - - if (sceneID_decoded == null) { - throw IllegalStateException("sceneID not found in TLV") - } - - tlvReader.exitContainer() - - return EnhancedViewSceneResponse( - status_decoded, - groupID_decoded, - sceneID_decoded, - transitionTime_decoded, - sceneName_decoded, - extensionFieldSets_decoded - ) - } - - suspend fun copyScene( - mode: UByte, - groupIdentifierFrom: UShort, - sceneIdentifierFrom: UByte, - groupIdentifierTo: UShort, - sceneIdentifierTo: UByte, - timedInvokeTimeout: Duration? = null - ): CopySceneResponse { - val commandId: UInt = 66u - - val tlvWriter = TlvWriter() - tlvWriter.startStructure(AnonymousTag) - - val TAG_MODE_REQ: Int = 0 - tlvWriter.put(ContextSpecificTag(TAG_MODE_REQ), mode) - - val TAG_GROUP_IDENTIFIER_FROM_REQ: Int = 1 - tlvWriter.put(ContextSpecificTag(TAG_GROUP_IDENTIFIER_FROM_REQ), groupIdentifierFrom) - - val TAG_SCENE_IDENTIFIER_FROM_REQ: Int = 2 - tlvWriter.put(ContextSpecificTag(TAG_SCENE_IDENTIFIER_FROM_REQ), sceneIdentifierFrom) - - val TAG_GROUP_IDENTIFIER_TO_REQ: Int = 3 - tlvWriter.put(ContextSpecificTag(TAG_GROUP_IDENTIFIER_TO_REQ), groupIdentifierTo) - - val TAG_SCENE_IDENTIFIER_TO_REQ: Int = 4 - tlvWriter.put(ContextSpecificTag(TAG_SCENE_IDENTIFIER_TO_REQ), sceneIdentifierTo) - tlvWriter.endStructure() - - val request: InvokeRequest = - InvokeRequest( - CommandPath(endpointId, clusterId = CLUSTER_ID, commandId), - tlvPayload = tlvWriter.getEncoded(), - timedRequest = timedInvokeTimeout - ) - - val response: InvokeResponse = controller.invoke(request) - logger.log(Level.FINE, "Invoke command succeeded: ${response}") - - val tlvReader = TlvReader(response.payload) - tlvReader.enterStructure(AnonymousTag) - val TAG_STATUS: Int = 0 - var status_decoded: UByte? = null - - val TAG_GROUP_IDENTIFIER_FROM: Int = 1 - var groupIdentifierFrom_decoded: UShort? = null - - val TAG_SCENE_IDENTIFIER_FROM: Int = 2 - var sceneIdentifierFrom_decoded: UByte? = null - - while (!tlvReader.isEndOfContainer()) { - val tag = tlvReader.peekElement().tag - - if (tag == ContextSpecificTag(TAG_STATUS)) { - status_decoded = tlvReader.getUByte(tag) - } - - if (tag == ContextSpecificTag(TAG_GROUP_IDENTIFIER_FROM)) { - groupIdentifierFrom_decoded = tlvReader.getUShort(tag) - } - - if (tag == ContextSpecificTag(TAG_SCENE_IDENTIFIER_FROM)) { - sceneIdentifierFrom_decoded = tlvReader.getUByte(tag) - } else { - tlvReader.skipElement() - } - } - - if (status_decoded == null) { - throw IllegalStateException("status not found in TLV") - } - - if (groupIdentifierFrom_decoded == null) { - throw IllegalStateException("groupIdentifierFrom not found in TLV") - } - - if (sceneIdentifierFrom_decoded == null) { - throw IllegalStateException("sceneIdentifierFrom not found in TLV") - } - - tlvReader.exitContainer() - - return CopySceneResponse( - status_decoded, - groupIdentifierFrom_decoded, - sceneIdentifierFrom_decoded - ) - } - - suspend fun readSceneCountAttribute(): UByte? { - 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 - } - - requireNotNull(attributeData) { "Scenecount attribute not found in response" } - - // Decode the TLV data into the appropriate type - val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - - return decodedValue - } - - suspend fun subscribeSceneCountAttribute( - minInterval: Int, - maxInterval: Int - ): Flow { - val ATTRIBUTE_ID: UInt = 0u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - ) - - val subscribeRequest: SubscribeRequest = - SubscribeRequest( - eventPaths = emptyList(), - attributePaths = attributePaths, - minInterval = Duration.ofSeconds(minInterval.toLong()), - maxInterval = Duration.ofSeconds(maxInterval.toLong()) - ) - - return controller.subscribe(subscribeRequest).transform { subscriptionState -> - when (subscriptionState) { - is SubscriptionState.SubscriptionErrorNotification -> { - emit( - UByteSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) - } - is SubscriptionState.NodeStateUpdate -> { - val attributeData = - subscriptionState.updateState.successes - .filterIsInstance() - .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } - - requireNotNull(attributeData) { "Scenecount attribute not found in Node State update" } - - // Decode the TLV data into the appropriate type - val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } - } - SubscriptionState.SubscriptionEstablished -> { - emit(UByteSubscriptionState.SubscriptionEstablished) - } - } - } - } - - suspend fun readCurrentSceneAttribute(): UByte? { - 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) - - 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) { "Currentscene attribute not found in response" } - - // Decode the TLV data into the appropriate type - val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - - return decodedValue - } - - suspend fun subscribeCurrentSceneAttribute( - minInterval: Int, - maxInterval: Int - ): Flow { - val ATTRIBUTE_ID: UInt = 1u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - ) - - val subscribeRequest: SubscribeRequest = - SubscribeRequest( - eventPaths = emptyList(), - attributePaths = attributePaths, - minInterval = Duration.ofSeconds(minInterval.toLong()), - maxInterval = Duration.ofSeconds(maxInterval.toLong()) - ) - - return controller.subscribe(subscribeRequest).transform { subscriptionState -> - when (subscriptionState) { - is SubscriptionState.SubscriptionErrorNotification -> { - emit( - UByteSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) - } - is SubscriptionState.NodeStateUpdate -> { - val attributeData = - subscriptionState.updateState.successes - .filterIsInstance() - .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } - - requireNotNull(attributeData) { "Currentscene attribute not found in Node State update" } - - // Decode the TLV data into the appropriate type - val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUByte(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(UByteSubscriptionState.Success(it)) } - } - SubscriptionState.SubscriptionEstablished -> { - emit(UByteSubscriptionState.SubscriptionEstablished) - } - } - } - } - - suspend fun readCurrentGroupAttribute(): UShort? { - 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 - } - - requireNotNull(attributeData) { "Currentgroup attribute not found in response" } - - // Decode the TLV data into the appropriate type - val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - - return decodedValue - } - - suspend fun subscribeCurrentGroupAttribute( - minInterval: Int, - maxInterval: Int - ): Flow { - val ATTRIBUTE_ID: UInt = 2u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - ) - - val subscribeRequest: SubscribeRequest = - SubscribeRequest( - eventPaths = emptyList(), - attributePaths = attributePaths, - minInterval = Duration.ofSeconds(minInterval.toLong()), - maxInterval = Duration.ofSeconds(maxInterval.toLong()) - ) - - return controller.subscribe(subscribeRequest).transform { subscriptionState -> - when (subscriptionState) { - is SubscriptionState.SubscriptionErrorNotification -> { - emit( - UShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) - } - is SubscriptionState.NodeStateUpdate -> { - val attributeData = - subscriptionState.updateState.successes - .filterIsInstance() - .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } - - requireNotNull(attributeData) { "Currentgroup attribute not found in Node State update" } - - // Decode the TLV data into the appropriate type - val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getUShort(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(UShortSubscriptionState.Success(it)) } - } - SubscriptionState.SubscriptionEstablished -> { - emit(UShortSubscriptionState.SubscriptionEstablished) - } - } - } - } - - suspend fun readSceneValidAttribute(): Boolean? { - 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}") - } - - logger.log(Level.FINE, "Read command succeeded") - - val attributeData = - response.successes.filterIsInstance().firstOrNull { - it.path.attributeId == ATTRIBUTE_ID - } - - requireNotNull(attributeData) { "Scenevalid attribute not found in response" } - - // Decode the TLV data into the appropriate type - val tlvReader = TlvReader(attributeData.data) - val decodedValue: Boolean? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getBoolean(AnonymousTag) - } else { - null - } - - return decodedValue - } - - suspend fun subscribeSceneValidAttribute( - minInterval: Int, - maxInterval: Int - ): Flow { - val ATTRIBUTE_ID: UInt = 3u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - ) - - val subscribeRequest: SubscribeRequest = - SubscribeRequest( - eventPaths = emptyList(), - attributePaths = attributePaths, - minInterval = Duration.ofSeconds(minInterval.toLong()), - maxInterval = Duration.ofSeconds(maxInterval.toLong()) - ) - - return controller.subscribe(subscribeRequest).transform { subscriptionState -> - when (subscriptionState) { - is SubscriptionState.SubscriptionErrorNotification -> { - emit( - BooleanSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) - } - is SubscriptionState.NodeStateUpdate -> { - val attributeData = - subscriptionState.updateState.successes - .filterIsInstance() - .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } - - requireNotNull(attributeData) { "Scenevalid attribute not found in Node State update" } - - // Decode the TLV data into the appropriate type - val tlvReader = TlvReader(attributeData.data) - val decodedValue: Boolean? = - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getBoolean(AnonymousTag) - } else { - null - } - - decodedValue?.let { emit(BooleanSubscriptionState.Success(it)) } - } - SubscriptionState.SubscriptionEstablished -> { - emit(BooleanSubscriptionState.SubscriptionEstablished) - } - } - } - } - - suspend fun readNameSupportAttribute(): UByte { - val ATTRIBUTE_ID: UInt = 4u - - 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) { "Namesupport attribute not found in response" } - - // Decode the TLV data into the appropriate type - val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte = tlvReader.getUByte(AnonymousTag) - - return decodedValue - } - - suspend fun subscribeNameSupportAttribute( - minInterval: Int, - maxInterval: Int - ): Flow { - val ATTRIBUTE_ID: UInt = 4u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - ) - - val subscribeRequest: SubscribeRequest = - SubscribeRequest( - eventPaths = emptyList(), - attributePaths = attributePaths, - minInterval = Duration.ofSeconds(minInterval.toLong()), - maxInterval = Duration.ofSeconds(maxInterval.toLong()) - ) - - return controller.subscribe(subscribeRequest).transform { subscriptionState -> - when (subscriptionState) { - is SubscriptionState.SubscriptionErrorNotification -> { - emit( - UByteSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) - } - is SubscriptionState.NodeStateUpdate -> { - val attributeData = - subscriptionState.updateState.successes - .filterIsInstance() - .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } - - requireNotNull(attributeData) { "Namesupport attribute not found in Node State update" } - - // Decode the TLV data into the appropriate type - val tlvReader = TlvReader(attributeData.data) - val decodedValue: UByte = tlvReader.getUByte(AnonymousTag) - - emit(UByteSubscriptionState.Success(decodedValue)) - } - SubscriptionState.SubscriptionEstablished -> { - emit(UByteSubscriptionState.SubscriptionEstablished) - } - } - } - } - - suspend fun readLastConfiguredByAttribute(): LastConfiguredByAttribute { - val ATTRIBUTE_ID: UInt = 5u - - 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) { "Lastconfiguredby attribute not found in response" } - - // Decode the TLV data into the appropriate type - val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - return LastConfiguredByAttribute(decodedValue) - } - - suspend fun subscribeLastConfiguredByAttribute( - minInterval: Int, - maxInterval: Int - ): Flow { - val ATTRIBUTE_ID: UInt = 5u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - ) - - val subscribeRequest: SubscribeRequest = - SubscribeRequest( - eventPaths = emptyList(), - attributePaths = attributePaths, - minInterval = Duration.ofSeconds(minInterval.toLong()), - maxInterval = Duration.ofSeconds(maxInterval.toLong()) - ) - - return controller.subscribe(subscribeRequest).transform { subscriptionState -> - when (subscriptionState) { - is SubscriptionState.SubscriptionErrorNotification -> { - emit( - LastConfiguredByAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) - } - is SubscriptionState.NodeStateUpdate -> { - val attributeData = - subscriptionState.updateState.successes - .filterIsInstance() - .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } - - requireNotNull(attributeData) { - "Lastconfiguredby attribute not found in Node State update" - } - - // Decode the TLV data into the appropriate type - val tlvReader = TlvReader(attributeData.data) - val decodedValue: ULong? = - if (!tlvReader.isNull()) { - if (tlvReader.isNextTag(AnonymousTag)) { - tlvReader.getULong(AnonymousTag) - } else { - null - } - } else { - tlvReader.getNull(AnonymousTag) - null - } - - decodedValue?.let { emit(LastConfiguredByAttributeSubscriptionState.Success(it)) } - } - SubscriptionState.SubscriptionEstablished -> { - emit(LastConfiguredByAttributeSubscriptionState.SubscriptionEstablished) - } - } - } - } - - suspend fun readSceneTableSizeAttribute(): UShort { - val ATTRIBUTE_ID: UInt = 6u - - 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) { "Scenetablesize attribute not found in response" } - - // Decode the TLV data into the appropriate type - val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort = tlvReader.getUShort(AnonymousTag) - - return decodedValue - } - - suspend fun subscribeSceneTableSizeAttribute( - minInterval: Int, - maxInterval: Int - ): Flow { - val ATTRIBUTE_ID: UInt = 6u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - ) - - val subscribeRequest: SubscribeRequest = - SubscribeRequest( - eventPaths = emptyList(), - attributePaths = attributePaths, - minInterval = Duration.ofSeconds(minInterval.toLong()), - maxInterval = Duration.ofSeconds(maxInterval.toLong()) - ) - - return controller.subscribe(subscribeRequest).transform { subscriptionState -> - when (subscriptionState) { - is SubscriptionState.SubscriptionErrorNotification -> { - emit( - UShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) - } - is SubscriptionState.NodeStateUpdate -> { - val attributeData = - subscriptionState.updateState.successes - .filterIsInstance() - .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } - - requireNotNull(attributeData) { - "Scenetablesize attribute not found in Node State update" - } - - // Decode the TLV data into the appropriate type - val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort = tlvReader.getUShort(AnonymousTag) - - emit(UShortSubscriptionState.Success(decodedValue)) - } - SubscriptionState.SubscriptionEstablished -> { - emit(UShortSubscriptionState.SubscriptionEstablished) - } - } - } - } - - suspend fun readFabricSceneInfoAttribute(): FabricSceneInfoAttribute { - val ATTRIBUTE_ID: UInt = 7u - - 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) { "Fabricsceneinfo 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(ScenesClusterSceneInfoStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - - return FabricSceneInfoAttribute(decodedValue) - } - - suspend fun subscribeFabricSceneInfoAttribute( - minInterval: Int, - maxInterval: Int - ): Flow { - val ATTRIBUTE_ID: UInt = 7u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - ) - - val subscribeRequest: SubscribeRequest = - SubscribeRequest( - eventPaths = emptyList(), - attributePaths = attributePaths, - minInterval = Duration.ofSeconds(minInterval.toLong()), - maxInterval = Duration.ofSeconds(maxInterval.toLong()) - ) - - return controller.subscribe(subscribeRequest).transform { subscriptionState -> - when (subscriptionState) { - is SubscriptionState.SubscriptionErrorNotification -> { - emit( - FabricSceneInfoAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) - } - is SubscriptionState.NodeStateUpdate -> { - val attributeData = - subscriptionState.updateState.successes - .filterIsInstance() - .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } - - requireNotNull(attributeData) { - "Fabricsceneinfo attribute not found in Node State update" - } - - // Decode the TLV data into the appropriate type - val tlvReader = TlvReader(attributeData.data) - val decodedValue: List = - buildList { - tlvReader.enterArray(AnonymousTag) - while (!tlvReader.isEndOfContainer()) { - add(ScenesClusterSceneInfoStruct.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - - emit(FabricSceneInfoAttributeSubscriptionState.Success(decodedValue)) - } - SubscriptionState.SubscriptionEstablished -> { - emit(FabricSceneInfoAttributeSubscriptionState.SubscriptionEstablished) - } - } - } - } - - suspend fun readGeneratedCommandListAttribute(): GeneratedCommandListAttribute { - 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}") - } - - 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 subscribeGeneratedCommandListAttribute( - minInterval: Int, - maxInterval: Int - ): Flow { - val ATTRIBUTE_ID: UInt = 65528u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - ) - - val subscribeRequest: SubscribeRequest = - SubscribeRequest( - eventPaths = emptyList(), - attributePaths = attributePaths, - minInterval = Duration.ofSeconds(minInterval.toLong()), - maxInterval = Duration.ofSeconds(maxInterval.toLong()) - ) - - return controller.subscribe(subscribeRequest).transform { subscriptionState -> - when (subscriptionState) { - is SubscriptionState.SubscriptionErrorNotification -> { - emit( - GeneratedCommandListAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) - } - is SubscriptionState.NodeStateUpdate -> { - val attributeData = - subscriptionState.updateState.successes - .filterIsInstance() - .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } - - requireNotNull(attributeData) { - "Generatedcommandlist attribute not found in Node State update" - } - - // 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() - } - - emit(GeneratedCommandListAttributeSubscriptionState.Success(decodedValue)) - } - SubscriptionState.SubscriptionEstablished -> { - emit(GeneratedCommandListAttributeSubscriptionState.SubscriptionEstablished) - } - } - } - } - - suspend fun readAcceptedCommandListAttribute(): AcceptedCommandListAttribute { - 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() - } - - return AcceptedCommandListAttribute(decodedValue) - } - - suspend fun subscribeAcceptedCommandListAttribute( - minInterval: Int, - maxInterval: Int - ): Flow { - val ATTRIBUTE_ID: UInt = 65529u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - ) - - val subscribeRequest: SubscribeRequest = - SubscribeRequest( - eventPaths = emptyList(), - attributePaths = attributePaths, - minInterval = Duration.ofSeconds(minInterval.toLong()), - maxInterval = Duration.ofSeconds(maxInterval.toLong()) - ) - - return controller.subscribe(subscribeRequest).transform { subscriptionState -> - when (subscriptionState) { - is SubscriptionState.SubscriptionErrorNotification -> { - emit( - AcceptedCommandListAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) - } - is SubscriptionState.NodeStateUpdate -> { - val attributeData = - subscriptionState.updateState.successes - .filterIsInstance() - .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } - - requireNotNull(attributeData) { - "Acceptedcommandlist attribute not found in Node State update" - } - - // 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() - } - - emit(AcceptedCommandListAttributeSubscriptionState.Success(decodedValue)) - } - SubscriptionState.SubscriptionEstablished -> { - emit(AcceptedCommandListAttributeSubscriptionState.SubscriptionEstablished) - } - } - } - } - - suspend fun readEventListAttribute(): EventListAttribute { - 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") - - 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 subscribeEventListAttribute( - minInterval: Int, - maxInterval: Int - ): Flow { - val ATTRIBUTE_ID: UInt = 65530u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - ) - - val subscribeRequest: SubscribeRequest = - SubscribeRequest( - eventPaths = emptyList(), - attributePaths = attributePaths, - minInterval = Duration.ofSeconds(minInterval.toLong()), - maxInterval = Duration.ofSeconds(maxInterval.toLong()) - ) - - return controller.subscribe(subscribeRequest).transform { subscriptionState -> - when (subscriptionState) { - is SubscriptionState.SubscriptionErrorNotification -> { - emit( - EventListAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) - } - is SubscriptionState.NodeStateUpdate -> { - val attributeData = - subscriptionState.updateState.successes - .filterIsInstance() - .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } - - requireNotNull(attributeData) { "Eventlist attribute not found in Node State update" } - - // 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() - } - - emit(EventListAttributeSubscriptionState.Success(decodedValue)) - } - SubscriptionState.SubscriptionEstablished -> { - emit(EventListAttributeSubscriptionState.SubscriptionEstablished) - } - } - } - } - - suspend fun readAttributeListAttribute(): AttributeListAttribute { - val ATTRIBUTE_ID: UInt = 65531u - - 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) { "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 subscribeAttributeListAttribute( - minInterval: Int, - maxInterval: Int - ): Flow { - val ATTRIBUTE_ID: UInt = 65531u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - ) - - val subscribeRequest: SubscribeRequest = - SubscribeRequest( - eventPaths = emptyList(), - attributePaths = attributePaths, - minInterval = Duration.ofSeconds(minInterval.toLong()), - maxInterval = Duration.ofSeconds(maxInterval.toLong()) - ) - - return controller.subscribe(subscribeRequest).transform { subscriptionState -> - when (subscriptionState) { - is SubscriptionState.SubscriptionErrorNotification -> { - emit( - AttributeListAttributeSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) - } - is SubscriptionState.NodeStateUpdate -> { - val attributeData = - subscriptionState.updateState.successes - .filterIsInstance() - .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } - - requireNotNull(attributeData) { "Attributelist attribute not found in Node State update" } - - // 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() - } - - emit(AttributeListAttributeSubscriptionState.Success(decodedValue)) - } - SubscriptionState.SubscriptionEstablished -> { - emit(AttributeListAttributeSubscriptionState.SubscriptionEstablished) - } - } - } - } - - suspend fun readFeatureMapAttribute(): UInt { - 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") - - 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 subscribeFeatureMapAttribute( - minInterval: Int, - maxInterval: Int - ): Flow { - val ATTRIBUTE_ID: UInt = 65532u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - ) - - val subscribeRequest: SubscribeRequest = - SubscribeRequest( - eventPaths = emptyList(), - attributePaths = attributePaths, - minInterval = Duration.ofSeconds(minInterval.toLong()), - maxInterval = Duration.ofSeconds(maxInterval.toLong()) - ) - - return controller.subscribe(subscribeRequest).transform { subscriptionState -> - when (subscriptionState) { - is SubscriptionState.SubscriptionErrorNotification -> { - emit( - UIntSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) - } - is SubscriptionState.NodeStateUpdate -> { - val attributeData = - subscriptionState.updateState.successes - .filterIsInstance() - .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } - - requireNotNull(attributeData) { "Featuremap attribute not found in Node State update" } - - // Decode the TLV data into the appropriate type - val tlvReader = TlvReader(attributeData.data) - val decodedValue: UInt = tlvReader.getUInt(AnonymousTag) - - emit(UIntSubscriptionState.Success(decodedValue)) - } - SubscriptionState.SubscriptionEstablished -> { - emit(UIntSubscriptionState.SubscriptionEstablished) - } - } - } - } - - suspend fun readClusterRevisionAttribute(): UShort { - 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) - - return decodedValue - } - - suspend fun subscribeClusterRevisionAttribute( - minInterval: Int, - maxInterval: Int - ): Flow { - val ATTRIBUTE_ID: UInt = 65533u - val attributePaths = - listOf( - AttributePath(endpointId = endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID) - ) - - val subscribeRequest: SubscribeRequest = - SubscribeRequest( - eventPaths = emptyList(), - attributePaths = attributePaths, - minInterval = Duration.ofSeconds(minInterval.toLong()), - maxInterval = Duration.ofSeconds(maxInterval.toLong()) - ) - - return controller.subscribe(subscribeRequest).transform { subscriptionState -> - when (subscriptionState) { - is SubscriptionState.SubscriptionErrorNotification -> { - emit( - UShortSubscriptionState.Error( - Exception( - "Subscription terminated with error code: ${subscriptionState.terminationCause}" - ) - ) - ) - } - is SubscriptionState.NodeStateUpdate -> { - val attributeData = - subscriptionState.updateState.successes - .filterIsInstance() - .firstOrNull { it.path.attributeId == ATTRIBUTE_ID } - - requireNotNull(attributeData) { - "Clusterrevision attribute not found in Node State update" - } - - // Decode the TLV data into the appropriate type - val tlvReader = TlvReader(attributeData.data) - val decodedValue: UShort = tlvReader.getUShort(AnonymousTag) - - emit(UShortSubscriptionState.Success(decodedValue)) - } - SubscriptionState.SubscriptionEstablished -> { - emit(UShortSubscriptionState.SubscriptionEstablished) - } - } - } - } - - companion object { - private val logger = Logger.getLogger(ScenesCluster::class.java.name) - const val CLUSTER_ID: UInt = 5u - } -} diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ScenesClusterAttributeValuePair.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ScenesClusterAttributeValuePair.kt deleted file mode 100644 index b64a49bfb3c025..00000000000000 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ScenesClusterAttributeValuePair.kt +++ /dev/null @@ -1,56 +0,0 @@ -/* - * - * Copyright (c) 2023 Project CHIP Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package matter.controller.cluster.structs - -import matter.controller.cluster.* -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvReader -import matter.tlv.TlvWriter - -class ScenesClusterAttributeValuePair(val attributeID: UInt, val attributeValue: UInt) { - override fun toString(): String = buildString { - append("ScenesClusterAttributeValuePair {\n") - append("\tattributeID : $attributeID\n") - append("\tattributeValue : $attributeValue\n") - append("}\n") - } - - fun toTlv(tlvTag: Tag, tlvWriter: TlvWriter) { - tlvWriter.apply { - startStructure(tlvTag) - put(ContextSpecificTag(TAG_ATTRIBUTE_I_D), attributeID) - put(ContextSpecificTag(TAG_ATTRIBUTE_VALUE), attributeValue) - endStructure() - } - } - - companion object { - private const val TAG_ATTRIBUTE_I_D = 0 - private const val TAG_ATTRIBUTE_VALUE = 1 - - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ScenesClusterAttributeValuePair { - tlvReader.enterStructure(tlvTag) - val attributeID = tlvReader.getUInt(ContextSpecificTag(TAG_ATTRIBUTE_I_D)) - val attributeValue = tlvReader.getUInt(ContextSpecificTag(TAG_ATTRIBUTE_VALUE)) - - tlvReader.exitContainer() - - return ScenesClusterAttributeValuePair(attributeID, attributeValue) - } - } -} diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ScenesClusterExtensionFieldSet.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ScenesClusterExtensionFieldSet.kt deleted file mode 100644 index 24f21fcdbcf814..00000000000000 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ScenesClusterExtensionFieldSet.kt +++ /dev/null @@ -1,71 +0,0 @@ -/* - * - * Copyright (c) 2023 Project CHIP Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package matter.controller.cluster.structs - -import matter.controller.cluster.* -import matter.tlv.AnonymousTag -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvReader -import matter.tlv.TlvWriter - -class ScenesClusterExtensionFieldSet( - val clusterID: UInt, - val attributeValueList: List -) { - override fun toString(): String = buildString { - append("ScenesClusterExtensionFieldSet {\n") - append("\tclusterID : $clusterID\n") - append("\tattributeValueList : $attributeValueList\n") - append("}\n") - } - - fun toTlv(tlvTag: Tag, tlvWriter: TlvWriter) { - tlvWriter.apply { - startStructure(tlvTag) - put(ContextSpecificTag(TAG_CLUSTER_I_D), clusterID) - startArray(ContextSpecificTag(TAG_ATTRIBUTE_VALUE_LIST)) - for (item in attributeValueList.iterator()) { - item.toTlv(AnonymousTag, this) - } - endArray() - endStructure() - } - } - - companion object { - private const val TAG_CLUSTER_I_D = 0 - private const val TAG_ATTRIBUTE_VALUE_LIST = 1 - - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ScenesClusterExtensionFieldSet { - tlvReader.enterStructure(tlvTag) - val clusterID = tlvReader.getUInt(ContextSpecificTag(TAG_CLUSTER_I_D)) - val attributeValueList = - buildList { - tlvReader.enterArray(ContextSpecificTag(TAG_ATTRIBUTE_VALUE_LIST)) - while (!tlvReader.isEndOfContainer()) { - add(ScenesClusterAttributeValuePair.fromTlv(AnonymousTag, tlvReader)) - } - tlvReader.exitContainer() - } - - tlvReader.exitContainer() - - return ScenesClusterExtensionFieldSet(clusterID, attributeValueList) - } - } -} diff --git a/src/controller/java/generated/java/matter/controller/cluster/structs/ScenesClusterSceneInfoStruct.kt b/src/controller/java/generated/java/matter/controller/cluster/structs/ScenesClusterSceneInfoStruct.kt deleted file mode 100644 index a77c286d44f563..00000000000000 --- a/src/controller/java/generated/java/matter/controller/cluster/structs/ScenesClusterSceneInfoStruct.kt +++ /dev/null @@ -1,86 +0,0 @@ -/* - * - * Copyright (c) 2023 Project CHIP Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package matter.controller.cluster.structs - -import matter.controller.cluster.* -import matter.tlv.ContextSpecificTag -import matter.tlv.Tag -import matter.tlv.TlvReader -import matter.tlv.TlvWriter - -class ScenesClusterSceneInfoStruct( - val sceneCount: UByte, - val currentScene: UByte, - val currentGroup: UShort, - val sceneValid: Boolean, - val remainingCapacity: UByte, - val fabricIndex: UByte -) { - override fun toString(): String = buildString { - append("ScenesClusterSceneInfoStruct {\n") - append("\tsceneCount : $sceneCount\n") - append("\tcurrentScene : $currentScene\n") - append("\tcurrentGroup : $currentGroup\n") - append("\tsceneValid : $sceneValid\n") - append("\tremainingCapacity : $remainingCapacity\n") - append("\tfabricIndex : $fabricIndex\n") - append("}\n") - } - - fun toTlv(tlvTag: Tag, tlvWriter: TlvWriter) { - tlvWriter.apply { - startStructure(tlvTag) - put(ContextSpecificTag(TAG_SCENE_COUNT), sceneCount) - put(ContextSpecificTag(TAG_CURRENT_SCENE), currentScene) - put(ContextSpecificTag(TAG_CURRENT_GROUP), currentGroup) - put(ContextSpecificTag(TAG_SCENE_VALID), sceneValid) - put(ContextSpecificTag(TAG_REMAINING_CAPACITY), remainingCapacity) - put(ContextSpecificTag(TAG_FABRIC_INDEX), fabricIndex) - endStructure() - } - } - - companion object { - private const val TAG_SCENE_COUNT = 0 - private const val TAG_CURRENT_SCENE = 1 - private const val TAG_CURRENT_GROUP = 2 - private const val TAG_SCENE_VALID = 3 - private const val TAG_REMAINING_CAPACITY = 4 - private const val TAG_FABRIC_INDEX = 254 - - fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): ScenesClusterSceneInfoStruct { - tlvReader.enterStructure(tlvTag) - val sceneCount = tlvReader.getUByte(ContextSpecificTag(TAG_SCENE_COUNT)) - val currentScene = tlvReader.getUByte(ContextSpecificTag(TAG_CURRENT_SCENE)) - val currentGroup = tlvReader.getUShort(ContextSpecificTag(TAG_CURRENT_GROUP)) - val sceneValid = tlvReader.getBoolean(ContextSpecificTag(TAG_SCENE_VALID)) - val remainingCapacity = tlvReader.getUByte(ContextSpecificTag(TAG_REMAINING_CAPACITY)) - val fabricIndex = tlvReader.getUByte(ContextSpecificTag(TAG_FABRIC_INDEX)) - - tlvReader.exitContainer() - - return ScenesClusterSceneInfoStruct( - sceneCount, - currentScene, - currentGroup, - sceneValid, - remainingCapacity, - fabricIndex - ) - } - } -}